AGENT SKILL

replit-reliability-patterns

Implement Replit reliability patterns including circuit breakers, idempotency, and graceful degradation. Use when building fault-tolerant Replit integrations, implementing retry strategies, or adding resilience to production Replit services. Trigger with phrases like "replit reliability", "replit circuit breaker", "replit idempotent", "replit resilience", "replit fallback", "replit bulkhead".

License 许可
MIT
最近更新
2026-03-20
Stars
★ 4
Forks
0

01 前言 Front Matter

name
replit-reliability-patterns
author
Jeremy Longshore <jeremy@intentsolutions.io>
license
MIT
version
1.0.0
description
Implement Replit reliability patterns including circuit breakers, idempotency, and graceful degradation. Use when building fault-tolerant Replit integrations, implementing retry strategies, or adding resilience to production Replit services. Trigger with phrases like "replit reliability", "replit circuit breaker", "replit idempotent", "replit resilience", "replit fallback", "replit bulkhead".
allowed-tools
Read, Write, Edit
compatible-with
claude-code, codex, openclaw

03 SKILL.md 正文

Replit Reliability Patterns

Overview

Production reliability patterns for applications hosted on Replit. Replit's container-based hosting, automatic sleep behavior, and ephemeral filesystem require specific resilience strategies for production workloads.

Prerequisites

  • Replit Deployments configured (for always-on)
  • Understanding of container lifecycle
  • External database for persistent state

Instructions

Step 1: Handle Cold Start Gracefully

Replit containers restart on deploy and after sleep. Pre-warm caches and connections on startup.

import time

startup_complete = False
startup_time = None

async def warmup():
    global startup_complete, startup_time
    startup_time = time.time()
    # Pre-load frequently accessed data
    await cache.warm(["config", "feature_flags", "templates"])
    # Verify database connection
    await db.ping()
    startup_complete = True

@app.route('/health')
def health():
    if not startup_complete:
        return {"status": "warming_up"}, 503  # HTTP 503 Service Unavailable
    return {"status": "ok", "uptime": time.time() - startup_time}

@app.before_first_request
async def on_startup():
    await warmup()

Step 2: External State for Persistence

Never rely on local filesystem for state that must survive container restarts.

from replit.object_storage import Client as ObjectStorage
import json

class PersistentState:
    def __init__(self):
        self.storage = ObjectStorage()
        self._cache = {}

    def save(self, key: str, data: dict):
        self.storage.upload_from_text(
            f"state/{key}.json",
            json.dumps(data)
        )
        self._cache[key] = data

    def load(self, key: str) -> dict:
        if key in self._cache:
            return self._cache[key]
        try:
            raw = self.storage.download_as_text(f"state/{key}.json")
            data = json.loads(raw)
            self._cache[key] = data
            return data
        except:
            return {}

Step 3: Keep-Alive for Non-Deployment Repls

For Repls not using Deployments, prevent sleep with an external health check ping.

# Internal: expose health endpoint
@app.route('/ping')
def ping():
    return "pong", 200  # HTTP 200 OK

# External: use a free cron service to ping every 5 minutes
# cron-job.org, UptimeRobot, or similar
# URL: https://your-repl.replit.app/ping
# Interval: 5 minutes

Step 4: Graceful Shutdown Handler

Replit sends SIGTERM before container stop. Save state during shutdown.

import signal, sys

def graceful_shutdown(signum, frame):
    print("Shutting down gracefully...")
    state.save("session", {"last_active": time.time()})
    db.close()
    sys.exit(0)

signal.signal(signal.SIGTERM, graceful_shutdown)

Error Handling

Issue Cause Solution
Data loss on restart Using local filesystem Use Replit DB or Object Storage
Slow first request Cold start Pre-warm on startup, show loading state
Container sleeping No activity for 30 min Use Deployments or external keep-alive
Database disconnects Container restart Reconnect on startup, connection pooling

Examples

Deployment Health Monitor

health = {
    "container_uptime": time.time() - startup_time,
    "db_connected": await db.ping(),
    "storage_available": storage.exists("state/"),
    "memory_mb": process.memory_info().rss / 1024 / 1024  # 1024: 1 KB
}

Resources

Output

  • Configuration files or code changes applied to the project
  • Validation report confirming correct implementation
  • Summary of changes made and their rationale

04 同仓库更多 Skills

micsapp
micsapp/micstec-skills

azure-apim-architecture

Analyzes and explains Azure API Management architecture decisions for enterprise API marketplace implementations using VNet Internal mode, Front Door, hybrid authentication, and multi-environment strategies. Use when discussing APIM component selection, network topology, cost optimization, or comparing alternatives like workspaces vs instances, VNet Internal vs External mode, or Front Door vs Application Gateway.

★ 4
micsapp
micsapp/micstec-skills

apiops-deployment

Guides deployment of Azure API Management infrastructure using Infrastructure as Code (Bicep/Terraform), CI/CD pipelines (GitHub Actions/Azure DevOps), and APIOps workflows. Use when deploying APIM, creating pipelines, or implementing dev→test→prod promotion strategies.

★ 4
micsapp
micsapp/micstec-skills

apim-policy-authoring

Creates production-ready Azure API Management policy XML for authentication (OAuth 2.0, JWT validation, subscription keys), rate limiting, CORS configuration, error handling, and API transformations. Use when implementing API security, access control, or request/response processing logic.

★ 4
micsapp
micsapp/micstec-skills

api-security-review

Reviews Azure API Management configurations for security vulnerabilities, OWASP API Security Top 10 compliance, VNet Internal mode validation, Private Link verification, and Azure Security Benchmark alignment. Use when performing security audits, pre-deployment validation, or compliance reviews.

★ 4
micsapp
micsapp/micstec-skills

jira-cli

Interact with Jira from the command line to create, list, view, edit, and transition issues, manage sprints and epics, and perform common Jira workflows. Use when the user asks about Jira tasks, tickets, issues, sprints, or needs to manage project work items.

★ 4
micsapp
micsapp/micstec-skills

calculator

Performs arbitrary-precision arithmetic calculations including addition, subtraction, multiplication, division, and exponents. Use when the user asks to calculate, compute, or evaluate math expressions, or when precise decimal arithmetic is needed to avoid floating-point errors.

★ 4