Sub topic 3
Deciding what is essential and what can be dropped
This chapter assumes you have built a service that calls other services or databases over a network, that you are comfortable with exceptions, and that you know what latency and availability mean. Before you add timeouts, retries, or breakers, you need to decide what each dependency is worth. That decision tells you what the service should do when the dependency fails.
Critical and optional dependencies
A critical dependency is one the service cannot do its core job without. If it fails, the correct response is a clear, fast error. An optional dependency supports a feature that improves the response but is not the reason the user came. If it fails, the service should still answer, with less.
Take a checkout service for an online shop:
| Dependency | Feature it supports | Class | Why |
|---|---|---|---|
| Orders database | Recording the order | Critical | No record means no sale. |
| Payment provider | Charging the card | Critical | Without a charge, the order is not valid. |
| Recommendation service | "You might also like" | Optional | The order completes without it. |
| Review service | Star ratings on items | Optional | The page is useful without ratings. |
| Analytics pipeline | Usage events | Optional | Users never see it. |
The class belongs to the feature, not to the dependency alone. The same recommendation service could be critical for a product whose whole purpose is recommending things.
A way to classify
Ask these questions about each dependency, in order:
- If this is missing, can the user still complete the main task?
- Would the response be wrong, or only less complete? Wrong answers, such as a missing price or a failed charge, make the dependency critical.
- Could you produce an acceptable substitute, such as old data or a default?
- Does the user need to know that something is missing?
A frequent mistake is to mark everything critical because every part feels important. Then no failure can ever be absorbed. The opposite mistake is treating a dependency as optional when dropping it produces a silently wrong result. Showing a stale price at payment time, for example, is worse than showing an error.
Define the degraded behavior in advance
For each optional dependency, write down what the service does when it is unavailable. A short table in your design document is enough.
| Feature | Normal behavior | Degraded behavior | Signal |
|---|---|---|---|
| Recommendations | Personalized list | Last cached list, else empty | `degraded: true` in the response |
| Ratings | Live average | Hide the stars | Metric counter |
| Analytics | Event sent inline | Event dropped or queued | Log line |
Writing this down forces the product and engineering conversation early. "Hide the section" and "show a generic list" are product decisions, so they should not be made in the middle of an incident.
Dependency map
The diagram below shows how the checkout service's calls split into two groups. Only the critical branch can turn a failure into an error for the user.
Encoding the decision in code
The classification should be visible in the code, not hidden in scattered try blocks. One approach is to make each call site state whether it is critical. This sketch lets critical failures propagate and replaces optional failures with a default.
def call_critical(fn):
"""Critical dependency: let failures propagate to the caller."""
return fn()
def call_optional(fn, default):
"""Optional dependency: on failure, return a default and flag it."""
try:
return fn(), False
except (TimeoutError, ConnectionError):
return default, True
def build_page(load_order, load_recommendations):
order = call_critical(load_order)
recs, recs_degraded = call_optional(load_recommendations, default=[])
return {
"order": order,
"recommendations": recs,
"degraded": recs_degraded,
}The caller of build_page sees an exception if the order cannot be loaded, and a normal response with degraded: true if only recommendations are missing. Note that only the expected failure types are caught. A bare except Exception would also hide programming errors such as a KeyError, and the service would report "degraded" when it is actually broken.
Common errors
- Classifying by team ownership or importance in meetings. Classify by what the user's task needs.
- Hidden critical dependencies. A service may call a configuration or authentication service on every request. If it is down, nothing works, so it is critical even if nobody listed it.
- No default agreed in advance. Engineers then invent one under pressure, and different endpoints behave differently.
- Degrading silently. If the user or operator cannot tell the response is reduced, wrong decisions follow. Later chapters cover signaling.
Exercise
A ride-booking service depends on a maps service for the estimated arrival time shown to the rider, and on a pricing service that computes the fare. Classify each as critical or optional for the "book a ride" feature, and describe an acceptable degraded behavior for any optional one.
Show answer
Pricing is critical: booking without a correct fare would charge the rider the wrong amount, so the service should return a clear error if pricing fails. The maps estimate is optional: the ride can still be booked without it. The degraded behavior could be to show "ETA unavailable" or a rough estimate from the last known value, with the response flagged as degraded. Note that if the maps service also decides which drivers are nearby, that part would be critical, so you would split the dependency by feature.