Choosing a Message Broker: One Ticket Through Redis, RabbitMQ, Kafka and SQS, and Four Questions That Pick One
One support ticket, four fates. Redis wipes it when taken, RabbitMQ routes copies by rule and removes them on ack, Kafka keeps it in a log each reader bookmarks, SQS hides it until it's deleted. A side-by-side table and four questions to pick one, with the honest note that none of them wins.
What you will learn
- Say what happens to a message after it's read in Redis, RabbitMQ, Kafka and SQS
- Explain RabbitMQ exchanges, bindings and dead-letter exchanges
- Explain Kafka offsets, retention and partitions, and SQS visibility timeouts and redrive
- Pick a broker with four questions
Before you start
- Celery and Redis for background tasks
- Events and the outbox
Picture a plain support app. A customer raises a ticket, and the app puts it on the broker so the email sender, the AI summary and analytics can pick it up later. Like the ticket rail in a kitchen, the ticket waits until someone takes it. That box in the middle could be Redis, RabbitMQ, Kafka or SQS. One question does most of the work: what happens to a message once it's read? And none of these is the winner.
Redis is a whiteboard: you take what's written and it's wiped. RabbitMQ is a post office with sorting rooms. Kafka is a newspaper archive where anyone can read from any date. SQS is a courier you hire, so someone else runs it.
Redis: wiped when taken
With a plain list as the queue, the app writes ticket 42 on the board. A worker takes it, and the pop returns the ticket and removes it. If that worker dies halfway, there's no copy anywhere, so the ticket is lost. To be fair, task libraries like Celery keep a spare copy of their own on top of Redis (see safe to run twice), and disk snapshots run every so often, so a Redis crash can lose the newest writes. It fits simple queues, especially when you already run Redis.
RabbitMQ: routed to a room
The ticket arrives at the exchange, the sorting desk, carrying a routing key, billing.urgent. The bindings are the rules. The key matches billing.*, and it matches #, which takes everything. So one copy goes to billing, one to audit, nothing to bugs. The billing worker takes its copy, and after the ack it's removed; if the worker dies with no ack, the ticket is delivered again.
Failures are built in. A worker rejects the ticket without putting it back, and the queue republishes it to a dead-letter exchange, where it lands in a parked queue. Four things send a message there: it's rejected, its TTL expires, the queue goes over its length limit, or on a quorum queue it hits the delivery limit. One trap: if that exchange doesn't exist, the message is silently dropped. RabbitMQ fits messages that must go to different places by rule.
Kafka: a log with bookmarks
The app appends the ticket to the tickets topic at offset 5. The email sender reads it, and its bookmark moves on to 6. The ticket stays. Analytics is far behind at offset 3, and nobody minds: same log, its own bookmark. That bookmark is the offset, the next thing to read; to be exact, one number per partition per consumer group.
Say analytics had a bug, now fixed. Move its bookmark back to offset 2 and it reads the same tickets again, like going back to an old newspaper. The archive isn't forever: a retention on the topic discards anything older, read or not. Tickets with the same key go to the same partition, and order is kept inside a partition. Kafka fits an event log that many readers read, and can read again.
SQS: a courier you hire
The app sends the ticket and AWS stores it on several servers. A worker receives it, but it's still in the queue, just hidden: that's the visibility timeout, and its clock is running. When the worker finishes it deletes the message, and only then it's gone. No delete? The timeout ends and the message is visible again. After the max receive count (three here), a redrive policy moves it to a dead-letter queue. SQS fits when you're on AWS and want nobody on your team running a broker.
Same ticket, four fates
Four questions
- Must readers replay a message, or many read the same history? Then Kafka.
- If not, must messages go different ways by rule? Then RabbitMQ.
- If not, are you on AWS, and nobody wants to run a broker? Then SQS.
- And if you already run Redis and the jobs are simple, just use Redis.
One system can use two: a queue for tasks and a log for events (the difference is in events and the outbox).
The lines blur
Redis Streams keep entries, RabbitMQ has streams too, Kafka has share groups, and SQS has FIFO queues. So whichever you pick, keep the consumer safe to run twice.
Common mistakes
- Choosing Kafka for a simple task queue because it's popular.
- A dead-letter exchange name that doesn't exist, so failures vanish.
- An SQS visibility timeout shorter than the job.
- Assuming any broker gives exactly once delivery.
Quick recap
- Redis, for simple queues you already run.
- RabbitMQ, for routing and dead letters.
- Kafka, for a log many readers can replay.
- SQS, for a queue AWS runs for you.
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
Fallback Models for an LLM App: A Chain That Checks Region and Fit, Flags Degraded Answers and Gets Rehearsed
When the main model goes down, the backup has to be allowed to take the data, able to read the whole request and tested before the bad day. A simulated four-model chain for an EU customer: a 6,000-token request lands on mid-eu, flagged degraded; a 10,000-token request is served by nobody, on purpose.
Back Pressure for LLM Traffic: Bound the Queue, Give Chat Its Own Lane, Count Tokens, Cancel When the Caller Leaves
A bulk upload buries the chat. In a small simulation, one shared queue grows to 199 waiting and the middle chat answer takes 80.2 s. A bound plus a chat lane brings it to 0.35 s while 178 bulk jobs are told to retry in 10 s, and cancelling abandoned calls saves 21,000 wasted tokens.
Load Balancing LLM Traffic: Count the Work, Weigh the Prefix Cache, Check Real Health, Drain Before Deploys
Six GPU replicas, two at 95% and four at 30%: round robin counts requests, and requests aren't equal. In a small simulation, least outstanding requests cuts p95 from 6.52 s to 3.05 s, prefix affinity lifts cache hits to 95% but pushes p95 to 11.45 s, a real health check takes errors from 48 to 2, and draining cuts 0 answers instead of 4.
A Message Queue for Document Ingestion: At Least Once, Leases, an Idempotent Consumer and a Dead Letter Queue
A queue doesn't lose a document, but it can hand one out twice. In a small simulation, a worker crash makes document two go from 3 to 6 chunks and the index holds 11 when the documents hold 8. An idempotent consumer brings it back to 8 with the same two deliveries, and a limit of three tries moves a poison file to a dead letter queue.
