Dapper, a Large-Scale Distributed Systems Tracing Infrastructure
2010 · Google Technical Report · ~11 min read
Read the original paperDapper records one request across every service it touches as a tree of spans, sampled cheaply enough to leave on in production. Read it to understand the model behind OpenTelemetry and the costs its sampling and collection choices still carry.
A user types a query and the results take 900 ms instead of the usual 200. Behind the search page sit dozens of services: query rewriting, spelling, several index shards, ranking, ads, images, news, each run by a different team, each with its own dashboard. Every dashboard looks normal. Each team can truthfully say its median latency has not moved. The slow request is real, and nobody can see it.
Logs did not help much. A machine’s log says what that machine did, not which user request it was doing it for or what that request was waiting on elsewhere. Matching log lines by timestamp across hundreds of machines is guesswork. The Dapper paper describes the tracing system Google built to follow a single request across every process it touches, and the two constraints that shaped it: it had to cover nearly every service without each team doing work, and it had to be cheap enough to leave on in production all the time, because the slow requests you need to see happen when nobody is watching.
After this page you should be able to read a trace and find its critical path, explain how a trace id gets from one process to the next, work out how many traces a given sampling rate produces, and recognise Dapper’s design inside OpenTelemetry. We will use one search request that took 126 ms.
What a single machine’s log cannot tell you
Before Dapper there were two families of tracing systems. Black-box systems, such as Project 5 from HP Labs, recorded messages between components and inferred the causal path statistically, which needs no changes to applications but gives approximate answers and needs a lot of data. Annotation-based systems, such as Pinpoint and X-Trace, had applications tag every message with a request id, which gives exact answers but needs every application changed.
Dapper is annotation-based, with one decision that made it practical at Google: the annotation lives in the shared libraries that every service already used, not in each service. Google’s binaries were built on a small set of common libraries, so instrumenting those few places covered nearly everything. That decision is the reason Dapper could be ubiquitous, and it is also the source of its main blind spot, which we will come to.
A trace is a tree, and the ids do the stitching
Dapper models a request as a trace: a tree of spans. A span is one unit of work, usually one RPC as seen by one server. It records a name, a start and end time, its own span id, the id of its parent span, and the trace id it belongs to. A process may also attach annotations to its span: timestamped text notes or key-value pairs.
Here is how our 126 ms request gets its tree. When the front end receives the HTTP request, it creates a root span and a new trace id, and stores both in thread-local storage. When it calls search.Query, the RPC library copies the trace id and the current span id into the outgoing request. The search server reads them, creates a child span whose parent is the front end’s span, and puts that in its own thread-local storage. When search hands work to a callback that runs on another thread, Google’s control-flow library carries the context with the callback. Repeat this at every hop and every span knows its parent, even though no machine ever saw the whole tree.
For an RPC, a span holds timestamps from both sides: when the client sent the request, when the server received it, when the server replied, and when the client got the reply. Those come from different machines with different clocks, and the paper notes the skew. The client’s send and receive times bound the server’s times, which is usually enough to tell network delay from server work.
Now change one variable. Suppose the ranking team uses its own thread pool rather than the shared control-flow library. Work handed to that pool loses its trace context. The database call ranking makes from inside the pool goes out with no trace id, so it either starts a new, orphaned trace or is not traced at all. The tree for our request now ends at ranking.Score, and the database call that made it slow is invisible. The paper names this limitation: applications using non-standard control flow or communication libraries need manual instrumentation. Coverage by shared libraries is very wide, but it is never complete, and the gaps are exactly where nonstandard code lives.
Reading where 126 milliseconds went
A trace is most useful drawn as a waterfall: each span a bar on a shared time axis. In our request the front end spends 4 to 18 ms on auth.Check, then calls search.Query and ads.Select in parallel. Ads finishes at 58 ms. Search fans out to an index lookup and then ranking, and ranking waits on a database read of user preferences that took 34 ms when its median is 6 ms.
In this request, if ads.Select became 30 ms faster, how much sooner would the user get the page? And if the database read dropped from 34 ms to its usual 6 ms?
Show the worked answer
Making ads faster saves nothing. Ads runs in parallel with search and finishes at 58 ms, while the front end waits until search returns at 116 ms. Ads is not on the critical path.
The database read is on the critical path: front end, then search, then ranking, then the database. Cutting it by 28 ms brings ranking and search back by about 28 ms, so the request finishes near 98 ms, as long as nothing else was overlapping in a way that now becomes the limit. Finding the critical path is the first thing to do with any trace.
Each bar is a span: one unit of work in one service, with its parent recorded so the tree can be rebuilt from scattered logs. Click a span.
Sampling is what made it possible to leave tracing on in production. One request in a thousand still gives thousands of traces a minute, and the slow patterns show up in that sample just as they do in the whole.
No dashboard in our opening scene would have shown this. The database’s median was normal. Only the trace connects one slow read to one slow page.
Deciding at the root which requests to keep
Tracing every request would cost too much. The paper measured the effect of sampling rate on a web search cluster: tracing every request added noticeably to average latency, tracing one in sixteen cost much less, and at one in 1,024 the difference was lost in measurement noise. Creating a span takes a couple of hundred nanoseconds; writing it to disk and shipping it costs more, and that is what sampling saves.
The sampling decision is made once, at the root, and travels with the trace context. Every downstream server either records its span or does not, according to that one bit. This matters more than it seems. If each server sampled independently at 1 in 1,024, a trace through five services would be complete with probability one in 1,024 to the fifth power, which is effectively never. Deciding at the root gives whole trees or nothing.
At 10,000 requests per second and 1 in 1,024, the front end produces about ten traces a second, or 36,000 an hour. That is plenty to see every common path and most uncommon ones. Now change the traffic. A low-volume service that gets five requests a minute, at the same rate, produces one trace roughly every three and a half hours, which is useless. Dapper therefore added adaptive sampling, which sets a target number of sampled traces per unit time rather than a fixed fraction, so quiet services sample more of their requests.
There is a second stage. Even sampled traces produced more data than the team wanted to store, so the collectors hash each trace id to a number between zero and one and keep the trace only if that number falls under a collection threshold. Because the hash depends only on the trace id, every span of a trace makes the same decision, and the team can turn down storage volume without touching any running binary.
What head sampling gives up is the rare event. If one request in a million hits a bug, a 1 in 1,024 sampler records about one occurrence per thousand. Later systems answered this with tail-based sampling: record every span briefly, decide after the trace is complete, and keep the slow or failed ones. The cost is buffering everything and routing all spans of a trace to one place before deciding.
Why the trace data travels out of band
Spans are not sent with the request or the response. Each process writes its spans to local log files. A Dapper daemon on every machine reads those files and sends the spans to collectors, which write them into Bigtable with one row per trace and one column per span. Bigtable’s sparse rows suit traces well, since each trace has a different number of spans.
The authors give two reasons for keeping trace data off the request path. Adding spans to RPC responses would change the size and timing of the very traffic being measured. And many RPCs are not neatly nested: a server may reply to its caller before its own children finish, so their spans would have no response to ride on. The cost is delay. The paper reports a median of under fifteen seconds from writing a span to finding it in the repository, but the slow end was much worse, sometimes hours. That made Dapper good for understanding behaviour and weaker for firefighting during an incident.
By default, Dapper recorded RPC method names and timings, not payloads. Application data only appeared in annotations a developer added on purpose. This kept the tracing system from becoming a copy of every user’s data, and it had a side benefit: the traces showed which services talked to which, which helped check that services were following security policies about who may call what.
How engineers actually used a trace
Storing traces is only half of the system. Dapper exposed its repository through an API that could fetch a trace by id, scan traces in bulk with MapReduce, or look them up through an index by service, host and time. Most engineers used a web interface built on top. The workflow the paper describes starts from a question, not a trace id: pick a service, a time window and a metric such as latency, and the interface shows the distribution of that metric across sampled traces. You then select an outlier from the slow end and open its waterfall.
That order is worth copying. A single trace is an anecdote. The distribution tells you whether the request you are looking at is typical or one of the 1 per cent, and the waterfall then tells you which span made it so. Today’s tools that plot latency heat maps and let you click through to an example trace follow the same path.
Now walk through a case the trace model handles badly. A storage server buffers writes and flushes them to disk in batches of twenty. Our search request happens to be the one whose write fills the buffer, so the flush runs inside its span. The trace shows a 40 ms disk write that the request did not really cause, and the nineteen other requests whose data was in the batch show nothing. The paper calls this a coalescing effect. An engineer reading the trace would blame the wrong thing, or at least the wrong request.
The fix later systems adopted is to let a span refer to more than one parent. In OpenTelemetry, a batch span can carry links to the spans of every request whose work it contains. The cost is that the data is no longer a simple tree: queries and displays have to handle a graph, and most tools still show links as a secondary detail. Queues and asynchronous messaging have the same problem, since the consumer’s work belongs to a request whose span may have finished long before.
What the choices bought and cost
| Choice | What it bought | What it cost | What later systems did |
|---|---|---|---|
| instrument shared libraries | coverage without each team’s effort | blind spots wherever code bypasses them | OpenTelemetry offers auto-instrumentation plus an explicit API for the gaps |
| sample at the root, about 1 in 1,024 | overhead lost in the noise | rare requests usually missed | tail-based sampling in collectors |
| collect out of band via local logs | serving path untouched | seconds to hours of delay | streaming exporters and collectors |
| record names and timings, not payloads | privacy and small spans | less context per span | attributes added deliberately by developers |
The experiences section of the paper is a set of short case studies. Google’s Ads Review team used traces during a large rewrite of their serving system to find latency problems early. Traces were joined to exception reports, so an engineer looking at an error could see the request around it. Traces were aggregated to infer which services depended on which, something no document had kept current. Network and storage use were attributed back to the services that caused them. The paper also lists what Dapper could not do well: work that is batched together gets attributed to whichever trace happened to trigger the batch, offline batch jobs do not fit the request model, and a trace shows that a span was slow without saying why, for example whether it sat in a queue.
From Dapper to OpenTelemetry
Twitter’s Zipkin (2012) reimplemented Dapper in the open, and Uber’s Jaeger followed. Two standardisation efforts, OpenTracing and OpenCensus, merged in 2019 into OpenTelemetry, which now defines the API and wire format most tracing tools use. The W3C Trace Context standard carries Dapper’s context in an HTTP header:
traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
│ └ trace id (128 bits) └ parent span id └ flags: 01 = sampledEvery part of that header is in the paper: the trace id, the id of the calling span, and the sampling decision made at the root. The ids grew from 64 bits to 128 to make collisions across organisations negligible.
Tracing is not always worth its setup. A single service with a request id in every log line can be debugged without it. The case for tracing grows with the number of services a request crosses and the number of teams that own them, which is exactly the situation Dapper was built for.
How to read the original
It is a technical report, not a conference paper, so it reads more like a design document with experience attached. Read section 2 for the trace model, where instrumentation lives, and how spans are collected; look closely at the figures of a span and its annotations. Section 4 covers overhead and sampling, including the table relating sampling rate to latency and throughput in web search (check what was measured and on what workload), adaptive sampling, and the second sampling stage at collection, which is easy to miss.
Sections 5 and 6, on the tools built on Dapper and the experiences of teams using it, are the most useful part, and the section on lessons and limitations that follows is worth reading twice. The related-work section explains why Dapper chose annotations over black-box inference. There is no controlled evaluation in the usual sense, so treat the numbers as one company’s production measurements.
Dapper shows you which span was slow. The next paper, The Tail at Scale, explains why some span is almost always slow when a request touches enough servers, and what to do about it.
The original. Read it after this page; the explainer above is a map, not a substitute.
Today's open standard for the spans and traces Dapper introduced.
An open-source tracing system built directly on the paper’s design.