Ch.57: Distributed Tracing System Design: The Missing Trace
Outline
- 0:00 The slow checkout with no trace
- 0:41 Two paths through the architecture
- 1:14 What the engineer needs to find
- 1:58 Put a budget behind the request
- 2:55 Spans and trace context
- 3:55 Head sampling versus tail sampling
- 4:40 A finite export queue
- 5:34 Group before you judge
- 6:22 Waiting does not prove completeness
- 7:19 Adding collectors can split a trace
- 8:29 The error arrives too late
- 9:20 Where durability begins
- 10:12 Search first, open second
- 11:04 Bound the investigation's cost
- 11:43 Recovering pending evidence
- 12:46 Test the promised investigation
- 13:41 Return to the complete architecture
- 14:15 The customer still waited
Transcript
0:00 A customer waits 6 seconds for checkout. It called inventory, then payment. Distributed tracing records the operations across those services so an engineer can follow that one request. But the tracing system has no record of this slow checkout. So we aren't designing checkout itself. We're designing the system an engineer uses afterward to find where that request spent its time. Exactly. Let's design the backend that groups a request's recorded pieces, decides what to retain and retrieves it later.
0:28 Our slow checkout starts normally. If we discard it too early, the expensive database at the end won't help. Then the decision about what to keep belongs in the design, not in a footnote after storage. Now put that retention decision on the complete architecture map. Checkout calls inventory and payment. Separately, those services export their records through small buffers. Collectors group the records and decide what survives; storage and search make the retained evidence available to engineers.
0:57 Those are separate arrows. Payment can finish while its tracing records are still traveling. We'll come back to this map when we can explain why that separation sometimes costs us a trace. We could build a fast store that can't find the customer's case. Which questions must search answer first? First, define our functional requirements for retrieval: accept operation records from services and open a request using its trace identifier. Also search retained recent requests by service and time window.
1:25 For example, find slow checkouts from the last 10 minutes. That last question matters. The engineer might know when the customer complained, but not the request's identifier. Search must give us candidate traces before we open one. And “retained” is doing real work here. We're not promising a searchable copy of every production request. We need an explicit answer when storage is unavailable, rather than quietly displaying no matches. Good. A blank result mustn't become evidence that checkout was healthy.
1:54 What resources can we spend getting those records there? With those queries defined, the non-functional requirements start with checkout: it must not wait for a tracing outage to end. Bound memory and ingestion work, isolate tenants and keep recent retained traces searchable. Suppose our exercise handles 10,000 requests a second, averaging eight recorded operations each. That's 80,000 records a second. At an illustrative kilobyte each, roughly 80 megabytes a second before overhead. If we hold 10 seconds of input, that's 800 megabytes of raw records across the collection system.
2:31 And that raw payload total excludes object overhead, bursts and one collector receiving too much. It isn't a machine-sizing answer. It tells us that waiting for more information has a memory price. Let's aim for retained traces to appear within 30 seconds under normal load, and keep them for a day. Those are our chosen targets to test. What exactly is one of these records? To make the data path concrete, take a checkout call to inventory. A span records that operation's identity, timing and outcome.
3:02 Related spans share the trace's identity; a parent identifier tells us which operation initiated another. One request becomes several connected pieces. How does inventory know that it's handling part of our checkout, rather than starting an unrelated trace? Checkout passes tracing context with the call. The W3C trace-context standard defines that HTTP propagation format. The official links are in the description. Then the identity can travel with the request. But if inventory never records its span?
3:31 Our backend cannot invent that missing operation afterward. And if a service loses the context, we can't reliably join its records to this checkout. We can connect the pieces we received. Right. Before any of those pieces reaches storage, someone may decide not to record it at all. Even before export? How can we decide a request isn't worth keeping when it's just begun? Before spending more on storage, imagine randomly keeping one request in 100 when it starts. That's head sampling: decide early.
4:03 Our 6-second checkout could be among the 99 discarded requests. Like setting aside one unopened case file from 100. We haven't seen the ending yet. Could the payment service notice the delay and ask for those earlier records again? Only if something actually kept them. OpenTelemetry's sampling guidance says head sampling alone cannot ensure retaining every later error. A downstream decision cannot recover records that were never exported or have already been discarded. Then let's look inside the files before choosing.
4:31 That's tail sampling: use observed outcomes. But we need room for the candidate records first. Storage savings don't automatically become ingestion savings. Before that delayed decision, the application needs to export spans without waiting on every network hop. It puts them in a finite local queue; a background exporter sends batches to the collector. If the collector is unavailable, that worker can't empty the queue. What happens when it fills? Our policy drops telemetry and counts that loss instead of blocking checkout. The queue still costs work and memory; we aren't promising zero overhead.
5:04 A collector failure shouldn't decide whether checkout can succeed. Uber's early Jaeger team moved routing into a local agent so application teams had less setup. That's historical rationale; it doesn't choose our transport. Okay, but the local exporter saying “queued” isn't the backend saying “durably stored.” If the process crashes before export, those spans may disappear. Yes. We accept that loss boundary to keep the customer request independent. Now we can route what arrives. Which collector should receive it?
5:34 Once records reach ingestion, my first thought is to spread batches evenly across collectors. But our checkout's fast inventory span could reach one machine and its slow payment span another. If they decide independently, they judge different fragments. So ingestion authenticates the service's tenant, then routes by tenant and trace identifier to one decision owner. OpenTelemetry's collector-scaling guide specifically warns about splitting traces across stateful samplers. And a tenant is the customer or team whose data we isolate.
6:01 An untrusted incoming identifier cannot prove access. Validate record sizes and approved attributes before buffering. If inventory exports a request-body attribute, reject that field. Passwords and tokens don't belong in our trace records either. That gives the related spans a meeting place. Now what tells the owner it has waited long enough? With each trace grouped, start a 10-second timer when its first span arrives. Collect the pieces during that interval. At the deadline, favor observed errors and checkouts whose root span, the record for the starting checkout operation, reports more than 2 seconds.
6:36 Keep a random baseline of ordinary requests too, so an engineer can compare a slow checkout with one that worked. Why not decide as soon as checkout's root operation finishes? That sounds like the end of the request. The root reports checkout finishing locally. It doesn't report every exporter completing delivery. A child may send in a later batch. Work placed on a queue might run after checkout has returned. We only know what arrived before our decision. Ah, 10 seconds is our waiting policy, not a certificate of completeness.
7:08 Cap each trace's buffered bytes and count drops when it fills. Our eight operations is an average, not a safe allowance for one checkout to consume everybody's memory. That grouping raises a scaling problem. Suppose we add a new decision collector halfway through the wait. A changed routing map sends payment's next span elsewhere. Didn't we just split our checkout again? We could. Inventory is in the old collector's memory; payment hasn't left the application's export queue. I'd hold export during maintenance, let existing decision timers finish, then switch every router to the same collector map before resuming.
7:44 If one router cannot confirm, export stays paused. That settles where new records go. What happens to inventory's record that's already waiting? Its timer keeps running. Suppose those ordinary fragments miss our baseline sample and get discarded before payment arrives. Think of a sorting desk: the staff get a new address list, but the unfinished pile hasn't moved. Payment reaches another desk after export resumes. Ah, everyone agrees which desk gets payment. Nobody moved inventory's pile. Routing agreement didn't preserve the unfinished checkout.
8:15 Exactly. Finite export queues can overflow too. We measure and expose that loss interval. If unfinished traces must survive the change, we need durable pending records and a real handover protocol. A routing rule alone supplies neither. Now the on-call engineer says, “Keep every error. That's the request I'll need.” But payment reports its error after our owner has discarded the ordinary fragments. The error wasn't present when we decided. Could we keep a small cache of decisions? Then the late span at least gets the same answer as its earlier fragments.
8:47 Yes, for the period that decision remains cached. The tail-sampling processor documents late spans inheriting a retained decision; once it forgets the trace, a later fragment can be treated as new input. A decision cache is bounded too. And if the cached answer was discard, consistency won't recover the old spans. We can choose a longer wait or spend more on recoverable buffering, but we can't call this an unconditional promise to retain every error. When can we promise selected spans survive one failed machine? Then suppose the 6-second root span did arrive in time.
9:23 We select that checkout and send its recorded pieces into retained storage. Our backend acknowledges durable acceptance only after two replicas on different machines have persisted the selected batch. That's our policy for surviving one machine failure. Not a guarantee about the records still sitting in the application's queue, or the undecided traces in another collector's memory. Those haven't crossed this boundary. Correct. Jaeger's architecture separates collectors from queries and documents persistent buffering as an alternative to direct storage.
9:53 In our retained path, retries still carry the original span identities. Replaying a span isn't a second payment call. So store by tenant, trace identifier and span identifier, and deduplicate matching retries. We now have retained pieces. How do we find this checkout without knowing which trace to open? Now follow that search for slow checkouts. For each retained trace, index a small summary: its tenant, root service and operation, start time, root duration and observed outcome. Ask for checkouts in that recent window above 2 seconds, then fetch a matching trace's spans by identifier.
10:30 Our checkout's recorded duration now makes it discoverable as slow. A trace-identifier key alone couldn't answer that search. But if the root is missing, we don't know the checkout duration; that mustn't turn into a “fast” label. Exactly. And if indexing lags storage, a trace may be fetchable by identifier before it appears in search. Return that freshness limit. The index should lead to readable evidence, not promise immediate discovery. With that separation, we can scale collection and reads independently.
11:00 But letting callers search every attribute would give us another unbounded bill. So bound how much work a search can do. You're on call: use that 10-minute window near the complaint. If that exhausts the tenant's work budget, return incomplete and ask for a narrower window. Don't let one broad query occupy every read worker. You narrow it and find a candidate. But that request's storage partition can't be reached. What should the investigation screen say? Unavailable, not “no matches.” You've finally found the right request; the screen shouldn't reassure you with a beautifully empty page.
11:34 Right. That's only a claim about retained evidence. Sampling, missing records and our 1-day expiry can all hide a real failure. That durability boundary leaves the earlier buffer exposed. Let's say its decision owner crashes with undecided spans still in memory. That pending evidence is gone in the best-effort version, isn't it? It can be. For recoverable pending state, persist every candidate on two machines before selection. Keep its original identities and decision deadline. A replacement takes ownership after the old collector fails and replays inventory's saved record. The checkout is pending again, with no extra time for payment.
12:13 Hold on. That's copying every case file before sorting, even the ones we'll throw away. If retention keeps 5%, we pay to protect the temporary 95 too. I think that incident evidence could justify the added recovery work, but I'd want the requirement stated before paying for it. That's the decision I'd want from the requirements discussion. Our current answer accepts measured preselection loss. Its health metrics count drops and decision-buffer pressure without depending on this same tracing path to report them.
12:46 Let's test the investigation, not just ingestion speed. Keep one fixture's records but break context at inventory: the screen must show a gap, not invent that parent connection. Replay payment's original span identifier. We should still see one payment operation. Then use a different fixture: delay a payment error past the decision. With a cached discard, nothing comes back. After that decision expires, the late fragment can be judged again. Neither result reconstructs the earlier checkout. And send the service fragments to separate owners; check that the split is visible.
13:18 Fill the export queue inside the application and crash a pending owner too. The loss counters must change independently of that damaged collection system. Finally make the chosen trace unreadable. The engineer must see an unavailable read, not a clean no-match screen. Load-test our 30-second discovery target too. Throughput alone wouldn't catch that misleading empty search. Now return to the map we saw near the beginning. Follow the 6-second checkout's records: exported spans meet at the chosen collector; its observed slow root gets the trace retained; the indexed duration lets the engineer find that slow checkout and open its recorded operations. Now remove an earlier arrow.
13:59 If instrumentation never made a span, or export dropped it, storage cannot recover it. If the span arrived but its pending owner failed, our best-effort choice can lose it there. A failed read later is different: our stored records may still exist. So finding the slow request required more than a database key. We had to choose where its pieces meet, how long to wait and which losses the service accepts. Yes. A useful tracing backend can preserve a path an engineer can investigate. It must also tell the truth about its limits.
14:34 The customer still waited 6 seconds, whether or not we kept the trace. Thanks for listening to Learning Podcasts.