Dependency failures: when what you call breaks
How much of the system needs it
Section titled “How much of the system needs it”The dependencies lesson called a component a hard dependency when a request cannot succeed without it, and a soft one when the request can carry on. Which a component is depends on the request. In the shop, the API calls the cache for 90% of the requests and the database directly for the other 10%, and the cache calls the database when it does not have the answer. The cache answers 80% of what it is asked.
So the share of requests that need the database is not 100% and not 10%. A request avoids the database only if it skips the direct call, which happens for 90% of them, and if the cache hits, which happens for 82% of them (1 − 0.9 × 0.2). Both together are 0.9 × 0.82, which is 74%, and the other 26% need the database.
Mental model. A dependency failure takes down the requests whose path goes through it, and only those. A cache, a replica or a default turns some of those paths into paths that do not.
Try it: kill the database
Section titled “Try it: kill the database”Press Kill the database and look at what still works.
Kill the database
The shop reads through a cache that answers four reads in five, and goes to the database for the rest and for every write. You kill the database. Find out how much of the system still works. Then decide what you would have built differently and run the same failure again.
The failure lab needs JavaScript. The healthy system is shown below.
1. Break it
The healthy system is shown first. When you press the button the failure strikes, and the run follows the 30 seconds after it.
What the failure does: The database stops answering.
Each dot stands for many requests. The numbers show the real rate.
No bottleneck: every component has headroom.
Cause and effect
Each step leads to the next. A step that is changing right now is marked.
- Traffic900 req/sNormal steady
- API utilisation75%Normal steady
- API queuenone waitingNormal steady
- Latency (p99)96 msNormal steady
- Timeouts and rejections0%Normal steady
- Errors0%Normal steady
| Component | State | Utilisation | Offered (req/s) | Served (req/s) | Rejected (req/s) | p50 | p95 | p99 |
|---|---|---|---|---|---|---|---|---|
| Clients | Healthy | <1% | 900 | 900 | 0 | 0 ms | 0 ms | 0 ms |
| Load balancer | Healthy | <1% | 900 | 900 | 0 | 0.03 ms | 0.15 ms | 0.23 ms |
| API | Busy | 75% | 900 | 900 | 0 | 14 ms | 60 ms | 93 ms |
| Cache | Healthy | 1% | 810 | 810 | 0 | 0.14 ms | 0.6 ms | 0.92 ms |
| Database | Healthy | 20% | 252 | 252 | 0 | 5.5 ms | 24 ms | 37 ms |
- Traffic
- 900 req/s
- Successful
- 900 req/s
- Error rate
- 0%
- Mean latency
- 24 ms
Sources
Illustrative values, not benchmarks of any real product.
Model notes
Assumptions
- Requests arrive at random, as a Poisson process, at a constant average rate.
- Each node is one queue, served first-come first-served by several identical slots (instances × concurrency).
- Service times are random with the stated mean; by default they are exponentially distributed.
- Each node is analysed separately, with the traffic it receives treated as Poisson.
- The system starts healthy at 900 requests a second. Three API instances can serve 1,200 a second and the database about 1,250 operations a second. Nine in ten requests read through the cache, which answers four in five of those reads; the rest, and every write, go to the database.
- A failure strikes at one instant and nothing repairs it during the run: no restart, no autoscaling, no operator. The load balancer notices a dead instance at once.
- The instances of a component are identical, and each request is independent of the others.
Simplifications
- Failover to a replica is instant here. A real failover takes seconds to minutes, and a replica can be missing the last writes of the primary it replaces.
- A read and a write cost the same, and every write needs the database. A real system could keep accepting writes in a queue, or serve reads in a read-only mode, which this lab does not model.
- A retry is a fresh, independent attempt with the same chance of failing as the last one. How long a real client library waits between attempts (backoff, jitter), and any retry budget or circuit breaker, are not simulated: attempts are counted, not scheduled.
- A client gives up when its first timeout runs out, so the latency shown stops at what a client would wait: the timeout of the first hop, times its attempts. After that the request counts as a failure.
- The cache's hit ratio is constant. Warming, stampedes and hot keys have their own labs.
- Nothing here models garbage collection, connection pools on the client, DNS, TLS handshakes, CPU throttling, noisy neighbours or cold caches. A real system fails in more ways, and in messier ones, than this model does.
- Above capacity there is no steady state. The model switches to a fluid approximation: the node serves at capacity, its queue grows until it reaches its limit, and further requests are rejected.
- Percentiles assume an exponential tail. A service-time variability other than exponential changes the mean wait but not the shape of the tail.
- A node frees its slot as soon as it has done its own work, before waiting on the services it calls. Real thread-per-request servers hold the slot, so a slow dependency exhausts them faster than this model shows.
- A request calls its dependencies one after another. Parallel fan-out is not modelled.
- When a caller times out and gives up, the callee still finishes the work, so abandoned requests keep consuming capacity.
- Retries add load. Their backoff and jitter decide when that load arrives, which only the per-request simulation shows.
- A caller’s timeout counts the mean time its dependencies take, not their full distribution.
- Latency percentiles for a whole request are estimated, over every request, including those that are rejected and fail quickly. The mean is exact, and the percentiles come from a gamma distribution that has that mean and the variance of the time spent in each component.
Parameter values are illustrative. They are not benchmarks of any real product.
Over the 30 seconds after the failure, 24% of the requests fail on average, and 26% at the worst, the share worked out above. The rest are served by the cache. The failures are fast: a dead database refuses at once, so the worst p99 is 92 ms, no worse than before. The retries show the waste. The API and the cache each retry a failed query once, so the attempts against the database go from ×1 to ×2. They double the calls to something that cannot answer, and no request was saved by them.
This is the benign kind of dependency failure, and a good picture of why. The system is partly up, the failures are quick and confined to the requests that need the database, and nothing else is affected. The next lesson shows what changes when the database does not die but slows.
What each fix buys
Section titled “What each fix buys”Choose the changes and run the same failure again. As in every lab of this module, a fix applies from the start of the run, as if you had built it before.
| Change | Requests that fail (average) | What it does |
|---|---|---|
| None | 24% | The 26% that need the database fail |
| Keep a replica ready to take over | 0% | A second database serves the requests, so none fails |
| Cache more of the reads | 13% | The cache hit ratio goes from 0.8 to 0.95, and the share needing the database falls from 26% to 14% |
| Stop retrying the database | 24% | The same requests fail; the attempts go from ×2 to none |
The replica removes the failure and costs a second database to run and keep in step. In the lab the takeover is instant. A real failover takes seconds to minutes, as the failover lesson measured, and a replica that is behind can lose the last writes, so this fix is the best case.
The bigger cache shrinks the blast of the failure instead of removing it. With a hit ratio of 0.95, the share that needs the database is 1 − 0.9 × (1 − 0.9 × 0.05), which is 14%, so about half as many requests fail. It costs memory and data that can be older, and a large cache takes time to fill again after a restart.
Stopping the retries changes nothing for the requests, because the database is dead and a second try cannot succeed. It removes the doubled load. The same setting would also remove the retries that save a request when the database is only briefly unreachable. Whether a retry helps depends on whether the failure is passing, which is what the reliability module is about.
Making a hard dependency soft
Section titled “Making a hard dependency soft”AWS’s Well-Architected guidance for this is to let a component keep doing its core function when a dependency is unavailable, serving stale, alternative or no data, so that a local failure does not become a complete one. Failure modes should be treated as normal operation. The first step is a business decision, not a technical one: what is the core function? For an online shop, the pages and the cart may be, and a recommendation panel is not. AWS’s example is a landing page that shows everything else when one upstream system fails, instead of an error page.
The lab models only one such measure, the cache, which is a soft dependency for reads by construction. It does not model a read-only mode, a queue that buffers writes until the database is back, or a default that stands in for a missing answer. The notes of the lab say so, and they are real options: AWS lists buffering writes in a queue, serving reads from replicas and defaults for a parameter store among them. Each has its own cost, and a fallback path is rarely exercised, so it needs testing to be trusted.
What happens if the cache fails too?
Section titled “What happens if the cache fails too?”Cache and database cover for each other in the shop only while both are up. If the cache dies and the database lives, every request that used the cache now goes to the database: 0.1 + 0.9, so all 900 requests a second ask it for a query. With 10 connections of 8 ms the database serves 10 ÷ 0.008, which is 1,250 a second, so it runs at 72% and survives, but with far less margin than the 252 queries a second, 20% of its capacity, that it sees now. The caching module has a lab for that failure. The two failures together leave nothing: the database is the hard dependency of every request that gets past the cache, and the cache is what makes the database small enough to run.
- A dependency failure fails the requests whose path goes through the component. In the shop 74% avoid the database, via the cache, and 26% need it.
- With the database dead, 24% of the requests fail on average, 26% at the worst, and fast: the worst p99 is 92 ms. The retries take the attempts against the database from ×1 to ×2 and save no request.
- A replica takes the failures to 0% at the price of a second database and an instant takeover that real life does not give. A hit ratio of 0.95 cuts the requests that need the database to 14% and the failures to 13%. Stopping the retries changes no failure.
- Graceful degradation is deciding the core function and making hard dependencies soft with stale data, defaults, queues or a read-only mode. The lab models only the cache.
- If the cache fails, all 900 requests a second reach a database that can serve 1,250, at 72%.
Next: gray failures, when the dependency is slow and not dead.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.