Quick revision
The short answer
Request-reply over Kafka does not remove the coupling: checkout still waits for inventory, so the services are as coupled in time as with HTTP, and Kafka adds two produce and two consume hops with batching and poll delays that make a 50 ms p99 hard to hold. Replies must also reach the exact instance that is waiting, and a restart or rebalance turns in-flight requests into unknown outcomes. For a synchronous stock check, use HTTP or gRPC with timeouts and a circuit breaker, and use Kafka to keep a local stock view fresh; request-reply over Kafka fits long-running work where the reply is itself a useful event.
What to remember
In this answer, we saw that request-reply over Kafka keeps checkout waiting for inventory, so the services stay coupled in time while the path grows from two network trips to four, which makes a 50 ms p99 hard to hold. We also saw that replies must be routed to the instance holding the future, and that restarts and timeouts turn requests into unknown outcomes. A synchronous call with a timeout and circuit breaker, plus Kafka events for a local stock view, is the better design here, while request-reply over Kafka suits long-running work whose reply is itself a useful event.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Request-reply over Kafka does not remove the coupling: checkout still waits for inventory, so the services are as coupled in time as with HTTP, and Kafka adds two produce and two consume hops with batching and poll delays that make a 50 ms p99 hard to hold. Replies must also reach the exact instance that is waiting, and a restart or rebalance turns in-flight requests into unknown outcomes. For a synchronous stock check, use HTTP or gRPC with timeouts and a circuit breaker, and use Kafka to keep a local stock view fresh; request-reply over Kafka fits long-running work where the reply is itself a useful event.
Why this question is asked
Developers often reach for Kafka because they have heard that events decouple services. The proposal here keeps the shape of a synchronous call but sends it through a broker, and it is worth understanding why that gives us the costs of both styles and the benefits of neither. Interviewers ask this to check whether we know what decoupling really means, how ReplyingKafkaTemplate works underneath, and when the pattern is a good fit. In this answer, we will recap how request-reply works over Kafka, look at the latency, routing and failure problems in turn, and then compare it with a plain synchronous call and with an event-driven design.
1A Quick Recap of Request-Reply Over Kafka
Kafka is built for one-way messages: a producer appends a record to a topic and any number of consumers read it later. To get a reply, we have to build a second one-way path back. Spring Kafka's ReplyingKafkaTemplate does this for us. It sends the request to a request topic with two headers: a correlation id, a unique value that identifies this request, and a reply topic, the topic where the answer should go. The inventory service reads the request, does the work, and sends the answer to the reply topic with the same correlation id. The template, which is also consuming the reply topic, matches the answer to the waiting request and completes a future.
Notice the call to future.get(). The checkout thread sits there until the answer arrives or the timeout expires. That single line tells us most of what we need to know about the design.
2Problem 1: The Caller Still Waits
Decoupling in time means the producer does not need the consumer to be running right now. That is true for a fire-and-forget event, but not here. If the inventory service is down, checkout gets no answer and fails, exactly as it would with HTTP. The broker in the middle stores the request, but nobody is waiting for it by the time it is processed, so durability buys nothing.
Meanwhile, the path is longer. A request makes four trips instead of two: checkout produces, inventory consumes, inventory produces the reply, checkout consumes it. Each produce may wait for batching (linger.ms), each must be acknowledged by replicas when acks=all, and each consume happens on the next poll. Each hop is often only a few milliseconds, but at p99, under load, with a garbage-collection pause or a slow follower, a 50 ms budget for four hops plus the actual stock lookup is very hard to hold. HTTP or gRPC needs one network round trip.
6 messages in order. Play them, or step through them one at a time.
Every arrow through the broker adds batching and polling delay; HTTP has one round trip.
3Problem 2: The Reply Must Find the Waiting Instance
Checkout runs as, say, six instances. The future for a given request lives in the memory of exactly one of them. The reply must reach that instance, but a normal consumer group would spread the reply topic's partitions across all six, so the reply might go to the wrong one.
There are three ways around this. Each instance can have its own reply topic, which means topics come and go with pods. Each instance can be assigned a fixed reply partition and put it in a header, which ReplyingKafkaTemplate supports, but then scaling checkout means managing partition assignments by hand. Or every instance can read every reply and discard those whose correlation id it does not know, which works for small volumes but multiplies the reply traffic by the number of instances. All three are workable; none is as simple as an HTTP response that naturally returns on the same connection.
4Problem 3: Timeouts Become Unknown Outcomes
When a checkout instance restarts or its reply consumer is rebalanced, the futures it held are gone. The template also gives up after its reply timeout, which defaults to a few seconds (five in recent versions; check yours) unless we set a shorter one. Either way, the request is still sitting in the inventory-requests topic and may be processed later.
So a timeout does not mean the operation failed. It means we do not know. For a read-only stock check that is harmless, but if the request reserved stock, a late reservation might happen after checkout already told the customer it failed. The caller must treat every timeout as an unknown outcome and the server must make requests idempotent, for example by keying reservations on the order id. HTTP has the same issue, but it is much more visible there, and the request does not wait in a durable queue for minutes.
5What to Use Instead, and When Request-Reply Fits
For a query that needs an answer now, a synchronous call is the honest choice: HTTP or gRPC from checkout to inventory, with a timeout of around 40 ms, a single retry with jitter for idempotent reads, and a circuit breaker that fails fast when inventory is unhealthy. Kafka still has a strong role next to it: the inventory service publishes StockChanged events, and checkout can keep a local view of stock levels from that stream. Then most checks are answered locally in microseconds, and only a borderline case, such as the last unit, needs the synchronous call.
Request-reply over Kafka does fit some work well: long-running or batch jobs where the reply comes minutes later, such as a pricing quote, a document render or a risk score computed by a model. There, the caller does not block a thread, the request is durable and replayable if the worker crashes, the reply itself is a useful event that other services may read, and the extra milliseconds do not matter.
| Need | Good fit | Why |
|---|---|---|
| Stock check within 50 ms | HTTP or gRPC | One round trip, clear timeout |
| Keep stock view fresh | Kafka events | Fan-out, no caller waiting |
| Quote computed in minutes | Request-reply over Kafka | Durable request, reply is an event |
| Must work when inventory is down | Local view from events | No runtime dependency |
6Follow-up questions
Does sending the request through Kafka make the system more resilient?
Only in a narrow sense. The request survives a broker-side failure, but the caller has usually given up by the time it is processed, so the user still sees a failure. Real resilience comes from not needing the call: a local stock view built from events keeps checkout working when inventory is down.
How would you size the timeout for the synchronous call?
Start from the user-facing budget. If checkout must respond in 300 ms and the stock check is allowed 50 ms, set the client timeout a little below that, say 40 ms, so there is room for one fast retry or a fallback. Watch the inventory service's p99 latency; if it regularly exceeds the timeout, the timeout is not the problem and the service needs attention.
What happens to requests left in inventory-requests after the caller timed out?
They are still processed, which wastes work and can cause side effects. We can set a deadline header on each request and have the inventory listener skip requests whose deadline has passed, which is cheap and avoids late side effects.
7Conclusion
In this answer, we saw that request-reply over Kafka keeps checkout waiting for inventory, so the services stay coupled in time while the path grows from two network trips to four, which makes a 50 ms p99 hard to hold. We also saw that replies must be routed to the instance holding the future, and that restarts and timeouts turn requests into unknown outcomes. A synchronous call with a timeout and circuit breaker, plus Kafka events for a local stock view, is the better design here, while request-reply over Kafka suits long-running work whose reply is itself a useful event.
Open with
My main concern is that this does not actually decouple anything. Checkout still blocks on future.get waiting for inventory, so if inventory is down checkout fails, just as with HTTP.
Then, if they want more
What changes is the latency: a request now goes through two produces and two consumes, each with batching, replication acks and poll delays, so holding 50 milliseconds at p99 is very hard.
There is also routing: the reply must reach the one checkout instance holding the future, so each instance needs its own reply topic or reply partition, or every instance reads all replies and drops the ones it does not know.
And a restart or rebalance loses in-flight futures; ReplyingKafkaTemplate times out after a few seconds by default while the request may still be processed later, so a timeout is an unknown outcome and the operation must be idempotent.
For this case I would use HTTP or gRPC with a short timeout, a retry for idempotent reads and a circuit breaker, and I would use Kafka for StockChanged events so checkout can keep a local stock view and often not call at all.
I would use request-reply over Kafka for long-running work, like a quote that takes minutes, where a durable request and a reply that is itself a useful event are worth the extra hops.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What are the problems, and when is request-reply over Kafka a reasonable choice?": https://scrivio-interview-library.netlify.app/spring-boot/kafka-design/b78dd5d89e/