Q1 · How do you design a resilient system that survives external dependency failures?
Back to 24 Architecture Questions.
The question is not “list resilience patterns”. The axis it turns on, from the index: which layer owns each budget, and what caps it. Every call to an external dependency spends three budgets from your system:
- Time: how long the caller waits before it stops waiting. The timeout, and who set it.
- Attempts: how many times the call is tried, and who decides to try again.
- Capacity: threads, connections, memory that the call holds while it waits.
A good answer names an owner and a cap for each. A bad answer lists patterns with no budget attached to any of them.
Each mechanism guards exactly one budget, and the fallback is a branch, not an afterthought:
What the answer should contain
Timeouts, set by the caller. Never rely on the dependency’s own timeout. The caller’s timeout must be shorter than the deadline the caller can afford, and it should propagate downward: if a request has 300 ms left, an internal call gets less than that, not a fresh 30 s.
Retries, capped and jittered. Two or three attempts, exponential backoff with jitter. Retry only errors that are plausibly transient: connection failures, 429, 503. Retry only operations that are safe to repeat, or make them safe with an idempotency key. Uncapped or synchronous retries are how a struggling dependency turns into a dead one: your retries are its load.
Circuit breaker. When the failure rate crosses a threshold, stop calling, fail fast, and probe occasionally until it recovers. It is the global version of the attempt budget: instead of every request spending its own retries against a dead dependency, one mechanism spends them for everyone.
Bulkhead. A separate connection or thread pool per dependency, so a slow dependency exhausts only its own pool. This is the capacity budget: one bad dependency should never be able to consume every worker in the process.
Fallback, decided in advance. What do you serve when the dependency is down: stale cache, a default value, a reduced feature set, or an honest error? The answer should name which one, per dependency, and note that this is a product decision, not an infrastructure one.
Shed load early. When everything is slow, reject work at the edge (503, bounded queue) rather than letting it pile up inside. A system that queues unboundedly is a system that dies slowly instead of failing fast.
Ideas worth mentioning out loud
- “Each dependency failure may cost us one timeout and one retry budget. It may never cost us our capacity.” That is the whole answer in one sentence.
- Timeouts and retries are per-request decisions; circuit breakers and bulkheads are per-system decisions. A resilient design has both, and knows which is which.
- Graceful degradation has a menu, not a single dish: partial results, cached answers, feature flags that turn off the dependent feature, or a clear “try later” to the user. Choose per dependency before the outage, not during it.
Follow-ups to expect
- How do you pick the timeout value? Measure the dependency’s p99, budget from the caller’s own deadline downward, never upward from the dependency’s promise.
- What if every client retries at once? Jitter, caps, and the circuit breaker; this is the retry-storm question in disguise.
- How is this different from just queuing the work? Sync failures block the caller; async failures isolate it, at the cost of staleness and a queue to operate. It is a trade-off answer, not a default.
Red flags in an answer
- “We wrap calls in try/catch.” Catching is hiding, not resilience.
- Relying on default timeouts, or having none.
- Infinite retries, or retries without backoff.
- One shared pool for every dependency.
- A fallback story that starts with “we would figure out”.
Sources
- Timeouts, retries, and backoff with jitter, AWS Builders’ Library: the budget argument in production form. Each layer sets its own timeout, attempts are capped, and jitter exists because synchronized retries are the dependency’s load.
- Avoiding fallback in distributed systems, AWS Builders’ Library: the counterweight to the fallback bullet. Fallbacks designed and tested in advance are resilience; improvised ones are a second failure mode. Decide before the outage, or do not claim one.
- CircuitBreaker, Martin Fowler: the pattern reference for the attempt budget owned globally.