Skip to content
tezvyn:
Menu

Distributed Tracing: Following a Request Across Microservices

Source: opentelemetry.ioMediumHow cards are made

Distributed tracing is like a passport for a request, stamped at every service it visits. It's essential for debugging microservices where one click can trigger many calls. The footgun is trying to debug without it, piecing together isolated logs.

Why it exists

In a monolithic application, a single stack trace can pinpoint an error. In a microservices architecture, a single user request might hop between a dozen services. If it's slow or fails, you're left trying to correlate timestamps across a dozen different log files. Distributed tracing was created to solve this chaos.

The mental model

Think of it like a package delivery with a tracking number. The package is your request, and the tracking number is a unique 'Trace ID'. At every stop—the web server, the authentication service, the database—the request's journey is scanned. All these scans are sent to a central system, which reconstructs the package's full journey, showing exactly where it went and how long it spent at each stop.

How it works

When a request first enters your system, it's assigned a unique Trace ID. The work done by that first service is a 'span'. When it calls another service, it passes the Trace ID along in the request headers—a process called context propagation. Each subsequent service creates its own spans, all linked by the same Trace ID. An observability backend collects all these spans and assembles them into a single, chronological waterfall graph, showing the entire request lifecycle.

When to use it

It is indispensable in any distributed system, especially microservices. Use it to diagnose latency bottlenecks ('Why did this API call take 2 seconds?'), find the root cause of errors ('Which downstream service failed first?'), and understand complex dependencies between services.

When not to use it

For simple, monolithic applications, it can be overkill; traditional logging and metrics are often sufficient. Tracing also introduces a small amount of overhead for instrumentation and data collection, so it requires careful implementation in extremely high-throughput, low-latency systems.

One canonical example

OpenTelemetry provides a vendor-neutral standard for tracing. You can use its APIs and SDKs to instrument your code once. Then, you can send that telemetry data to any backend, like Jaeger, Prometheus, or a commercial vendor, using the OpenTelemetry Collector. This prevents vendor lock-in and allows you to switch observability tools without rewriting your application's instrumentation.

Interview question

In a microservices architecture, what is the main problem distributed tracing is designed to solve?

  • a.Providing a comprehensive, end-to-end view of a single request's flow and performance across services.Correct
  • b.Automatically re-routing failed requests to healthy service instances.
  • c.Reducing the overall network overhead between services.
  • d.Ensuring data consistency across multiple service databases.
Why?

Distributed tracing's core purpose is to provide a unified view of a request's journey across many services, solving the chaos of correlating isolated logs. While tracing helps diagnose latency, it does not automatically re-route requests or ensure data consistency, which are handled by other system components.

Just read this? Test yourself on what you have been reading.

Read the original → opentelemetry.io

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on observability — each one lists the topics its interview covers.

See open roles