liveBook · Manning

Correlation id

As explained in Grokking Software Architecture

An identifier shared across related operations, messages, or log records so their activity can be traced across components.

A user clicks Buy, and an order service finishes its work. Five seconds later, a shipping service wakes up—and something fails. A correlation ID is the breadcrumb shared across those related operations, so their records can be pieced together even when there is no single stack trace to follow. section 7.5.3 section 7.6.5

Generate a unique ID at the start of the request, then carry it through each handoff: API, database, event, queue, and consumer. Include the same ID in the relevant logs. Filtering by it turns a pile of unrelated messages into a request’s story across services. section 7.5.3

The ID is the thread, not the whole story: useful tracing also needs information about the services involved, their order, and the state passed between them. Centralized distributed tracing uses the shared ID to connect those details across network boundaries. section 12.6.1 section 7.9

[T+00s] [Producer] [ID: 8f42a...] Comment 'Your code smells' dropped in channel.
[T+00s] [Producer] HTTP 200 OK returned to user.
---------------------------------------------------
( ... 3 seconds of awkward silence while GPU spins ... )
[T+03s] [AI Consumer] *Yawn* Waking up...
[T+03s] [AI Consumer] [ID: 8f42a...] Oh look, a message! AI Inference starting...
[T+03s] [AI Consumer] Analysis Complete: TOXICITY DETECTED! Banning User.
[T+03s] [AI Consumer] ACK sent.

The producer and AI consumer show the same ID despite a three-second gap. The user receives a response before the consumer finishes. section 7.7.3

A practical check: confirm that both the producer and consumer logs display the same ID. If the ID disappears at a handoff, the breadcrumbs stop there. section 7.7.2 section 7.5.3

How Grokking Software Architecture covers it

How deep it goes
Explains ID generation and propagation, while deferring instrumentation mechanics such as baggage propagation and spans.
Examples
Uses an order-to-shipping failure and an asynchronous comment-processing exercise with matching producer and consumer IDs.
What you can do after
Diagnose distributed failures by following a shared ID through related logs and service handoffs.
How it connects
Connects correlation IDs to event-driven architecture, structured logging, distributed tracing, and microservices.

Also explained in

Compare how 8 books explain correlation id →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.