Redis Pub/Sub (Publish/Subscribe) Created: 14 Jan 2026 Updated: 14 Jan 2026

Understanding Redis Pub/Sub

Understanding Redis Pub/Sub: Real-Time Messaging at Scale

In modern distributed systems, communication between services must be fast, decoupled, and scalable. One of the most popular patterns for achieving this is the Publish/Subscribe (Pub/Sub) model. While Redis is primarily known as a high-performance in-memory data store, its Pub/Sub implementation offers a powerful way to handle real-time messaging with minimal overhead.

What is Redis Pub/Sub?

Redis Pub/Sub is a messaging paradigm where senders (publishers) do not send messages directly to specific receivers (subscribers). Instead, messages are published to channels. Subscribers express interest in one or more channels and only receive messages that are of interest, without needing to know which publishers are sending them.

How it Works

The architecture is built on three core pillars:

  1. Publishers: Clients that broadcast messages to a specific channel.
  2. Channels: Named logical paths (like "orders" or "system-logs") that act as meeting points for data.
  3. Subscribers: Clients that listen to one or more channels and react when a message arrives.

Key Features and Characteristics

1. The "Fire-and-Forget" Nature

The most defining characteristic of Redis Pub/Sub is that it is ephemeral. It follows an "at-most-once" delivery semantic. If a subscriber is offline when a message is published, that message is lost to them. Redis does not store the messages; it simply pushes them to the connected clients and forgets them.

2. Pattern Matching (Wildcards)

Redis provides a flexible way to subscribe to multiple channels using glob-style patterns through the PSUBSCRIBE command.

  1. Example: Subscribing to sensor.* will capture messages from sensor.temperature, sensor.humidity, and sensor.motion.

3. Extremely High Throughput

Because Redis does not write these messages to disk or manage complex consumer offsets (like Kafka), the performance is incredibly high. The latency is often measured in microseconds, making it ideal for high-frequency updates.

4. Decoupling of Services

Pub/Sub allows for a "plug-and-play" architecture. You can add a new microservice that listens to an existing "UserSignedUp" channel without changing a single line of code in the original User Service.

Comparison: Pub/Sub vs. Redis Streams

For a software architect, choosing between Pub/Sub and Streams is a critical decision.

FeatureRedis Pub/SubRedis Streams
PersistenceNone (Ephemeral)Persistent (Saved to disk/memory)
Historical DataCannot access past messagesCan replay history
Delivery ModelPush-basedPull-based (Consumer Groups)
Use CaseReal-time chat, notificationsEvent sourcing, Task queues


Share this lesson: