Dependencies: what a request cannot do without
What a dependency is
Section titled “What a dependency is”A dependency is something a component needs in order to do its job. A component depends on another when it calls it, reads from it, or cannot start without it. The arrow in an architecture diagram that leaves your component is a dependency.
Dependencies come in layers. The checkout service depends on a payment provider, and the provider depends on the banks and card networks behind it. Your service has direct dependencies, and each of those has its own. When the second layer fails, you feel it without having drawn it.
Draw the request path
Section titled “Draw the request path”Here is a checkout request and every component it touches. The service checks the customer’s identity, reads the stock, takes the payment, asks a recommendation service for suggestions, and puts an order message on a queue that an email worker reads later.
Text version of the diagram
- Customer sends requests to Checkout service.
- Checkout service sends requests to Login service, Inventory database, Payment provider, Recommendations service, Order queue.
- Login service does not call another component.
- Inventory database does not call another component.
- Payment provider does not call another component.
- Recommendations service does not call another component.
- Order queue sends requests to Email worker.
- Email worker does not call another component.
Not all of these arrows are the same. Some break the request when the other end fails. Some do not. Some are not on the request’s path at all.
Hard, soft, and off the path
Section titled “Hard, soft, and off the path”- A hard dependency is one the request cannot succeed without. If it fails, the request fails.
- A soft dependency is one the request can succeed without, with less. If it fails, the request still succeeds, with a missing recommendation or an estimate marked “unavailable”.
- A component is off the request path when the request does not wait for it. The email worker reads the queue later, so while it is down, messages wait and emails arrive late, but no checkout fails.
The difference is not a property of the other component. It is a property of your code. The recommendation service is a soft dependency here because the checkout shows an empty list when it does not answer within 100 ms. Remove that timeout and fallback and the same service becomes a hard dependency, with the same code and the same service.
That is what AWS means by turning hard dependencies into soft ones: a component should keep doing its core job when a dependency fails, in a degraded form, such as showing everything except the part that failed. It is one of the cheapest ways to make a system more available, and it is a design decision, so it has a price. The fallback path needs testing, and it should be simpler than the main path.
Try sorting them
Section titled “Try sorting them”Eight components around the checkout. For each, say what happens to a checkout request when it is down.
Challenge
Which dependencies can a request not do without?
In the checkout above, the service confirms an order only after the payment has been taken and the order message has been stored on the queue. It asks the recommendation service for suggestions and shows an empty list if there is no answer within 100 ms. It asks a shipping-estimate service for a delivery date and shows "estimate unavailable" if there is no answer within 200 ms. For each component, say what happens to a checkout request when it is down.
Sorting needs JavaScript.
Categories
- Hard dependency
- The request fails without it.
- Soft dependency
- The request succeeds without it, with less.
- Off the request path
- The request does not wait for it.
Check your answers at least once before looking at the answers.
Hard dependencies multiply
Section titled “Hard dependencies multiply”Here is the arithmetic that makes dependencies important. If a request needs all of a chain of components, it succeeds only when every one of them is up. For independent components, the availabilities multiply.
The checkout service plus its four hard dependencies make five components in a row. Suppose each is available 99.9% of the time:
Availability calculator
Your numbers
The share of time one copy of one component works. 99.9% means it is down about 8.8 hours a year. A provider's published figure is a promise, so measure what you actually get.
How many components in a row must all work for a request to succeed: the hard dependencies of the request path, each counted once.
How many copies of each component can serve a request, so that one failure does not stop it. 1 means no redundancy.
Changing the numbers needs JavaScript. The result is for the starting numbers.
Result
System availability99.5%
That allows 1.82 d of downtime a year.
How it is calculated
Each step shows its formula, the numbers that go in, and the figure that comes out.
One component, with its copies
A_c = 1 − (1 − a)^r
A group of copies is down only when every copy is down at the same time, so its unavailability is one copy's unavailability to the power r.
- a availability of one copy
- 99.9%
- r copies of each component
- 1
A_c availability of one component, with its copies99.9%
The whole chain
A = A_c^n
A request needs every component in the chain, so the availabilities multiply. The chain is up only when all of them are.
- A_c availability of one component, with its copies
- 99.9%
- n components in the chain
- 5
A system availability99.5%
Downtime in a year
D = (1 − A) × T
The time the chain is down is the unavailable share of the year (365 days).
- A system availability
- 99.5%
- T time in a year
- 365 d
D downtime in a year1.82 d
| Availability | Down per year | Down per month (30 days) | Down per day |
|---|---|---|---|
| 99% | 3.65 d | 7.2 h | 14.4 min |
| 99.5% · your system | 1.82 d | 3.59 h | 7.19 min |
| 99.9% | 8.76 h | 43.2 min | 1.44 min |
| 99.95% | 4.38 h | 21.6 min | 43.2 s |
| 99.99% | 52.6 min | 4.32 min | 8.64 s |
| 99.999% | 5.26 min | 25.9 s | 864 ms |
Model notes
Assumptions
- Components fail independently of one another. Failures with a shared cause (a bad deploy, one power supply, one data centre) break this, so real copies are less independent than this, and the real availability is lower than the figure here.
- A copy takes over instantly and completely when another fails. Real failover takes time, and requests fail while it happens, so copies buy fewer nines than the arithmetic says.
Simplifications
- Availability here is the share of time that the system is up. Many teams measure the share of requests that succeed instead, which is about the same only when traffic is even through the day.
- The calculator does not claim more than twelve nines. Beyond about six, a figure says more about the model's assumptions than about any real system, and the arithmetic cannot tell a copy's failure from a shared one.
- A year is 365 days and a month is 30 days.
Parameter values are illustrative. They are not benchmarks of any real product.
Five components, each down only 0.1% of the time, give a system that is down about 1.8 days a year. Every extra hard dependency costs availability. Ten of them at 99.9% give 99.0%, which is a little over three and a half days of downtime a year. This is why teams that add services casually find that the system gets less reliable while every individual service looks healthy.
There are two ways to get availability back.
- Remove a hard dependency from the path. Turn it into a soft one, or move it off the path. A dependency off the path no longer multiplies into the request.
- Add copies. If a component has two copies and either one can serve, it is down only when both are down at once, so the unavailabilities multiply instead. Two copies of a 99.9% component are available 99.9999% of the time. Set the number of copies to 2 in the calculator above and the whole chain goes from 99.5% to about 99.9995%, a downtime of about two and a half minutes a year.
Copies are not magic. The arithmetic assumes the copies fail independently and that one takes over instantly. Copies in the same rack, on the same power, or running the same bad deploy fail together, and a failover takes time during which requests fail. The model notes under the calculator say so, and the real figure is lower than the one on the screen. And some dependencies cannot be copied by you at all: if the payment provider is 99.9% available, checkout can never be better than 99.9%, however many copies of your own services you run.
The lab below is a shop whose database is a hard dependency for some requests and not for others. Most reads are answered by a cache and never reach it, while the writes and the remaining reads cannot do without it. Before you press Kill the database, write down how much of the system you expect to keep working. Then try the two ways back that you have just read about: keep a replica ready to take over, which adds a copy, and cache more of the reads, so that fewer requests need the database. Run the failure again after each one and compare.
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.
The dependency nobody drew
Section titled “The dependency nobody drew”The diagram above shows what the team thought of. Real systems have more, and the missing ones are the ones that cause surprises:
- DNS. Almost every request starts by turning a name into an address.
- Certificates. An expired certificate stops requests as surely as a crashed server.
- Time. Many protocols and tokens assume that clocks agree.
- The platform. The cloud region, its network, and the control plane that starts new instances.
- Your own tooling. The registry your deployments pull from, and the monitoring you need to see anything.
For each, ask the same question as before: if it is down, does the request fail, succeed with less, or not notice? You will not always like the answer, but it is far better to know it from a table than from an outage.
What happens if the recommendation service gets slow?
Section titled “What happens if the recommendation service gets slow?”The recommendation service is a soft dependency with a 100 ms timeout. Normally it answers in 20 ms. Today it has a problem and takes 5 seconds, not by failing but by being slow. What does checkout do?
With the timeout, each request waits 100 ms and gives up, instead of getting an answer in 20 ms. That makes every checkout 80 ms slower. At 1,000 requests per second, 1,000 × 0.1 s = 100 requests are waiting on the recommendation service at any moment, against 20 on a normal day. The cost is real but bounded.
Without the timeout, each request waits the full 5 seconds, and at 1,000 requests per second there are 1,000 × 5 s = 5,000 requests stuck waiting. They hold threads, connections and memory. Soon the checkout service has none left for requests that never needed the recommendations, and checkout fails. A soft dependency without a timeout turns into a hard one the moment it is slow. And a slow dependency is often worse than a dead one: a dead one fails immediately, and a slow one ties up resources while it fails. The failure labs later in the course let you watch this happen.
- A dependency is something a component needs to do its job. Direct dependencies have their own dependencies.
- A hard dependency makes the request fail when it fails. A soft dependency lets the request succeed with less. A component off the path does not affect the request at all.
- Whether a dependency is hard or soft is a property of your code: a timeout and a fallback turn a hard one into a soft one.
- For independent components, availabilities multiply along a chain of hard dependencies: five at 99.9% is about 99.5%, or 1.8 days of downtime a year.
- Copies multiply unavailabilities instead. Two copies of a 99.9% component are 99.9999% available, if they fail independently and fail over instantly.
- The dependencies that surprise teams are the ones that were never drawn: DNS, certificates, time, the platform.
- A soft dependency without a timeout becomes a hard one when it is slow.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.