Design a Distributed Tracing
Design a distributed tracing system for a company with thousands of microservices. When a request enters the system, every service it touches records a span: which operation ran, when it started, how long it took, whether it failed, and which span called it. Engineers open a trace by its id from a log line or an error report, or search for traces such as “checkout calls slower than 2 seconds in the last hour”, and see the whole request as a waterfall across services.
There are 5,000 services on 200,000 hosts, taking 2 million requests a second at the edge. Each request creates about 25 spans, so the fleet produces 50 million spans a second, about 25 GB a second before compression. Keeping all of it is unaffordable and almost none of it is ever read, but the one trace an on-call engineer needs at 3 a.m. must be there. The hard parts are deciding what to keep without knowing in advance which requests will fail, never slowing the services being traced, and keeping the data cheap to store and fast to find.
Good questions to ask first
Decide what you would assume for each before you look at ours.
- 1Do we need every trace?
- 2How quickly must a trace be searchable?
- 3How long do we keep traces?
- 4May tracing slow down services?
- 5Do we need metrics too?
- 6Which protocols?
- 7Multiple teams and tenants?
- 8Is logging in scope?
How to spend the 45 minutes
- 5minPart 1: Requirements and scope
- 5minPart 2: Estimates
- 5minPart 3: API and data model
- 15minPart 4: Architecture, stage by stage
- 15minPart 5: Deep dives: sampling, storage, metrics