What’s the Difference Between RabbitMQ and Redis?

RabbitMQ is a message broker, while Remote Dictionary Server (Redis) is an in-memory key-value data store. However, you can compare the two technologies, because you can use both to create a publish-subscribe (pub/sub) messaging system. In modern cloud architecture, applications are decoupled into smaller, independent building blocks called services. Pub/sub messaging provides instant event notifications for these distributed systems. RabbitMQ is a distributed message broker that collects streaming data from multiple sources and routes it to different destinations for processing. Redis supports a push-based system where the publisher distributes messages to all subscribers when an event occurs.

How they work: RabbitMQ vs. Redis

Both RabbitMQ and Redis allow applications, microservices, and software components to exchange messages in different ways. 

RabbitMQ workflow

RabbitMQ uses the Advanced Message Queuing Protocol (AMQP) to send messages securely through message brokers. A message broker consists of exchanges and queues. The process works like this:

  1. The data producer sends messages to RabbitMQ
  2. An exchange receives data and routes it to the respective queue according to a set of rules called bindings
  3. The message resides in the queue until a RabbitMQ consumer picks it up

When the queue reaches maximum capacity, RabbitMQ prevents producers from publishing messages until consumers handle the unread messages. RabbitMQ can also restore messages if the exchange fails before consumers read them.

Redis workflow

Redis is designed as a data structure server that supports various data structures like lists, sets, hashes, and bitmaps. It allows client applications to store, retrieve, and process almost any data type. Redis organizes stored data in key-value pairs, which provides a structured arrangement for subscribing client applications.

For example, you can separate ecommerce data into customer name, email, purchased items, and feedback keys. After this, you publish the relevant data for each key. 

Redis enables the real-time exchange of short retention messages. It works like this:

  1. The data producer sends messages to Redis
  2. Redis node checks the message key to identify interested subscribers
  3. Redis delivers the message to all the connected subscribers

 

Message handling: RabbitMQ vs. Redis pub/sub

Both Redis and RabbitMQ provide publish-subscribe (pub/sub) mechanisms for applications to distribute messages across the cloud environment. However, message handling differs significantly.

Read about pub/sub messaging »

Message delivery 

RabbitMQ uses the Advanced Message Queuing Protocol (AMQP) to support complex routing logic. It can deliver messages point-to-point or from one producer to many consumers. Regardless of methods, all consumers send message acknowledgements to the producer to confirm a successful read. If the producer doesn’t receive a confirmation, it makes several retries at different intervals. 

Meanwhile, Redis simply pushes messages to all connected subscribers; it doesn’t guarantee message delivery. A subscriber must be connected to the Redis server to receive incoming messages. If Redis gets disconnected, it may be unable to retrieve all messages. 

Message size

RabbitMQ can deliver larger messages without experiencing a substantial drop in performance. It was initially designed to handle messages up to 2 GB in size but later the limit was reduced to 128 MB.

Conversely, Redis doesn’t define a limit for stored messages but experiences notable latency for messages larger than 1 MB. So, developers commonly use Redis as a cache to process datasets like strings, hashes, lists, and sets.

Message persistence

RabbitMQ supports persistent messages and transient messages. When it sends messages to the persistent queue, it writes data to permanent storage as soon as it arrives. RabbitMQ also writes transient messages to the disk, but only if they exceed the memory’s capacity. 

On the other hand, Redis does not support persistent messages by default. Developers must enable a feature called Redis Database (RDB) to take periodic snapshots of the RAM and store them on disk. Enabling data persistence on Redis adds overhead to data operations, which slows down message delivery. Another alternative is to use recovery techniques like asynchronous replication.

Message encryption

RabbitMQ uses SSL to encrypt data in transit between producers, brokers, and consumers. Encrypting messages helps organizations safeguard confidential information and reduce data risks.

Redis, meanwhile, does not support SSL natively. Only Redis version 6.0 and later provide SSL support. To enable SSL, developers must get SSL certificates from the Redis cluster and create a client certificate for their database.

Performance: RabbitMQ vs. Redis pub/sub

Message-handling differences impact performance of RabbitMQ and Redis in different scenarios.

Speed

Redis is much faster than RabbitMQ, as it processes messages primarily on memory. However, there’s a risk of losing unread messages if the Redis server fails. 

In contrast, when operating in the persistent mode, RabbitMQ waits for acknowledgements from each consumer before it sends the next message. RabbitMQ also takes additional time to store the messages on disk, which slows down the average message exchange speed. 

As a comparison, Redis can send up to tens of million messages per second, while RabbitMQ handles up to tens of thousands of messages per second. 

Availability

Clustering, which allows message broker systems to replicate nodes, is handled differently in RabbitMQ and Redis.

With RabbitMQ, multiple nodes that contain relevant data and functions are replicated in a cluster. However, message queues are not replicated across these nodes, which share a peer relationship. To do that, developers use a special message queue that supports replication. 

Meanwhile, Redis Cluster is a feature introduced in later versions of Redis. It copies data from each leader node to one or multiple followers. When a leader node fails, the follower takes over to provide high-availability message delivery. 

When to use: RabbitMQ vs. Redis pub/sub

RabbitMQ outperforms Redis in many areas, but this doesn’t mean that RabbitMQ is the better message distribution system for all applications. 

Redis works better in enterprise applications that require real-time data processing and low-latency caching. With its in-memory data store and support for diverse data structures, Redis is suitable for performing low-level data computation. For example, financial institutions use Redis to cache transactional data to enable real-time fraud detection. 

Meanwhile, choose RabbitMQ if you need a dedicated microservices message broker with asynchronous communication mechanisms to support code and system building. RabbitMQ is also more suitable than Redis for transferring large files between applications. For example, a system that needs to send data reliably between many microservices might choose RabbitMQ. The system will benefit from RabbitMQ’s fault tolerance, larger file handling capacity, and guaranteed message delivery mechanisms.

Summary of differences: RabbitMQ vs. Redis pub/sub

 

RabbitMQ

Redis

Message delivery

Guaranteed message delivery. Supports complex logic.

Does not guarantee message delivery. Requires active connection from subscribers.

Message size

Message size limited to 128 MB. Can handle large messages. 

No message limit, but performance degrades for large messages (greater than 1 MB).

Message persistence

Supports persistent and transient messages. Writes persistent messages to disk.

Does not support persistent messages by default.

Message encryption

Supports SSL encryption.

SSL encryption available in Redis version 6.0 and above. 

Speed

Up to tens of thousands of messages per second.

Up to millions of messages per second.

Availability

Creates multiple peer-to-peer nodes in a cluster.

Uses leader-follower model in clustering. 

How can AWS help with your RabbitMQ and Redis requirements?

Amazon Web Services (AWS) provides managed services to run your open-source message broker systems at scale. You can set up your publish-subscribe (pub/sub) services easily and integrate them with other AWS services.

Here are AWS offerings you can use with Redis and RabbitMQ:

  • With Amazon MemoryDB, you can add durability when you deliver messages on Redis. You can run high-concurrency streaming data feeds to ingest user activity and support millions of requests per day for media and entertainment applications.
  • With Amazon MQ, you can provision your RabbitMQ brokers without time-consuming setups. It encrypts RabbitMQ messages in transit and at rest, which helps ensure high-availability data pipelines across AWS Availability Zones.

Instead of Redis or RabbitMQ, you can also use Amazon Simple Notification Service (SNS) to build a pub/sub messaging system. You can directly send messages from your applications to customers or other applications in a scalable and cost-efficient manner.

Amazon SNS offers several features:

  • High-throughput, push-based, many-to-many messaging between distributed systems, microservices, and event-driven serverless applications
  • Message encryption and traffic privacy
  • Fanout capabilities across AWS categories, such as analytics, compute, containers, databases, Internet of Things (IoT), machine learning, security, and storage

Get started with pub/sub, Redis, and RabbitMQ on AWS by creating an account today.

Next Steps with AWS