Video in progress
How do you compare RabbitMQ, Redis Pub/Sub, Kafka and NATS when choosing a message broker for real-time push?
Redis Pub/Sub and NATS core are fast but "fire-and-forget": if there's no subscriber, the message is lost. Kafka gives storage and replay, but it doesn't suit latency-sensitive paths or many small channels. RabbitMQ supports routing and STOMP, but gets heavy as the number of connections and queues grows.
📖 Answer
There is no single "best", because in a real-time system the broker has two different jobs: (a) storing events reliably and (b) fast fan-out between nodes. Often two different tools do them.
| Redis Pub/Sub | NATS (core / JetStream) | Kafka | RabbitMQ | |
|---|---|---|---|---|
| Latency | very low | very low | medium | low |
| Storage | none | in JetStream | yes, long-term | in the queue, until consumed |
| Many small channels | good | very good (subjects) | poor | medium |
| Replay | none | JetStream | strong | limited |
| Spring integration | RedisMessageListenerContainer |
library | Spring Kafka | STOMP relay, AMQP |
Practical observations:
- With Redis Pub/Sub, if a subscriber drops for a second because of a network problem, the messages from that second are gone. Redis Streams solves that, but the semantics are different. If Redis is already there, it's the cheapest start for fan-out between nodes.
- Kafka is the source of truth and the buffer. But a topic per user or per chat room is a no. It's also heavy for fast fan-out between gateways.
- NATS subject hierarchy (
chat.room.42) fits real-time routing very naturally. The main question is whether your team can operate it. - RabbitMQ works with Spring out of the box through the STOMP relay. The broker connection per client becomes a limit at scale.
My usual combination: Kafka as the source for events and the inbox; Redis Pub/Sub or NATS for the fast "tell gateway X to deliver this message" signal between nodes. A lost signal isn't a disaster, because the client picks it up from the inbox on resume.
Beyond the technical table, the most important factor in the choice is what already runs in prod at the company and who can fix it at 3 a.m.
Sign up to mark studied questions and save your progress.