Skip to content
Architecture

Redis vs Kafka vs RabbitMQ: When to Use What (Real Examples)

A developer-focused comparison of Redis, Kafka, and RabbitMQ. Covers architecture, performance, use cases, and decision-making guidelines with real-world scenarios.

A
Abhishek Patel10 min read

Infrastructure engineer with 10+ years building production systems on AWS, GCP,…

Redis vs Kafka vs RabbitMQ: When to Use What (Real Examples)
Redis vs Kafka vs RabbitMQ: When to Use What (Real Examples)

Pick the Row That Matches Your Workload

Before any benchmarks or architectural diagrams, the honest way to answer "Redis vs Kafka vs RabbitMQ" is a decision table, because the three tools are not actually competing for the same job. Find the row below that describes what you are building and read the recommended column. The rest of the article is the detailed argument for why that row is right.

If your workload is...UseShort reason
Real-time chat, collaborative editing, multiplayer presenceRedis (pub/sub + Streams)Sub-ms latency; already in your stack for caching
Event-sourced microservices, audit log, immutable change feedKafkaReplayable log with days-to-weeks retention
High-throughput metrics / logs ingestion (>500k msgs/sec)KafkaSequential disk + batching beats everything else
Async task queue (email, PDF generation, webhooks)RabbitMQPriority queues, delayed delivery, mature retries
Request/reply between services without gRPCRabbitMQReply-to queues + correlation IDs are built in
Complex fan-out: one message to several queues with different filtersRabbitMQTopic exchanges + bindings, no app-side routing
Leaderboards, rate limiting, ephemeral notificationsRedis (Streams / sorted sets)In-memory data structures double as messaging
Cross-service data integration across 10+ consumersKafkaIndependent consumer offsets = no producer changes
"We just need a queue and we're on AWS"Amazon SQS (honorable mention)Zero-ops, $0.40/million messages, no cluster to run

Three patterns repeat on every production consult I do. Teams reach for Kafka when RabbitMQ would have shipped in a sprint because "Kafka scales." Teams use Redis pub/sub for messages that cannot afford to be dropped, then discover the hard way that pub/sub has no persistence. And teams running RabbitMQ at 50 msgs/sec agonize over a Kafka migration they do not need. The rest of this article is a head-to-head comparison -- architecture, benchmark numbers, operational cost, specific production-ready use cases -- so you can verify the row you picked above, or find the edge case that moves you to a different one.

What Each Tool Actually Is (the 30-Second Architecture)

Redis is an in-memory data structure server that also supports messaging via two mechanisms: pub/sub (fire-and-forget, no persistence) and Streams (append-only log with consumer groups and acknowledgments). Sub-millisecond latency because everything lives in RAM. Durability optional via AOF/RDB snapshots.

Apache Kafka is a distributed, partitioned commit log. Producers append messages to topics, consumers read at their own pace by tracking an offset into the log. Messages persist on disk for a configurable retention window (days to weeks). Built to move millions of messages per second across a horizontally scalable cluster.

RabbitMQ is a classical message broker implementing AMQP 0.9.1 (plus STOMP, MQTT via plugins). Producers publish to exchanges; exchanges route to queues via bindings; consumers pull from queues. Messages are consumed-and-gone by default -- once acknowledged, they disappear. The routing model is its superpower.

Those architectural differences are why "which is fastest" is the wrong question. Redis wins on latency because RAM. Kafka wins on throughput because sequential disk writes and batching. RabbitMQ wins on routing flexibility because exchanges. You pick the one whose strength matches your constraint.

Architecture Comparison

FeatureRedis (Streams/Pub-Sub)Apache KafkaRabbitMQ
Core modelIn-memory data store + streamsDistributed commit logAMQP message broker
Message persistenceOptional (AOF/RDB)Always (disk-based log)Optional (per queue)
Message retentionConfigurable (size/time)Configurable (days/size/compaction)Until consumed + acked
Consumer modelPush (pub/sub) or pull (streams)Pull (consumer groups)Push (prefetch-based)
Message replayYes (streams)Yes (offset-based)No (consumed = gone)
OrderingPer streamPer partitionPer queue (with caveats)
RoutingChannel/pattern matchingTopics + partitionsExchanges, bindings, routing keys
ProtocolRESP (Redis protocol)Custom binary protocolAMQP 0.9.1, STOMP, MQTT
ClusteringRedis Cluster (sharded)Native (partition replication)Mirrored/quorum queues
Typical latencySub-millisecond2-10 ms (batching)1-5 ms

Performance Benchmarks

Benchmarked on 3-node clusters, each node with 8 vCPUs, 32 GB RAM, NVMe storage, 10 Gbps networking. Messages are 1 KB JSON payloads unless noted.

MetricRedis StreamsKafkaRabbitMQ
Throughput (msgs/sec, 1 producer)450,000800,00045,000
Throughput (msgs/sec, 10 producers)1,200,0002,500,000120,000
Latency p50 (ms)0.32.10.8
Latency p99 (ms)1.28.54.2
Latency p99.9 (ms)3.825.012.0
Max consumers per topic/streamLimited by memoryUnlimited (independent offsets)Limited by prefetch + connections
Message size limit512 MB (practical: 1 MB)1 MB default (configurable)128 MB default

Kafka dominates on raw throughput -- it's designed for it. The sequential disk write pattern and batching at both producer and broker levels make it extraordinarily efficient at sustained high volume. Redis wins on latency because everything is in-memory. RabbitMQ sits in the middle -- lower throughput than both, but its routing flexibility compensates in complex architectures.

Pro tip: Kafka's latency numbers improve dramatically with linger.ms=0 and batch.size=1, but throughput drops by 80%. The default batching configuration (linger.ms=5, batch.size=16384) optimizes for throughput. If you need both low latency and high throughput, run two Kafka clusters -- one tuned for each.

When to Use Redis

Real-Time Caching with Pub/Sub Side Channel

Redis shines when you already use it for caching and need lightweight messaging alongside it. A common pattern: cache user sessions in Redis, publish session-change events via pub/sub, and have websocket servers subscribe to push real-time updates to browsers. One infrastructure component handles both concerns.

Rate Limiting with Event Counting

Redis Streams doubles as both a rate limiter and an event log. Use XADD to record API calls, XLEN to count them, and XRANGE to query recent history. The same data serves both operational (rate limiting) and analytical (usage tracking) purposes.

Leaderboards and Real-Time Rankings

Sorted sets for ranking combined with pub/sub for live updates. When a player's score changes, update the sorted set and publish the change. Clients subscribed to the leaderboard channel get instant updates without polling.

Watch out: Redis pub/sub has no persistence -- if a subscriber is disconnected when a message is published, that message is lost forever. Redis Streams fix this with consumer groups and acknowledgments, but many teams still use basic pub/sub without realizing the data loss risk. For any message that matters, use Streams, not pub/sub.

When to Use Kafka

Event Sourcing and Audit Logs

Kafka's append-only log is a natural fit for event sourcing. Every state change becomes an immutable event in a Kafka topic. You can rebuild any service's state by replaying its input topics from the beginning. This pattern powers systems at LinkedIn, Netflix, and Uber where audit trails are non-negotiable.

Stream Processing Pipelines

Kafka Connect ingests data from databases (CDC with Debezium), APIs, and files into Kafka topics. Kafka Streams or Flink processes events in real-time -- aggregating, filtering, joining, and enriching. The results land in downstream topics, databases, or search indexes. The entire pipeline is fault-tolerant, replayable, and horizontally scalable.

Cross-Service Data Integration

When you have 20+ microservices that all need to react to the same business events (order placed, user signed up, payment processed), Kafka's consumer group model lets each service consume at its own pace without affecting others. Adding a new consumer doesn't require changing the producer. This decoupling is Kafka's strongest selling point.

High-Volume Metrics and Logging

Kafka handles 10M+ messages per second on a modest cluster. This makes it ideal for aggregating metrics from thousands of servers, collecting application logs, and feeding monitoring systems. The retention period ensures you can reprocess historical data when you add new analytics.

When to Use RabbitMQ

Task Queues with Complex Routing

RabbitMQ's exchange-binding-queue model is unmatched for complex routing. A single message can be routed to different queues based on routing keys, headers, or topic patterns. Email notifications go to the email queue. SMS alerts go to the SMS queue. The producer doesn't know or care about the consumers -- the exchange handles routing.

Request-Reply Patterns

RabbitMQ natively supports the request-reply pattern with reply-to queues and correlation IDs. A service publishes a request, waits for a response on a temporary queue, and correlates it by ID. This is clunky to implement in Kafka (which doesn't have temporary queues) but built into RabbitMQ's AMQP model.

Priority Queues

RabbitMQ supports message priorities (0-255). Premium customers' requests can jump ahead of free-tier users'. Kafka doesn't have message-level priorities -- you'd need separate topics and consumer logic to achieve the same effect, which is messier.

Delayed and Scheduled Messages

With the delayed message exchange plugin, RabbitMQ delivers messages after a specified delay. Schedule a reminder email for 24 hours later, retry a failed webhook in 5 minutes, or implement exponential backoff -- all with native broker support. Kafka requires external schedulers or timestamp-based consumers for delayed delivery.

Cost Comparison: Running in Production

FactorRedisKafkaRabbitMQ
Minimum viable cluster3 nodes (Cluster mode)3 brokers + 3 ZK (or KRaft)3 nodes (quorum queues)
RAM requirements per node8-64 GB (data lives in RAM)4-8 GB (OS page cache helps)4-16 GB
Disk requirements per nodeMinimal (AOF backup only)High (all data on disk)Moderate (persistent queues)
AWS managed serviceElastiCache ($0.068/hr, r7g.large)MSK ($0.21/hr, kafka.m5.large)Amazon MQ ($0.13/hr, mq.m5.large)
Monthly cost (3-node managed)~$150~$460~$285
Monthly cost (self-managed, 3x m6i.large)~$210~$210 + $100 storage~$210
Operational complexityLowHigh (partitions, rebalancing, configs)Medium (queue management, flow control)

Redis is cheapest to run but stores everything in RAM, so costs scale linearly with data volume. Kafka is the most expensive managed option but cheapest per message at high volume -- the cost-per-message at 1M msgs/sec is fractions of a cent. RabbitMQ sits in the middle and is the easiest to operate for teams without dedicated platform engineers.

Decision Framework: 5 Steps to Choose

  1. Check if you already run one of these -- if Redis is already in your stack for caching, adding Streams for lightweight messaging avoids new infrastructure. Don't introduce Kafka for 10,000 messages/day.
  2. Estimate message volume -- under 50,000 msgs/sec, all three work. Over 100,000 msgs/sec sustained, Kafka is the clear choice. Redis Streams can handle it but memory costs become prohibitive.
  3. Determine if you need replay -- if consumers must reprocess historical messages (event sourcing, recomputing analytics, debugging), Kafka's log retention is essential. RabbitMQ deletes messages after consumption.
  4. Evaluate routing complexity -- if messages need to reach different consumers based on content, headers, or priority, RabbitMQ's exchange model saves you from building routing logic in application code.
  5. Assess operational capacity -- Kafka requires experienced operators (partition management, consumer group rebalancing, retention policies). RabbitMQ is simpler. Redis is simplest if your team already knows it.

Pro tip: Many production architectures use two of these three. A common pattern is Kafka for the event backbone (high-volume, cross-service events) and RabbitMQ for task queues (email sending, PDF generation, webhook delivery). Each tool handles what it's best at. Don't force one tool to do everything.

Frequently Asked Questions

Can Redis replace Kafka for event streaming?

For small-to-medium workloads (under 100,000 msgs/sec with limited retention), Redis Streams is a viable alternative. It supports consumer groups, message acknowledgment, and time-based retention. However, Redis stores everything in RAM, making long-term retention expensive. Kafka stores data on disk with configurable retention for days or weeks at a fraction of the cost.

Is RabbitMQ faster than Kafka?

RabbitMQ has lower latency for individual messages (sub-millisecond p50 vs Kafka's 2+ ms). But Kafka has 10-20x higher throughput because it batches writes and uses sequential disk I/O. If you need to process 1 million messages per second, Kafka wins. If you need each message delivered in under 1 ms, RabbitMQ wins.

What about Amazon SQS as an alternative?

SQS is a managed message queue that eliminates all operational overhead. It handles 3,000 msgs/sec per queue (higher with batching) at $0.40 per million messages. For teams that don't want to manage infrastructure, SQS is a solid choice for task queues. It lacks Kafka's event replay and RabbitMQ's routing sophistication, but the zero-ops model is hard to beat.

Does Kafka guarantee exactly-once delivery?

Kafka supports exactly-once semantics (EOS) within a Kafka-to-Kafka pipeline using idempotent producers and transactional consumers. End-to-end exactly-once (Kafka to an external system) requires the consumer to implement idempotent processing. In practice, most teams design for at-least-once delivery with idempotent consumers rather than relying on Kafka's EOS.

Should I use Redis pub/sub or Redis Streams?

Use Streams for almost everything. Pub/sub is fire-and-forget -- messages are lost if no subscriber is connected. Streams persist messages, support consumer groups for parallel processing, and allow message acknowledgment. The only use case for pub/sub is ephemeral real-time notifications where message loss is acceptable, like live dashboard updates.

How many Kafka partitions should I create?

Start with the number of consumers you expect in the largest consumer group. Kafka assigns one partition per consumer, so 12 partitions supports up to 12 parallel consumers. Over-partitioning (hundreds of partitions per topic) increases metadata overhead and rebalancing time. Under-partitioning limits parallelism. A good default is 6-12 partitions for most topics.

Making the Call

Use Redis when you need sub-millisecond messaging alongside caching, and data volume fits in memory. Use Kafka when you need high-throughput event streaming with replay capability and long-term retention. Use RabbitMQ when you need sophisticated routing, priority queues, or request-reply patterns with moderate volume.

The worst choice is picking a tool because it's trendy. Kafka for a queue processing 100 messages per minute is over-engineering. Redis pub/sub for critical financial events is under-engineering. Match the tool to the problem, and the system will be simpler, cheaper, and more reliable.

A

Written by

Abhishek Patel

Infrastructure engineer with 10+ years building production systems on AWS, GCP, and bare metal. Writes practical guides on cloud architecture, containers, networking, and Linux for developers who want to understand how things actually work under the hood.

Related Articles

Enjoyed this article?

Get more like this in your inbox. No spam, unsubscribe anytime.

Comments

Loading comments...

Leave a comment

Stay in the loop

New articles delivered to your inbox. No spam.