Course contentsShow
← System Design
Lesson 672 of 1,91918. Message Queues and BrokersFree lesson

Redis as a Lightweight Message Broker

Using Redis lists for queues and Pub/Sub for broadcasting messages.

Redis as a Lightweight Message Broker

What You'll Learn

You'll discover how Redis, primarily known as a cache, can serve double-duty as a simple, fast message broker using its list and Pub/Sub features.

Why Redis for Messaging?

While Redis isn't a full-featured broker like RabbitMQ, it offers lightweight messaging capabilities that work beautifully for simpler use cases. If you already have Redis in your infrastructure for caching, adding basic message passing requires no new components.

Redis Lists as Queues

Redis lists support the point-to-point queue pattern. Think of a list as a simple pipe where producers push items in one end and consumers pop them from the other.

Operations:

  • LPUSH — Add message to the head of the list (producer)
  • RPOP or BRPOP — Remove message from the tail (consumer)
  • BRPOP blocks until a message arrives, avoiding wasteful polling

This creates a classic work queue where multiple consumers compete for tasks, providing load distribution across workers. Messages are durable while in the queue but disappear once consumed (no built-in reprocessing if a consumer crashes mid-task).

Redis Pub/Sub for Broadcasting

Redis Pub/Sub implements the pub-sub pattern for event broadcasting. Publishers send messages to channels, and all active subscribers receive copies simultaneously—classic fan-out behavior.

Key characteristics:

  • Fire-and-forget: no message persistence
  • Subscribers only receive messages published while they're connected
  • Perfect for real-time notifications, cache invalidation signals, or event broadcasting where missed messages are acceptable

When to Use Redis Messaging

Choose Redis when you need simple, fast messaging with minimal operational overhead—event notifications, background job queues with basic semantics, or temporary coordination between services. Avoid it when you need guaranteed delivery, message replay, complex routing, or enterprise-level reliability.

Key Takeaway: Redis provides lightweight message queue (via lists) and pub-sub (via channels) capabilities that work well for simple, high-speed messaging scenarios where operational simplicity matters more than advanced broker features.