robisson/build-like-amazon-agent-skills/dependency-management

Claude Code and agent skill by robisson/build-like-amazon-agent-skills

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Managing external dependencies safely with circuit breakers, timeouts, retries with exponential backoff, bulkhead pattern, graceful degradation, and dependency isolation.

Install

npx vskill@latest install robisson/build-like-amazon-agent-skills/dependency-management

SKILL.md

The same SKILL.md was published earlier as robisson/build-like-amazon-agent-skills/dependency-management.

Dependency Management

Overview

Every external dependency is a liability. Every network call can fail, every downstream service can become slow, every database can become overloaded. Dependency management is the discipline of treating every external interaction as unreliable and building defenses that keep your service healthy even when dependencies are not.

At Amazon, a single service may depend on dozens of other services, databases, caches, and external APIs. Without proper dependency management, a slowdown in one dependency cascades into a full system outage—the "thundering herd" or "retry storm" that has caused some of Amazon's most significant incidents.

The core principle: your service's availability is the product of its dependencies' availabilities, unless you actively decouple from them. If you depend on 5 services each at 99.9% availability and do nothing, your service can only be 99.5% available. Proper dependency management breaks this multiplication.

When to Use

  • Making any HTTP call to another service
  • Querying any database or cache
  • Calling any third-party API
  • Publishing to or consuming from message queues
  • Reading from configuration services
  • Any I/O operation that crosses a network boundary

Amazon Context

Amazon's distributed architecture means most requests traverse multiple services. The call graph for a single customer request might involve 50+ services. Without dependency isolation, a single slow service can cause a cascading failure that takes down the entire customer experience.

Key lessons learned:

  • The 2004 outage taught Amazon that retries without backoff amplify failures (retry storms)
  • The "thundering herd" incidents taught that all callers recovering simultaneously overwhelms the recovering service
  • The "gray failures" (slow but not dead services) are harder to detect and more damaging than hard failures

Amazon's architecture mandates: circuit breakers at every service boundary, timeouts on every call, retries with jitter, and bulkheads isolating failure domains. These are not optional patterns—they are architectural requirements enforced through ORR.

The Process

1. Timeouts (First Line of Defense)

Every external call has an explicit timeout. Never use defaults.

python
# BAD: No timeout - a slow dependency blocks your thread forever
response = requests.get("https://payment-service/charge")
# BAD: Timeout too generous - 30 seconds of blocked threads = cascading failure
response = requests.get("https://payment-service/charge", timeout=30)
# GOOD: Aggressive timeout with connect and read separated
response = requests.get(
"https://payment-service/charge",
timeout=(1.0, 5.0), # 1s connect, 5s read
)

Timeout rules:

Dependency TypeConnect TimeoutRead TimeoutRationale
Internal service (same region)1s5sShould be fast; detect failures quickly
Internal service (cross-region)2s10sNetwork latency is higher
Database (primary)1s3sDB calls should be fast; slow = problem
Cache (Redis/Memcached)500ms1sCache misses should be fast
External third-party API2s15sLess control, but still bound it
Non-critical dependency500ms2sFail fast, degrade gracefully
2. Retries with Exponential Backoff and Jitter

Retries are essential but dangerous. Without backoff, retries amplify load on a struggling service:

python
from tenacity import retry, stop_after_attempt, wait_exponential_jitter
@retry(
stop=stop_after_attempt(3),
wait=wait_exponential_jitter(
initial=0.1, # First retry after ~100ms
max=10, # Never wait more than 10s
jitter=2, # Add random jitter up to 2s
),
retry=retry_if_exception_type((TransientError, TimeoutError)),
)
def call_payment_service(order_id: str) -> PaymentResult:
return payment_client.charge(order_id)

Retry rules:

  • Only retry transient errors — never retry 400s, auth failures, or validation errors
  • Exponential backoff — 100ms → 200ms → 400ms (not 100ms → 100ms → 100ms)
  • Full jitter — randomize wait time to prevent thundering herd
  • Limited attempts — 3 attempts maximum for synchronous paths
  • Budget-based retries — limit total retries per time window (e.g., 10% of traffic can be retries)
python
class RetryBudget:
"""Limits retries to a percentage of total requests."""
def __init__(self, budget_percent: float = 10.0, window_seconds: int = 60):
self.budget_percent = budget_percent
self.window_seconds = window_seconds
self._total_requests = 0
self._retry_requests = 0
def can_retry(self) -> bool:
if self._total_requests == 0:
return True
retry_rate = (self._retry_requests / self._total_requests) * 100
return retry_rate < self.budget_percent
3. Circuit Breakers

Circuit breakers prevent calling a known-failing dependency:

python
from circuitbreaker import CircuitBreaker
payment_circuit = CircuitBreaker(
failure_threshold=5, # Open after 5 consecutive failures
recovery_timeout=30, # Try again after 30 seconds
expected_exception=(TransientError, TimeoutError),
)
@payment_circuit
def call_payment_service(order_id: str) -> PaymentResult:
return payment_client.charge(order_id)
def process_payment(order_id: str) -> PaymentResult:
try:
return call_payment_service(order_id)
except CircuitBreakerError:
# Circuit is open - dependency is known-bad
logger.warning("payment.circuit_open", order_id=order_id)
metrics.count("PaymentCircuit.Open", 1)
raise PaymentUnavailableError("Payment service temporarily unavailable")

