liveBook · Manning

Request-response API

As explained in Kafka for Architects

A request-response pattern is a communication pattern in which one service sends a request and another service returns a corresponding response.

A request-response API lets one service send a request and receive a corresponding reply. It contrasts with event-driven communication, where services communicate by triggering events. Kafka can support this pattern, but it is identified as a poor match compared with its strengths in asynchronous microservice communication. section 1.9 section 7.0

The requester must correlate each reply with its request and ensure that the reply returns to the service instance that sent it. A correlation ID in the message header provides the match. Failures complicate recovery: a replacement consumer may receive the partition without the original request context and therefore cannot process the response correctly. section 7.1.2 section 7.1.2

Correlated response flow

A requester sends a message with a CORRELATION_ID header and expects the responder to echo it in the response. The message may also identify the response topic and partition, allowing the responder to route the reply to the intended service instance. section 7.1.2 section 7.1.2

Figure 7.6 The availability of RequestResponseService is problematic, as another instance does not have the original request context.
A diagram of a diagram

AI-generated content may be incorrect.

Shows why request-response availability is difficult when another service instance lacks the original request context after failure. section 7.1.2

How Kafka for Architects covers it

How deep it goes
Explains correlation and failure hazards, but stops short of detailing recovery strategies beyond identifying implementation approaches.
Examples
Uses correlation headers, response topics, partitions, service instances, and failure-reassignment scenarios.
What it assumes
Assumes distributed services, producers, consumers, partitions, and consumer groups, while contrasting them with publish-subscribe behavior.
What you can do after
Apply it via Spring Kafka while accounting for correlation, response routing, and lost request context after consumer failure.
How it connects
Connects request-response with event-driven architecture, publish-subscribe, consumer groups, correlation IDs, and Kafka.

Also explained in

Compare how 2 books explain request-response API →

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.