Try
↑ ↓ move↵ openesc close

Interview prep / Distributed tracing

Mid · Distributed tracing · System design interview question

Compare head-based and tail-based sampling. What does each keep, and what does each cost?

Sketch your own answer first, then compare it with the one below.

A strong answer

Head-based sampling decides at the start of a request, usually with a random draw, and passes the decision along in the trace context. It is cheap and needs no buffering. Because the outcome is not known yet, it keeps slow and failing requests at the same rate as healthy ones, so the stored sample is a fair picture of traffic and a poor picture of problems.

Tail-based sampling decides after the trace is complete. A rule can keep every slow or failed trace and a small baseline of the rest. The cost is that every span of every trace must be held until the decision, and all spans of one trace must reach the same collector to be judged. Storage grows with the share of traces that are interesting, which can be large during an incident.

Either way the stored sample is biased. Compute rates from metrics that see every request, and use traces to explain individual requests.

Sources

Learn it by running it

The distributed tracing lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms