liveBook · Manning

Correlation id

As explained in Kafka for Architects

A correlation ID is an identifier carried with related request and response messages so they can be matched.

In request-response messaging, a correlation ID is a shared identifier that lets a service match a reply to its request. In Kafka, it is commonly carried in a message header and echoed in the response. section 7.1.2

Matching messages is only part of the design: the response must also reach the service instance that holds the request context. If a consumer fails and another instance takes over its partition, that instance may lack the context needed to process the reply. RabbitMQ uses the same matching principle with a reply queue and correlation ID. section 7.1.2 section 5.3.1

Figure 7.5 Both services participating in the request-response pattern have a producer and consumer container. The request and response are matched using the correlation ID, specified in the message header.
A diagram of a flowchart

AI-generated content may be incorrect.

The diagram shows request and response services matching messages through the correlation ID in their headers. section 7.1.2

How Kafka for Architects covers it

How deep it goes
Defines header-based matching and explains response-routing and lost-context problems, without detailing a complete recovery implementation.
Examples
Uses a CORRELATION_ID header in Kafka services and matching IDs on RabbitMQ request-reply queues.
What you can do after
Understand how a shared identifier pairs a reply with its request and why routing it to the originating service instance matters.
How it connects
Connects request-response messaging with message headers, reply queues, consumer groups, and partition assignment.

Also explained in

Compare how 5 books explain correlation id →

Related concepts

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