API / Microservices Design Patterns Interview Questions
What is the Distributed Tracing pattern and how do trace context headers propagate across services?
Distributed Tracing reconstructs the end-to-end path of a single request as it flows across multiple microservices, providing a flamegraph of timings that reveals where latency accumulates and where failures occur. Without it, correlating logs from 10 services for a single slow request requires manual, error-prone cross-referencing.
Key concepts:
- Trace — the complete journey of a request, identified by a globally unique
traceId. All spans belonging to the same originating request share this ID. - Span — a named, timed unit of work within a single service (e.g., "HTTP GET /orders/42", "DB SELECT orders", "Kafka publish OrderPlaced"). A span records start time, duration, service name, tags (metadata), and the
parentSpanIdlinking it to its caller. - Context propagation — the tracing library injects the trace context into outbound call headers; the receiving service extracts it and creates a child span with the correct
traceIdandparentSpanId.
# W3C Trace Context header (standard across OpenTelemetry, Jaeger, Zipkin)
traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
# version-traceId(128-bit hex) -spanId(64-bit)-flags
# Outgoing HTTP request from Service A to Service B includes this header.
# Service B extracts traceId + parentSpanId, creates its own child span.
# All spans are sent asynchronously to Jaeger / Zipkin / AWS X-Ray.
Two propagation standards are in common use:
- W3C Trace Context (
traceparent+tracestateheaders) — the IETF standard, supported natively by OpenTelemetry. - Zipkin B3 headers (
X-B3-TraceId,X-B3-SpanId,X-B3-ParentSpanId,X-B3-Sampled) — older but still widely used by Istio, Zipkin, and some Jaeger deployments.
For async messaging, the trace context is injected into message headers (Kafka record headers, AMQP headers) so traces span across broker boundaries.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
