Video in progress
Should you use Kafka for synchronous request-reply? One team is proposing it instead of HTTP.
Technically it's possible (Spring has ReplyingKafkaTemplate), but it usually combines the drawbacks of both worlds: you keep HTTP's coupling and add Kafka's delay and complexity on top. Unless there's a specific reason, I'm against it.
📖 Answer
The proposal is often justified like this: "Kafka is more reliable, messages don't get lost". But in request-reply the caller is still waiting for the answer. If the responding service is down, the request is stored in the topic, but the caller times out after 5 seconds and returns an error to the user. Then if the request gets processed later, nobody needs the response any more, while the effect has already happened.
Additional problems:
- managing the reply topic and the correlation ID: each instance needs its own reply partition, otherwise the response lands on a different pod;
- latency: producer batching and consumer polling add noticeably more than a plain HTTP call, especially under low load;
- debugging gets harder: you can't just check with
curl; - timeouts go both ways: when does the request message "expire"? The consumer must drop requests that are past their deadline.
When it might make sense:
- the responder is reachable on the network only through Kafka (an isolated segment);
- the result is actually asynchronous: the user gets "accepted" back, and the result arrives later by push or polling. But that isn't request-reply, it's an ordinary event-driven design.
What I usually propose to the team: where a synchronous answer is needed, HTTP/gRPC + timeout + retry + circuit breaker. If the real problem is coupling (when one service goes down, the other stops working too), then redesign the process to be asynchronous: accept the command and report the result later. Putting Kafka in place of HTTP doesn't remove that coupling, it only hides it.
Sign up to mark studied questions and save your progress.