Distributed Tracing
How traces work, head vs tail sampling, and why traces are the highest-leverage signal for microservice debugging.
Overview
Where did the time go?
Distributed tracing answers a question metrics and logs can't: 'this user request took 5 seconds; where did the time go across our 12 services?'
To see how, follow one request through four components.
- The gateway starts the root span and calls Orders, which records a span for POST /orders.
- Orders calls Inventory, which records a span for the stock check.
- Inventory runs a SELECT against the database, and that query is a span of its own.
- The query is slow. The database answers Inventory, Inventory reports back to Orders, and Orders reports back to the gateway.
Because every hop left a span, the trace points straight at the slow query.
Key concepts
- Trace
- Span
- Parent-child link
- Head sampling
- Tail sampling
- W3C traceparent
Interview questions
- How does head sampling differ from tail sampling — and which should I use?
- What's the difference between a span attribute and a baggage item?
- Distributed tracing has overhead. How do you minimise it?
Sign up free to read the full topic
More SRE topics
Start free on Cariara · Coding problems · System design studio