Back to sketch

SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 41

Design a distributed tracing system

Advanced · 45 min · Observability

A checkout request touches dozens of services before it returns. When it is slow or fails, an engineer wants to open that one request and see every call it made, in order, with timings and errors, instead of guessing from averaged graphs.

Requirements

  • Carry trace context across service calls over HTTP, RPC and message queues.
  • Record spans: service, operation, start time, duration, status, parent span and tags.
  • Fetch a full trace by ID and show it as a waterfall; search traces by service, operation, duration, error and tag over a time range.
  • Keep every trace that contains an error or is unusually slow; sample the rest.
  • Show a service dependency map with call rates between services.

Constraints and assumptions

  • 2,000 services; 1 million incoming requests per second at peak; an average trace has 30 spans of about 500 bytes.
  • Instrumentation may add at most 1% CPU and well under 1 ms of latency to a request.
  • The storage budget is about 20 TB of spans per day; traces are kept for 7 days.
  • Most spans of a trace arrive within 30 seconds of the request finishing; spans from asynchronous consumers can arrive minutes later.
  • Searches over the last hour should return in under 5 seconds.

Out of scope for the first sketch

Log storage and log search · Continuous profiling · Automatic root-cause analysis

Draw your design

Rough math and notes

Done on paper? Compare with the worked approaches