Video in progress
One page sends parallel requests to 12 services. Every service's p99 is good, but the page's p99 is bad. Why, and what do you do?
In a fan-out the result equals the slowest response: the probability that at least one of 12 services lands in its p99 case is about 11%. So each service's p99 becomes the page's p89. The solution: reduce the fan-out, hedged requests, partial responses and caching.
📖 Answer
Simple math. For each service, the probability that a request is slower than its p99 is 1%. The probability that none of 12 independent calls is slow is 0.99^12 ≈ 0.886. So about 11% of page loads wait for at least one "tail" call. With a 100-service fan-out it becomes 63%. Google's "The Tail at Scale" paper is exactly about this.
What you can do:
-
Reduce the fan-out. Often 4–5 of the 12 services are needed for the main part of the page and the rest are secondary. Fetch those with a separate request after the page loads (lazy), or take them from a read model prepared in advance in the BFF.
-
Partial response. One overall deadline for the calls (say 300 ms). Whatever doesn't arrive in time becomes an empty block or a cached value. The page ships with the important parts.
var reviews = CompletableFuture.supplyAsync(() -> reviewClient.get(id), executor)
.completeOnTimeout(Reviews.empty(), 250, TimeUnit.MILLISECONDS);
-
Hedged requests. If the response hasn't arrived by the p95 time, send the same request to a second replica too and take whichever answer comes first. Only for idempotent reads. The extra load is around 5%, but the tail shrinks sharply. Hedges need a budget too, otherwise under load they become a problem themselves.
-
Find the cause of the tail. Slow requests are often not random: a GC pause, a cold cache, one "noisy neighbor" node, waiting in a connection pool. Filter the slowest spans in the traces and see which pod and what time they came from.
Have a page-level p99 SLO in your metrics, not only per service. Otherwise every team says "everything is fine on our side" while the user sees a slow page.
Sign up to mark studied questions and save your progress.