Sub topic 1
How dependencies fail: errors, slowness, and partial outages
Prerequisites
This chapter assumes you have built a service that calls other services or databases over a network. You should know how exceptions work in your language, how HTTP requests and responses look, and what latency (how long a call takes) and availability (the share of calls that succeed) mean.
Why failure modes matter
A dependency is anything your service calls to do its work: a database, another service, a payment provider, a cache, a search index. Later chapters cover the tools that protect you from dependency problems. Each tool targets a specific kind of failure, so you need to recognize the kinds first.
There are three common failure modes. They look different in your code and cause different damage.
| Failure mode | What the caller sees | Typical cause | Main risk |
|---|---|---|---|
| Hard error | Quick exception or error status | Service down, bad deploy, refused connection | Unhandled exceptions |
| Slowness | Calls succeed late or never return | Overload, lock contention, network congestion | Exhausted threads and connections |
| Partial outage | Some calls succeed, some fail | One bad node, one region, one customer's data | Intermittent bugs that are hard to reproduce |
Hard errors
A hard error is a fast, explicit failure. The connection is refused, DNS fails, or the dependency returns a 5xx status such as 500 or 503. The caller learns about the problem within milliseconds.
Hard errors are the easiest mode to handle. Your code gets an exception, and you decide what to do next. The common mistake is not handling them at all, so one failed call to an optional feature turns the whole request into a 500 error.
Not every error means the dependency is unhealthy. A 404 or 400 usually means your request was wrong, and retrying it will not help. Separate errors that signal a sick dependency (connection failures, timeouts, 503) from errors that signal a bad request (most 4xx). Only the first group should trigger retries, circuit breakers, and fallbacks.
Slowness
Slowness is usually more dangerous than an outage. A dependency that is down fails fast. A dependency that is slow holds on to your resources.
Consider a service with 50 worker threads. Each request calls a dependency that normally answers in 20 ms. If the dependency starts taking 10 seconds, every worker that calls it waits 10 seconds. At 5 requests per second, all 50 threads are blocked in about 10 seconds. After that, the service cannot answer anything, including requests that never touch the slow dependency.
This is how a problem in one dependency becomes an outage of your whole service. The failure moves up the call chain: your callers see you slow down, their threads fill up, and the pattern repeats.
Slowness also hides from simple monitoring. Error rate stays near zero because calls eventually succeed, yet users see long waits. Watch latency percentiles (such as p99, the time that 99% of calls beat) and not only error counts.
Partial outages
In a partial outage, the dependency works for some calls and fails for others. Examples:
- One of five database replicas is unhealthy, so about 20% of reads fail.
- A service works in one availability zone but not another.
- A search index is corrupt for one customer's data, and only that customer sees errors.
- A dependency sheds load and rejects a share of requests with 429 or 503.
Partial outages are tricky because averages hide them. A 2% error rate looks small on a dashboard, but if it hits one important customer every time, that customer has a full outage. Break metrics down by endpoint, region, and customer to see these cases.
Partial outages also make retries look useful. A failed call that is retried may land on a healthy node and succeed. That is helpful in small doses, but when the whole dependency is overloaded, retries add load and make things worse. The retries chapter returns to this.
Seeing the modes in code
The function below simulates all three modes against a fake dependency, and shows how a caller tells them apart.
import random
import time
def flaky_dependency(mode):
"""Simulate a dependency in one of four states."""
if mode == "error":
raise ConnectionError("connection refused")
if mode == "slow":
time.sleep(2.0)
return "late answer"
if mode == "partial":
if random.random() < 0.3:
raise ConnectionError("node unavailable")
return "ok"
return "ok"
def timed_call(mode):
start = time.monotonic()
try:
result = flaky_dependency(mode)
outcome = f"success: {result}"
except ConnectionError as exc:
outcome = f"error: {exc}"
elapsed = time.monotonic() - start
return outcome, round(elapsed, 2)
for mode in ["healthy", "error", "slow", "partial"]:
print(mode, timed_call(mode))The error call fails in microseconds. The slow call succeeds, but only after two seconds, so an error-rate check would call it healthy. The partial call succeeds or fails at random, so one test run proves little. Each of these needs a different defense.
Common errors in reasoning
- Treating "up" as one yes-or-no state. Dependencies are often up and unusable at once.
- Monitoring only error rate. Slowness and partial outages stay invisible.
- Assuming failures are independent. Your dependencies may share a network, a database, or a cloud region.
- Retrying every error. Retries on a bad request waste capacity, and retries on an overloaded service deepen the overload.
What comes next
Knowing the failure modes sets up the central idea of the tutorial: deciding in advance what your service should do when each one happens. The next chapter defines graceful degradation as that decision.
Exercise
A service has 20 worker threads and receives 10 requests per second. Each request calls a recommendations service that normally answers in 50 ms. The recommendations service starts responding after 5 seconds, but never returns an error. Roughly how long until the service stops answering all requests, and why does the error-rate dashboard stay green?
Show answer
At 10 requests per second, each blocked for 5 seconds, about 50 workers would be needed to keep up, and only 20 exist. The pool fills in about 2 seconds (20 workers at 10 new requests per second). After that, new requests wait or are rejected, even those that do not need recommendations. The dashboard stays green because every call eventually succeeds, so no errors are counted. Only latency metrics, such as p99, show the problem.