Timeouts, Retries, and Circuit Breakers
Core Concepts (5)
- 1.Every remote call needs a timeout shorter than its caller's patience
- 2.Retries multiply load and can cause a retry storm
- 3.A retry budget caps extra traffic from retries
- 4.A circuit breaker fails fast while a dependency recovers
- 5.Bulkheads stop one slow dependency from consuming all resources
Map to Your Experience
Have you seen a small slowdown turn into a total outage? Describe how it escalated.
Design Brief: Harden a Service-to-Service Call
Learn
A call without a timeout can wait forever, and threads waiting forever are how small problems become total outages. Every remote call needs an explicit timeout. Better, use a timeout budget: the user-facing request has a total deadline, and each downstream call is given the remaining time, never more. A downstream timeout longer than the upstream one is wasted work.
Retries rescue transient failures but are dangerous in bulk. If a dependency is overloaded and every caller retries three times, the dependency now sees four times the load and cannot recover. This is a retry storm. Mitigate it with exponential backoff and jitter, retry only idempotent operations, retry at one layer rather than at every layer, and impose a retry budget, for example allowing retries to add at most ten percent extra traffic.
A circuit breaker watches the error rate of a dependency. While closed, calls pass through. When failures exceed a threshold, it opens and calls fail immediately without touching the dependency, giving it room to recover. After a cooling period it half opens and lets a few probe calls through. If they succeed, it closes again. Failing fast protects both sides.
A bulkhead isolates resources, like watertight compartments in a ship. Give each dependency its own connection pool or concurrency limit, so a slow inventory service can exhaust only its own pool and not the threads needed for everything else. Combine this with sensible limits on queue length, so excess work is rejected early rather than piling up.
What the caller does when a call fails is a product decision. Options include showing cached data, hiding an optional feature, or returning a clear error. Decide them in advance, test them, and document them, because a fallback that was never exercised often fails when first needed.
Map
Trace one user request through three services. For each hop, write its timeout and retry count, then check that the timeouts shrink toward the leaves. Compute the worst-case load multiplication if every layer retries twice.
Design
Specify the protections for the storefront call to inventory: the timeout values with reasoning, the retry rules and budget, the breaker thresholds and cooling period, the bulkhead size, and the fallback the shopper sees when the breaker is open.
Requirements
- •Set timeouts across the call chain
- •Define a retry policy with a budget
- •Describe the circuit breaker states and thresholds
Constraints
- •Inventory occasionally takes 10 seconds
- •Storefront must stay usable when inventory is down
Must Cover
Trade-off Axis
availability vs correctness
Referenced Patterns
Competencies Advanced
Ready to Design?
Open this day in the Design Studio. The studio follows this track: its days, concepts, patterns and trade-offs are loaded, and you keep one design across the whole track.
Open in Studio →