Resilience in Distributed Systems 00:00:01 Stop waiting before the pool fills A reviews service slows down. Checkout never needed a review to charge for an order, yet soon it cannot answer either. The missing dependency is not a business rule. It is a pool of workers both paths consume. 50 requests a second, 0.2 seconds each in reviews: 10 threads busy. Answers now take 30 seconds. Threads pile up at 50 a second. After 4 seconds all 200 threads wait for reviews. Orders is perfectly healthy. Nobody reaches it. The same slow service with a limit of 0.5 seconds keeps 25 threads busy. Pages come without reviews. A timeout frees a local caller only if the application actually releases its resources. Propagate cancellation where supported and choose the deadline from the time left for the customer. 00:00:56 Retries spread through time Three clients fail together at 0 s. When do they come back? A short overload. Three clients get an error at the same moment. With fixed one-second retries, the same three calls hit the overloaded service every second. Waits of 1, 2 and 4 seconds. Fewer calls, but still all three together each time. Each waits a random time below the limit. The waves dissolve. In this example draw client 2 tries twice within the first second. After four attempts, or when the deadline or the retry budget is used up, give up and use the fallback. Backoff and jitter reduce synchronized bursts but still add requests. Bound attempts and isolate which layer is responsible for retrying a given operation. 00:01:46 Know when a call is unlikely to help Five failures in a row open it, 30 seconds later it tests, three successes close it. Closed is the good state: calls flow through. Payments answers with timeouts. One success here would set the count back to zero. The fifth failure opens it. The next calls are refused at once, without waiting a second each. After 30 seconds a few test calls go through. The others still use the queue. Had a test call failed, the breaker would open again for another 30 seconds. Three test calls succeed. Calls flow, and a worker empties the queue slowly. A circuit breaker can reject calls quickly after sufficient failure evidence. Limited probes test recovery without instantly sending the entire backlog to a dependency that has just restarted. 00:02:36 Protect the important response A product page decides in advance what to show when a part is missing. Four parts, all fresh. The list falls back to popular items. Few people notice. Yesterday's reviews from the cache, with their date. No fallback. The page shows the product and says that the price cannot be shown now. The buy button is off. If the product permits it, checkout can continue without fresh recommendations. A fallback has to preserve the required business rule, not merely return a successful status code while silently dropping an order. 00:03:09 Lose a whole zone Three zones, sized so that two can carry everything. Each carries a third at 60% CPU. Health checks fail and the balancer stops sending there. 60% x 3 divided by 2 equals 90%. It holds, barely. At 70% it would have needed 105%. Auto-scaling adds servers in A and C. New capacity may be scarce, because everyone asks for it now. Rehearse both the movement of traffic and the capacity of the surviving zone. A working failover route helps little if the destination queues every request beyond its deadline. 00:03:50 Multiplying retries consume the recovery Why retries in every layer keep an outage alive. Normally one click is one call at each layer. User app, gateway and orders each make up to four attempts. Only orders retries, with a budget of 10%. The others pass the error on and use a fallback. Give retries a shared budget and record the ratio of attempts to successful customer actions. An apparent increase in service traffic can consist almost entirely of the same unhappy buyers trying again. Trace one failure until it stops affecting unrelated customers. A timeout, a retry limit, a fallback and spare capacity protect different parts of that journey.