Kafka or RabbitMQ for an order processing system?
- Posted
- Tags
- system-design, message-brokers, agents
RabbitMQ hands a task to a worker and deletes it once it is done. Kafka keeps every event in a log for a set time, and each service tracks its own place in it, so a fixed bug can be replayed. Orders fit Kafka, an OTP email fits RabbitMQ. A broker is not essential to an AI harness, but the same split applies when agent work gets slow or needs replay.
I watched a KodeKloud video that works through a classic system design interview question: would you use Kafka or RabbitMQ for an order processing system? I had already written about when to use a message broker instead of a load balancer, so this is the next step: once I decide I need a broker, which one?
The question I had
In an order processing system, do I use Kafka or RabbitMQ, and what actually separates them?
What I found
The scenario
A customer places an order and it goes to a checkout service. Checkout needs four things done: payment, inventory (reserve the item), email (tell the customer), and analytics (update the sales dashboard).
If checkout calls all four directly, the customer waits whenever any one of them is slow. So only payment stays in the request. Once payment is done, the order is confirmed, and the order is handed to a broker that passes it on to inventory, email, and analytics in the background.
That broker could be Kafka or RabbitMQ. The video's point is that the difference is not speed or popularity. It is what happens to the order after it has been processed.
RabbitMQ: do the task, then delete it
- Each remaining service gets its own queue: an inventory queue, an email queue, an analytics queue. (Checkout publishes to an exchange, which routes a copy to each queue. The video skips that part.)
- Workers pick tasks off a queue. One worker takes the email task for a customer and sends the email.
- Once the worker confirms it is done (an ack), RabbitMQ deletes the task.
- If a worker fails before confirming, the task goes to another worker.
- If a task keeps failing, it can be moved to a dead letter queue. That is something I configure (for example on a rejection or after a delivery limit), not something that happens by itself after a few tries.
Kafka: write it down and keep it
- Checkout writes the order to a topic called
orders. All three services read from that same topic. - Each service keeps its own position, called an offset. Email might be at order 500 while analytics is at 420. (In reality offsets are tracked per consumer group and per partition, so "order 500" is a simplification.)
- The events stay in the topic after they are read. The default retention is 7 days, after which old events are deleted. It is configurable by time or size.
The email bug example
If the email service is only slow, nothing is lost in either tool. The tasks just wait.
Now say the email service has a bug for one hour and sends wrong emails. In RabbitMQ, the workers finished those tasks, so they were deleted. There is nothing left to resend once the bug is fixed.
In Kafka, those orders are still in the topic. I fix the bug, move the email service's offset back one hour, and it reads those orders again and sends the right emails.
Side by side
| RabbitMQ | Kafka | |
|---|---|---|
| What it is | Queues that hand tasks to workers | A log of events in a topic |
| After a task is done | Deleted once acked | Kept until retention runs out (7 days by default) |
| Several services need the same order | Each gets its own queue and copy | All read the same topic, each with its own offset |
| A consumer had a bug | The finished tasks are gone | Move the offset back and read again |
| A worker fails | Task goes to another worker, then maybe a dead letter queue | Service resumes from its last offset |
| Good fit | One-off tasks, like an OTP email | History and replay, like orders |
How to choose
- Sending an OTP email: once it is sent, I don't need the task again, and an old OTP has expired anyway. RabbitMQ is enough.
- Keeping a history of every event so I can read it again: Kafka.
- Orders: the video picks Kafka, because I want the history and I want to fix and replay mistakes.
What the video leaves out
- Replay means duplicates. Rewinding an hour re-sends emails for orders that were already fine. The email service has to be idempotent, or deduplicate, so a replay doesn't spam customers.
- Retention is a limit. A service that falls behind further than the retention period loses events it hasn't read yet. "Nothing is lost" holds only while the lag stays inside it.
- The line is blurrier than it sounds. RabbitMQ also has streams, a log-style structure that keeps messages and can be re-read, so "RabbitMQ always deletes" is not the whole story anymore.
- It is a trade-off, not a rule. RabbitMQ would also work for three services if I never need replay, and Kafka is more to run. I chose Kafka here because replay and history are the whole point.
Where my curiosity went: brokers in AI applications
The video made me wonder how brokers are used in AI applications. More specifically: is a broker essential in a good harness design? (I covered what a harness is and how it differs from agentic engineering in earlier posts.)
This part is my own reasoning, not from the video. My answer is no, a broker is not essential. It is a tool in the system around the model, and I reach for it only when certain things are true.
When I would not need one
A single agent loop on my machine, with a person watching, is just a model call, a tool call, and repeat. That is plain function calls. A broker would add something to run and debug without solving a problem I have.
When a queue helps (the RabbitMQ side)
Agent runs are slow and LLM APIs have rate limits. This is the same problem as checkout waiting on email. A request becomes a job on a queue, workers run the agent, and the job is acked when it succeeds. A failed run goes to another worker or a dead letter queue. The queue depth shows the backlog, and the number of workers caps how many calls go out at once.
When a log helps (the Kafka side)
If every step of an agent (the prompt, the tool call, the result) is written as an event, then separate consumers can read the same stream at their own pace: an audit trail, an evaluation job, a cost dashboard. None of them slow the agent down. And the email bug has an agent version: a bad prompt or a broken tool gives wrong results for an hour, and with the log I can fix it and replay those inputs.
| What I need | Style |
|---|---|
| Run slow agent jobs in the background, with retries and a cap on load | Queue (RabbitMQ) |
| Keep every step so I can audit, evaluate, and replay | Log (Kafka) |
| A single short agent loop with a person waiting | No broker |
Watch out
- A replay is not the same run. An LLM is not deterministic, so replaying an input gives a new answer, not the old one. A replay re-runs the work. It doesn't restore the past.
- Tool side effects happen twice. If a replayed step sends an email or makes a payment, it does it again. Tools need to be idempotent, just like the email service.
- Long jobs and timeouts. An agent job can run for many minutes, and brokers usually have a timeout for how long a worker may hold a task before acking. I'd check that setting before putting long agent runs on a queue.
- A database may be enough. For a small system, a table used as a job queue can do the job without a broker. I touched on this in my earlier post.
Takeaway
The right tool for the right job. Before picking a broker, ask what should happen to a message after it is processed. If I never need it again, a queue like RabbitMQ is enough. If I might need to read it again, I want a log like Kafka. The same question applies to AI applications: a broker is not required for a good harness, but once agent work gets slow, needs retries, or needs replay, it is the same decision.