Skip to content
SD-41 · Back to the write-up

Design a Distributed Tracing

Route every span of a trace to one collector, count metrics from all of them, keep the 5% that matter, and store those as blocks in object storage.

Follow a request

Hosts
Ingest
Pipeline
Storage
Services + SDKMake spans
Host agentBatch + scrub
Routing tierHash by trace id
Collectors30 s buffer, decide
Sampling configTeam rules
Span streamKept spans + deltas
Block writers5-minute blocks
Span metricsExact rates
Trace blocksObject storage
Trace indexSlim
Query serviceUI + API
1router → collector · last span arrivesThe last span of a trace reaches its collector, which holds the trace in memory until 30 seconds pass with no new span for it.1 / 4

The numbers, at a glance

Of every 20 spans made……1 is kept, and all 20 are counted
1 kept ≈ 2.5M/s19 counted, then dropped
Bytes per day at each stepRaw, after sampling, after compression
Errors are rare but always keptAbout 2% of traces have an error
Head sampling at 10% would keep only one in ten of the red slice.

From span to stored trace

Healthy traces that lose the 1% draw stop after step 3; their spans still count in metrics.

Service
Host agent
Collector
Span stream
Block writer
Object storage
Trace index
1 span
2 batch by trace_id
3 metric deltas
4 kept trace (after 30 s)
5 read batch
6 spans
7 PUT block + bloom
8 200
9 trace id → block
10 commit offset
RequestResponseAsync, does not block

Where to decide what to keep

The decision this question is really about.

Keep everything
Unaffordable
50M spans/s
store all
2,160 TB a day
+ Nothing missing.− About 2 PB a day.
Head sampling
Blind
first service: 10%?
flag in traceparent
90% of errors lost
+ Free and complete traces.− Decided before errors happen.
Tail by trace id
Our pick
route by trace_id
count allwait 30 s
keep errors, slow + 1%
+ Keeps every error and slow trace.− Memory to hold 30 s of traces.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 100,000 spans/sMake it work
Services + SDK
Collectors
Search clusterQuery
Every span into one search cluster.
Stage 2 · ≈ 1M spans/sKeep the right traces
Services + SDK
Routing tier
Sampling collectors
Search clusterSpan metricsQuery
Route by trace id, decide at the tail, count metrics first.
Stage 3 · ≈ 5M spans/sStore it cheaply
Services + SDK
Routing tier
Sampling collectorsSpan stream
Block writersTrace blocksTrace index
A stream for bursts, blocks in object storage, a slim index.
Stage 4 · ≈ 50M spans/sRun it fleet-wide
Services + SDKHost agents
Routing tierSampling config
Sampling collectorsSpan stream
Block writersTrace blocksTrace indexSpan metrics
An agent per host batches and scrubs; teams own their rules.
Was this walkthrough useful?Your vote tells us what to improve next.