A five-hop synchronous call chain where every timeout was longer than the one above it
A slow inventory database turned into a full checkout outage. The edge gave up after 10 seconds, but each service below kept waiting for up to 30, doing work nobody would ever receive. How we found it in traces, budgeted timeouts per hop, propagated deadlines and moved two hops off the request path.
During an evening peak, the inventory service's database had a slow period: a vacuum on a large table combined with heavy traffic pushed query times from about 5 ms to 2 to 4 seconds. Inventory is one service among many. Within three minutes, checkout was failing for nearly everyone, the API gateway was returning 504s on unrelated endpoints, and three services were restarting after running out of worker threads.
The trace of one failed checkout request showed the shape:
gateway POST /checkout 10.00s (timeout, 504 to client)
checkout POST /internal/checkout 29.71s (still running after gateway gave up)
orders POST /orders 29.70s
pricing POST /price 18.20s
inventory GET /stock?skus=... 18.19s (slow DB)
inventory POST /reservations 11.48s
The gateway timed out at 10 seconds and returned an error to the user. But the checkout service, below it, kept working for another 20 seconds on a request whose response would never be delivered. So did orders, pricing and inventory. Every one of those requests held a thread, a database connection and memory.
The timeout configuration
Each service had been configured by its own team, with a generous timeout for its own outgoing calls:
| Caller | Callee | Timeout | Retries |
|---|---|---|---|
| gateway | checkout | 10 s | 0 |
| checkout | orders | 30 s | 1 |
| orders | pricing | 20 s | 2 |
| orders | inventory | 15 s | 2 |
| pricing | inventory | 20 s | 1 |
Every timeout further down the chain was longer than the one above it. And with retries, orders could wait up to 3 × 20 s for pricing alone. The total time the chain might spend was over two minutes, for a request the user abandons after ten seconds.
Work continues after the caller has given up
When a client times out, it closes its side of the connection (or simply stops waiting). Unless the server notices and cancels, it keeps processing. In our stack, the HTTP servers did not cancel in-flight work when the client disconnected, and even if they had, the downstream calls they had already made would not have known.
So a slow leaf (inventory) caused this sequence:
- Requests to inventory slow down.
- Callers wait, holding threads. Thread pools in pricing and orders fill up.
- Upstream timeouts fire, users retry, and new requests arrive while the old ones are still running.
- Every service in the chain is now doing double or triple work, most of it for requests that have already failed.
- Thread pool exhaustion makes healthy endpoints of those services fail too.
This is a cascading failure. The slow dependency is the trigger, but the timeout configuration turns it into an outage.
Retries multiply load
Orders retried pricing twice, and pricing retried inventory once. One checkout could produce up to 3 × 2 = 6 calls to inventory just through that path, all against a database that was already struggling. Retries help with brief, random failures. Against a dependency that is slow because it is overloaded, they make the overload worse.
Long chains are fragile on their own
Even with good timeouts, a synchronous chain's availability is roughly the product of each hop's availability, and its latency is the sum. Five services at 99.9 percent each give about 99.5 percent for the chain. Every synchronous hop on the critical path is a liability, which is why the most effective fix was removing two of them.
Environment
| Item | Value |
|---|---|
| Services | Go (gateway, inventory), Java (checkout, orders), Python (pricing) |
| Transport | HTTP/1.1 JSON, gRPC between orders and inventory |
| Trigger | inventory DB latency 5 ms to 2-4 s for 12 minutes |
| Impact | checkout failure rate 87% for 9 minutes, 3 services restarted |
1. A timeout budget from the edge down
We started from what the user is willing to wait: the gateway's 10 seconds for checkout, with a target of under 2 seconds normally. Every hop must finish within what is left of its caller's budget, minus a margin for its own work. The new configuration:
| Caller | Callee | Timeout | Retries |
|---|---|---|---|
| gateway | checkout | 8 s | 0 |
| checkout | orders | 6 s | 0 |
| orders | pricing | 1.5 s | 1 (only on connection errors) |
| orders | inventory | 1.5 s | 1 (only on connection errors) |
Each timeout is shorter than its caller's, and the sum of the worst case down any path fits within the budget above it. Retries are limited to failures where the request certainly did not reach the server.
2. Propagate a deadline, not just timeouts
Static timeouts per hop are a good start, but they do not know how much time has already been spent. A request that waited 5 seconds in a queue at checkout still gets a fresh 6 second timeout to orders. A deadline, an absolute point in time by which the whole request must finish, solves this. Each service reads the deadline from the incoming request and passes the remaining time to every outgoing call.
gRPC has this built in. A client deadline is sent with the call (as the grpc-timeout header), and servers
can read it from the context:
// inventory service (Go, gRPC server)
func (s *server) Reserve(ctx context.Context, req *pb.ReserveRequest) (*pb.ReserveResponse, error) {
// ctx is cancelled automatically when the caller's deadline passes
rows, err := s.db.QueryContext(ctx, reserveSQL, req.Sku, req.Qty)
if errors.Is(err, context.DeadlineExceeded) {
return nil, status.Error(codes.DeadlineExceeded, "reservation timed out")
}
...
}
Passing ctx into QueryContext means the database query itself is cancelled when the deadline passes.
The work stops instead of continuing for nobody.
For our HTTP services, we added a header, X-Request-Deadline, set by the gateway as an absolute UTC
timestamp, and middleware in each language that turns it into a context or timeout for outgoing calls:
# pricing (Python), outgoing call helper
def remaining_budget(request) -> float:
deadline = parse_rfc3339(request.headers.get("X-Request-Deadline"))
return max(0.0, (deadline - now_utc()).total_seconds() - 0.05) # keep 50 ms for our own work
def call_inventory(request, payload):
budget = remaining_budget(request)
if budget <= 0:
raise DeadlineExceeded("no time left before calling inventory")
return http.post(INVENTORY_URL, json=payload, timeout=budget,
headers={"X-Request-Deadline": request.headers["X-Request-Deadline"]})
A service that receives a request whose deadline has already passed rejects it immediately rather than starting work.
3. Take hops off the critical path
The deeper fix was asking which calls truly had to be synchronous.
- Pricing calling inventory to show stock warnings during price calculation. Pricing now receives stock levels from inventory's change events and keeps a local view. Stock warnings may be a few seconds stale, which product agreed was fine. One hop gone.
- Orders calling inventory to reserve stock. This must happen before the order is confirmed, so it stays synchronous, but with a strict 1.5 second budget and a fallback: if the reservation times out, the order is created as "pending reservation" and confirmed asynchronously, and the user sees "we are confirming your order" instead of an error.
The checkout critical path went from five synchronous hops to three.
4. Bound concurrency per dependency
Each service now limits the number of concurrent calls to each dependency (a bulkhead), so a slow inventory can occupy at most a fixed share of orders' threads, and orders' other endpoints keep working.
1. Fault injection. In staging we added 3 seconds of latency to inventory's database with a proxy and ran the checkout load test:
| Version | Checkout success | Max work after user timeout | Other endpoints affected |
|---|---|---|---|
| Before | 9% | 29 s | yes, 3 services exhausted threads |
| After | 94% (rest as pending confirmation) | 0.1 s | no |
2. Traces. No span in the chain now outlives its parent. We added a check to our trace analysis that reports any child span ending more than 100 ms after its parent; it has been empty since the rollout.
3. A real incident. Two months later, the inventory database had a similar slow period. Checkout success dipped to 96 percent for four minutes, with the rest confirmed asynchronously within a minute. No other service was affected.
4. Security implications. Accepting a deadline from a request header must not let a client request unlimited time. The gateway sets the header and strips any value sent by external clients, and each service caps the incoming deadline at its own maximum.
Takeaways
- A downstream timeout longer than its caller's means work continues after the result is useless.
- Budget timeouts from the edge down, and propagate an absolute deadline through every hop.
- Pass the context or deadline into database calls so the work itself is cancelled.
- Retry only failures that certainly did not reach the server, and remove synchronous hops that do not need to be on the critical path.
References: gRPC deadlines, Go context package, Go database/sql QueryContext, Google SRE book, addressing cascading failures.
Add a label
Embed this post
<iframe src="https://hibug.me/synchronous-call-chain-cascading-timeouts" width="700" height="420" frameborder="0" loading="lazy"></iframe>
I have spent the past decade on systems where work moves through queues and events: order processing, notifications, payment flows and the services around them. I have helped split a monolith into services and, a few years later, helped merge some of them back. Distributed systems fail in ways that are hard to see from one log file. A poison message that blocks a queue for hours, a consumer that hoards messages, a schema change that silently drops events, a compensation step that ran twice, updates lost because two clocks disagreed. My posts trace each failure across the services involved, explain the guarantee we assumed and did not have, and show the design change that fixed it. For the bigger topics like sagas, CAP and service boundaries, I stay with concrete examples from systems I worked on rather than diagrams alone.
Comments
0No comments yet. Be the first to comment!
Sign In to post a comment.