Try
↑ ↓ move↵ openesc close

Interview prep / Distributed tracing

Senior · Distributed tracing · System design interview question

A request puts a message on a queue and a worker processes it later. The trace splits in two at the queue. How do you keep it connected, and what do you do when one message belongs to many requests?

Sketch your own answer first, then compare it with the one below.

A strong answer

Treat the message as a carrier. The producer writes the trace context into the message headers when it publishes, and the consumer reads it when it starts processing and creates its span as a child, or with a link, to the producer's span. OpenTelemetry's messaging conventions use links as the default and allow a direct parent only when a consumer handles a single message.

For batches, a worker may handle messages from many traces at once. Create one span for the batch and add a link to each message's context, instead of picking one parent. That keeps every origin findable without pretending the batch belongs to a single request.

Be honest about latency in the picture. The time a message waits on the queue is part of the user's wait but it is not work in either service, so show it as its own span or gap. Two details remain. Clocks differ between hosts, so a consumer span can appear to start before its producer. And retries and dead-letter paths need the same context, or they fall out of the trace.

Sources

  • Sergey Kanzhelev, Morgan McLean, Alois Reitbauer, Bogdan Drutu, Nik Molnar, Yuri Shkuro (2021). Trace Context.
  • OpenTelemetry project (2024). Traces.

Learn it by running it

The distributed tracing lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms