agentleFS
BuilderCedBuilderCed/agent-skills/skills/resilience/api-resilience-patterns/SKILL.md

api-resilience-patterns

Skill2 starsChanged 7 months agoMITView on GitHub

Implement API resilience patterns — circuit breakers, retry with backoff, rate limiting, bulkhead isolation, timeout management, and graceful degradation.

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 8 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Only retry on transient errors (429, 500, 502, 503, timeout)

    line 59
  2. Distinctive:

    Never retry on client errors (400, 401, 403, 404)

    line 60
  3. Distinctive:

    Always add jitter to prevent thundering herd

    line 61
  4. Distinctive:

    If service A fails, services B and C are unaffected

    line 79
  5. Distinctive:

    Does not implement specific libraries (guides patterns)

    line 112
  6. Distinctive:

    Does not monitor uptime (use APM tools)

    line 113
  7. Distinctive:

    Does not manage API keys or authentication

    line 114
  8. Distinctive:

    Does not handle business logic fallbacks (only infrastructure patterns)

    line 115

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

API Resilience Patterns

When to Use

  • Calling external APIs that might fail or slow down
  • Designing microservice communication
  • Building agents that call multiple tools/APIs
  • Handling rate limits from LLM providers
  • Preventing cascade failures

Pattern 1: Circuit Breaker

Prevents repeated calls to a failing service.

States: Closed (normal) → Open (failing) → Half-Open (testing)

StateBehaviorTransition
ClosedForward requests normally→ Open after N consecutive failures
OpenReject immediately (fail fast)→ Half-Open after cooldown period
Half-OpenAllow 1 test request→ Closed if success, → Open if fail

Config: threshold=3 failures, cooldown=30s, half-open-max=1.

Pattern 2: Retry with Exponential Backoff

Attempt 1: immediate
Attempt 2: wait 1s + random(0-500ms)
Attempt 3: wait 2s + random(0-500ms)
Attempt 4: wait 4s + random(0-500ms)
Max: 5 attempts, 16s max wait

Rules:

  • Only retry on transient errors (429, 500, 502, 503, timeout)
  • Never retry on client errors (400, 401, 403, 404)
  • Always add jitter to prevent thundering herd
  • Set a total timeout budget (not just per-attempt)

Pattern 3: Rate Limiting (Client-Side)

Respect provider limits proactively:

StrategyWhenHow
Token bucketSteady rate with burstsRefill N tokens/sec, consume per request
Sliding windowStrict per-minute limitsTrack timestamps of last N requests
Queue-basedOrdered processingFIFO queue with configurable concurrency

Pattern 4: Bulkhead Isolation

Isolate failures to prevent cascade:

  • Separate connection pools per service
  • Separate thread/worker pools per dependency
  • If service A fails, services B and C are unaffected

Pattern 5: Timeout Management

TierTimeoutPurpose
Connection5sDetect unreachable host
Request30sDetect slow response
Total operation60sBudget for retries included

Rule: Total timeout > (max_retries × request_timeout). Always set all three.

Pattern 6: Graceful Degradation

ScenarioFallback
Search API downReturn cached results + "results may not be current"
Payment API slowQueue payment, confirm later
AI API rate-limitedSwitch to cheaper/faster model
Database read replica downRead from primary (accept perf hit)

Anti-Patterns

Anti-PatternProblemFix
Retry without backoffAmplifies load on failing serviceExponential backoff + jitter
No timeoutThread/connection leakAlways set timeouts
Retry on all errorsRetrying 401 wastes timeOnly retry transient errors
Sync retry in UI threadBlocks user interfaceAsync retry with status feedback
Cascading timeoutsInner timeout > outer timeoutBudget timeouts from outside in

What This Skill Does NOT Do

  • Does not implement specific libraries (guides patterns)
  • Does not monitor uptime (use APM tools)
  • Does not manage API keys or authentication
  • Does not handle business logic fallbacks (only infrastructure patterns)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.