Failure, Retries, and Timeouts
Core Concepts (5)
- 1.Everything fails; design for partial failure
- 2.Every network call needs a timeout
- 3.Retries need backoff and jitter or they cause storms
- 4.Only idempotent operations are safe to retry blindly
- 5.Circuit breakers stop callers hammering a failing dependency
Map to Your Experience
Recall an outage that started small and grew. Was something retrying, queuing, or waiting forever?
Design Brief: Harden a Service Call
Learn
In a distributed system, parts fail independently and often partially. A server is slow rather than down, a network drops one packet in a hundred, a dependency returns errors for one customer. Designing for this reality is what separates a demo from a production system.
The first defence is the timeout. Without one, a caller waits as long as the slow dependency takes, and its own resources, such as threads and connections, are tied up. Enough slow calls and the caller itself stops responding, so a problem in one service spreads to others. Set every timeout deliberately, based on what the caller can afford, and keep the total below the user's patience.
The second defence is the retry. Many failures are brief, so trying again often works. But naive retries are dangerous. If a service is overloaded and every client retries immediately, the extra load makes things worse, a retry storm. Use exponential backoff, waiting one second, then two, then four, and add jitter, a random variation, so clients do not retry in lockstep. Cap the number of attempts.
Retries also raise the duplicate problem. If a charge request times out, you do not know whether it happened. Retrying blindly could charge the customer twice. The fix is idempotency: send a unique key with the request so the server can recognise a repeat and return the first result.
The third defence is the circuit breaker. After a threshold of failures, the breaker opens and calls fail immediately for a cooling-off period, giving the dependency room to recover and sparing the caller from waiting. It then lets a few trial calls through before closing again.
Finally, decide what the user sees when a dependency stays down. A degraded but working experience, such as hiding recommendations or queueing the order for later, beats an error page. Graceful degradation should be designed, not discovered.
Map
A call has a timeout of 10 seconds and three retries with no backoff, and the page budget is 3 seconds. Explain what goes wrong for the user and for the dependency, and propose better numbers.
Design
Harden the checkout call to a payment provider. Specify the timeout, retry count, backoff schedule with jitter, the idempotency key scheme, and the circuit breaker threshold and cooling-off time. Then describe the fallback the customer sees if the provider is down for an hour, and how the order is completed later.
Requirements
- •Choose a timeout with reasoning
- •Define a retry policy with backoff
- •Say when the circuit opens
Constraints
- •Payment charges must never be duplicated
- •Checkout page budget is 3 seconds
Must Cover
Trade-off Axis
availability vs risk of duplicate side effects
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 →