Course contentsShow
← System Design
Lesson 1222 of 1,91931. Observability: TracingFree lesson

Trace ID and Span ID

How unique identifiers for traces and spans enable correlation of operations across service boundaries.

Trace ID and Span ID

What You'll Learn

You'll learn how unique identifiers for traces and spans enable correlation of operations across service boundaries in distributed tracing.

The Need for Unique Identifiers

In distributed tracing, operations flow across multiple services—a user request might traverse authentication, inventory, payment, and shipping services. Without unique identifiers, you'd have no way to stitch together logs and operations from different machines into a coherent story of what happened.

Trace ID: The Journey's Passport

A Trace ID is a globally unique identifier assigned to an entire request journey. Think of it as a passport number that travels with a tourist across multiple countries—every checkpoint stamps the same passport, allowing you to reconstruct the complete journey later.

When a request enters your system, it receives a Trace ID (often a UUID or random 128-bit number). This ID propagates to every service and operation involved in handling that request. All spans belonging to the same user request share the same Trace ID.

Span ID: Individual Operations

A Span ID uniquely identifies a single operation within a trace. While the Trace ID groups all related work together, each span needs its own ID to distinguish individual steps. Think of spans as individual flight segments on a trip—they all share the same booking reference (Trace ID), but each flight has its own ticket number (Span ID).

Correlation Across Boundaries

When Service A calls Service B, it passes both the Trace ID and its own Span ID (which becomes the parent span ID for Service B's operations). Service B creates new spans with new Span IDs but maintains the same Trace ID. This parent-child relationship lets tracing systems reconstruct the call hierarchy.

Key Takeaway: Trace IDs group all operations for a single request across services, while Span IDs uniquely identify individual operations within that request, enabling complete visibility into distributed system behavior.