← Math
Math

Tail latency under fan-out

Every partition is green. Why are searches slow?

Turn per-call latency probabilities into a promise for the request that waits for them.

Outcome

Compute how often a fanned-out request meets its threshold, find the largest fan-out for a target, and set per-call objectives that back a request-level promise.

Terminology (6)Terms used in this lesson

Term on the front, definition on the back. Paste with tabs between fields and a new line between cards, or import the download in Anki as Basic.

Fan-out
One request calling many backends in parallel and combining their answers.
Tail latency
The slow end of a latency distribution, such as the slowest 1% of calls.
Per-call objective
How often one backend call must meet a latency threshold, for example 99.5% within 300 ms.
Required call
A call the request waits for before it can answer.
Optional call
A call whose result is shown if it arrives in time and skipped otherwise; it never delays the answer.
Hedged request
Sending a second copy of a slow call to another replica and using whichever answers first.

Why this matters

Search, feeds, dashboards and microservice pages all fan out: one request, many backend calls. Each backend team watches its own percentile, and every one can be healthy while users wait. Promising anything about the whole request means converting between per-call and per-request numbers, in both directions.

This lesson assumes independent probabilities and percentiles from earlier lessons.

What fan-out does to latency

Fan-out sends one request to several backends. If the response needs every result, its completion time follows the slowest required call, plus dispatch and merge overhead. Tail latency describes the less frequent slow responses beyond a chosen threshold.

The chance of meeting that threshold depends on the calls being fast together. Under the lesson’s independent-call model, their probabilities multiply. Which calls block the response therefore matters as much as each call’s own percentile; the worked model sets overhead aside explicitly.

01The slowest call decides

The slowest call decides

A log search queries 40 partitions and answers when the last one does. Each partition meets 300 ms 99.5% of the time, so every dashboard is green. Under an independent-call model, nearly one search in five still misses 300 ms. The slow 0.5% of each partition is common once a request waits for forty of them.

The search starts all partition calls together and waits for the slowest. Ignoring dispatch and merge overhead, Tsearch=max(T₁,…,Tₙ), so P(Tsearch≤300 ms)=P(all Tᵢ≤300 ms)=pⁿ under independence. Predict the three lines this program prints.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const p = 0.995; // one partition meets 300 ms this often

console.log((p ** 40).toFixed(6)); // a search over 40 partitions
let calls = 0;

while (p ** (calls + 1) >= 0.9) calls++;

console.log(calls); // most partitions for 90% of searches
console.log((0.99 ** (1 / 3)).toFixed(6)); // per read, for 99% of pages with 3 required reads
Why is the first line so much lower than 0.995?
Chance a whole request meets the threshold
Per call10 calls40 calls100 calls
99%0.9040.6690.366
99.5%0.9510.8180.606
99.9%0.9900.9610.905

02How far fan-out can grow

How far fan-out can grow

To keep 90% of searches within 300 ms at 99.5% per partition, add partitions while 0.995ⁿ stays at or above 0.9: 0.995²¹ = 0.9000 and 0.995²² = 0.8955, so 21 partitions is the limit. The quick estimate (1 − 0.9) ÷ (1 − 0.995) = 20 is close, but checking successive computed products retains the declared boundary instead of flooring an approximate logarithm.

p ** n and target ** (1 / k) cover both directions. The lab supplies a fixed integer-power multiplication sequence for unrounded decision comparisons.

03Required and optional calls

Required and optional calls

The search page waits for matches, access permissions and index metadata, then streams a histogram and suggestions. Only the three awaited calls enter this completion-time model. If the team makes the histogram required, the page now waits for four calls, and its latency promise needs a stricter objective from every backend or a looser promise.

What per-read chance keeps 99% of pages fast with 3 required reads?

04Back a promise

Back a promise

05When calls are slow together

When calls are slow together

pⁿ assumes calls are slow independently. A garbage-collection pause on a shared host or a common network interruption can make calls slow together. A hot shard may also have a different marginal probability, breaking the equal-p premise. For example, perfectly coincident slow events leave P(all fast)=p rather than pⁿ. The direction and size of an error need joint latency data; marginal percentiles alone cannot determine it. Treat pⁿ as a guide and check it against measured request latency.

06Size the search fan-out

Size the search fan-out

The search planner needs three answers from the same model: request success at a fixed fan-out, the last fan-out that still reaches its target, and an equal per-call objective for the actual blocking set. Hard must report the root while checking the current required-call product; counting streamed panels can make a feasible request look short.

A fanned-out log search

Whole-search latency, the fan-out limit, then the per-call objective.

  1. easy · M-FANOUT-V4-1 Whole-search latency
  2. medium · M-FANOUT-V4-2 Fan-out limit
  3. hard · M-FANOUT-V4-3 Per-call objective
In the frontend Required and streamed data in Next.js and Svelte Optional

The page awaits its required data together and lets optional panels stream in, so the histogram is outside the awaited data set. Optional requests can still contend for shared resources; streaming removes a direct await, not all possible effects on latency. The application supplies the data functions and display components shown here.

Estimate.tsx
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
import { Suspense } from "react";

// Required data is awaited together; optional panels stream in and never hold the page.
export default async function SearchPage({
  params
}: {
  params: Promise<{ query: string }>;
}) {
  const { query } = await params;
  const [matches, access, index] = await Promise.all([
    getMatches(query),
    getAccess(query),
    getIndex(query)
  ]);

  return (
    <main>
      <Results matches={matches} access={access} index={index} />
      <Suspense fallback={<p>Loading histogram…</p>}>
        <HistogramPanel query={query} />
      </Suspense>
    </main>
  );
}

async function HistogramPanel({ query }: { query: string }) {
  const histogram = await getHistogram(query);

  return <Histogram data={histogram} />;
}

Check this idea later
A request waits for 100 independent calls at 99.9% each, under the same threshold and negligible merge overhead. About how often is it fast?
For 0<target<1 with an equal per-call objective, an optional panel becomes required. What happens to the per-call objective that backs the page promise?
Sources

Values above were computed in Node 22 and run in Go 1.27, Rust 1.99 and Apple clang 17. The log search is a worked model.

Report a problem in this lesson

For typos, mistakes and things that don’t work. We read every report and fix what’s wrong, but we don’t reply here, so a question won’t get an answer.