Circuit breaker states:

┌──────────┐ failures >= threshold ┌──────────┐
│ CLOSED │ ─────────────────────────────→ │ OPEN │
│(normal) │ │(failing) │
└──────────┘ └──────────┘
↑ │
│ success │ recovery_timeout elapsed
│ ↓
│ ┌────────────┐
└─────────────────────────────────── │ HALF-OPEN │
│(testing) │
└────────────┘

Circuit breaker metrics to emit:

  • CircuitBreaker.StateChange (with from/to dimensions)
  • CircuitBreaker.Rejected (requests rejected while open)
  • CircuitBreaker.HalfOpenSuccess / CircuitBreaker.HalfOpenFailure
4. Bulkhead Pattern

Bulkheads isolate dependency failures so one bad dependency doesn't consume all resources:

python
import asyncio
from concurrent.futures import ThreadPoolExecutor
class BulkheadedDependencies:
"""Each dependency gets its own thread pool - one failing dependency
can't starve others of threads."""
def __init__(self):
# Payment gets 10 threads - if it's slow, only these 10 block
self.payment_pool = ThreadPoolExecutor(
max_workers=10, thread_name_prefix="payment"
)
# Inventory gets 20 threads - higher traffic, isolated from payment
self.inventory_pool = ThreadPoolExecutor(
max_workers=20, thread_name_prefix="inventory"
)
# Recommendations is non-critical - only 5 threads
self.recommendations_pool = ThreadPoolExecutor(
max_workers=5, thread_name_prefix="recommendations"
)
async def get_payment_status(self, order_id: str):
return await asyncio.get_event_loop().run_in_executor(
self.payment_pool,
payment_client.get_status,
order_id,
)

Bulkhead strategies:

StrategyUse WhenImplementation
Thread pool isolationBlocking I/O callsSeparate ThreadPoolExecutor per dependency
Semaphore isolationAsync callsasyncio.Semaphore limiting concurrent calls
Connection pool isolationDatabase connectionsSeparate connection pools per use case
Queue isolationMessage processingSeparate queues for different priority levels
5. Graceful Degradation Strategy

Classify every dependency as critical or non-critical:

python
class DependencyClassification:
"""
CRITICAL: Failure means we cannot serve the customer at all.
Example: Database for order data, Auth service
Strategy: Retry, circuit break, return error to caller
NON-CRITICAL: Failure means reduced functionality but core works.
Example: Recommendations, analytics, personalization
Strategy: Timeout aggressively, return default, log and continue
"""
pass
def get_product_page(product_id: str) -> ProductPage:
# CRITICAL: Product data - no fallback possible
product = product_service.get(product_id) # Full retry + circuit breaker
# NON-CRITICAL: Reviews - show page without reviews if unavailable
try:
reviews = review_service.get_reviews(
product_id, timeout_ms=200
)
except (TimeoutError, ServiceError):
metrics.count("Reviews.Degraded", 1)
reviews = CachedReviews.get(product_id, default=[])
# NON-CRITICAL: Recommendations - show page without recs
try:
recommendations = rec_service.get_similar(
product_id, timeout_ms=150
)
except (TimeoutError, ServiceError):
metrics.count("Recommendations.Degraded", 1)
recommendations = []
return ProductPage(
product=product,
reviews=reviews,
recommendations=recommendations,
)
6. Dependency Isolation Architecture
┌─────────────────────────────────────────────────────────┐
│ Your Service │
├─────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ Payment Client │ │ Inventory Client │ │
│ │ ┌─────────────┐ │ │ ┌─────────────┐ │ │
│ │ │ Timeout │ │ │ │ Timeout │ │ │
│ │ │ Retry │ │ │ │ Retry │ │ │
│ │ │ Circuit Brk │ │ │ │ Circuit Brk │ │ │
│ │ │ Bulkhead │ │ │ │ Bulkhead │ │ │
│ │ │ Metrics │ │ │ │ Metrics │ │ │
│ │ └─────────────┘ │ │ └─────────────┘ │ │
│ └──────────────────┘ └──────────────────┘ │
│ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ Cache Client │ │ Recs Client │ │
│ │ (non-critical) │ │ (non-critical) │ │
│ │ ┌─────────────┐ │ │ ┌─────────────┐ │ │
│ │ │ Timeout(1s) │ │ │ │ Timeout(200ms)│ │ │
│ │ │ No retry │ │ │ │ No retry │ │ │
│ │ │ Fallback │ │ │ │ Fallback:[] │ │ │
│ │ │ Metrics │ │ │ │ Metrics │ │ │
│ │ └─────────────┘ │ │ └─────────────┘ │ │
│ └──────────────────┘ └──────────────────┘ │
│ │
└─────────────────────────────────────────────────────────┘
7. Dependency Client Template
python
class ResilientServiceClient:
"""Template for a properly-managed dependency client."""

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/robisson/build-like-amazon-agent-skills/dependency-management/badge)](https://verified-skill.com/skills/robisson/build-like-amazon-agent-skills/dependency-management)

Something wrong with this skill or its page? Tell us.