This guide helps you choose between Redis Pub/Sub and Redis Streams, the two messaging tools built into Redis, and it is written for developers picking one for a service. The question usually turns urgent the first time a worker restarts during a deploy and the messages published in those few seconds are gone for good. The short answer is that Pub/Sub fits cases where a missed message costs nothing, such as live notifications or telling every app server to drop a cached value. Streams fit everything else, because they store entries on disk and let a consumer group, meaning several workers sharing one stream, pick up what was missed and confirm each entry. By the end you will know which mode your service needs, and how to move from Pub/Sub to Streams if you started on the wrong one.
How to verify
# Pub/Sub — list channels with subscribers
redis-cli PUBSUB CHANNELS '*'
redis-cli PUBSUB NUMSUB news.ticks events.orders
redis-cli PUBSUB NUMPAT
# Streams — entries, groups, pending
redis-cli XLEN events:orders
redis-cli XINFO STREAM events:orders FULL
redis-cli XPENDING events:orders billing
redis-cli XINFO GROUPS events:orders
What’s happening
Pub/Sub is in-memory and stateless. A publisher sends a message to a channel; the server forwards it to every subscriber currently connected to that channel. If a subscriber is not connected at the moment of publication, the message is lost — there is no persistence and no replay. If a subscriber is slow, the server buffers up to client-output-buffer-limit pubsub, then disconnects the slow client. The server has no idea who is supposed to receive what; there are no groups, no acknowledgments, no delivery guarantees. This is the model real-time notifications and cache-invalidation broadcasts want: low latency, simple, and the cost of a missed message is acceptable.
Streams are durable. Entries are persisted with the rest of the database (RDB + AOF), replicate to replicas, and survive restarts. Consumer groups distribute entries across workers, track per-consumer pending entries until acknowledged, and let another consumer claim entries from a crashed worker. The cost is memory for the log, an explicit trim policy to bound it, and the discipline of acknowledging entries after work. Streams are what work queues, event sourcing, and at-least-once pipelines want.
The two modes also differ in cluster behavior. Pub/Sub messages on Redis Cluster propagate across all nodes by default (you can scope with SSUBSCRIBE to a single shard), while a Stream is a single key on a single shard.
The decision
Use Pub/Sub when:
- Subscribers being connected at the instant of publication is the contract — chat presence, live tick broadcasts, cache invalidation.
- A lost message has no business consequence and you do not want the cost of trim, ack, or persistence.
- The message rate is high and the consumers are many — Pub/Sub fan-out is cheap in CPU and memory.
- You want the simplest possible producer:
PUBLISH channel messageand you are done.
Use Streams when:
- A consumer offline during publication must still receive the message after coming back — work queues, audit logs, event sourcing.
- You need consumer groups: many workers cooperatively consuming a single source.
- Delivery must be at-least-once with explicit acknowledgment and recovery of stuck entries via
XCLAIMorXAUTOCLAIM. - You want replay — a new consumer should be able to read history from any point.
- You need backpressure: a slow consumer in Pub/Sub gets dropped; a slow consumer in Streams just lags, and the producer can choose to trim or block.
A hybrid sometimes makes sense — publish to a stream for durability, and publish a notification on a Pub/Sub channel to wake subscribers immediately. The stream is the source of truth; Pub/Sub is the doorbell.
The procedure (migrating Pub/Sub to Streams)
When a project outgrows Pub/Sub — typically because lost messages started causing business problems — the migration is mechanical.
-
Add an XADD call alongside every PUBLISH. Producers now write to both. Stream is the source of truth.
r.publish("events.orders", json.dumps(payload)) r.xadd("events:orders", {"data": json.dumps(payload)}, maxlen=1_000_000, approximate=True) -
Build a stream consumer for one of the existing Pub/Sub subscribers. Create a consumer group; consume with
XREADGROUP; acknowledge after work.redis-cli XGROUP CREATE events:orders billing '$' MKSTREAM -
Migrate subscribers one by one. When a subscriber moves to the stream, remove its Pub/Sub subscription.
-
Remove the PUBLISH call once every consumer is on the stream.
-
Add an XAUTOCLAIM cron to recover entries from crashed consumers, and a Prometheus alert on consumer-group lag.
Common pitfalls
- Treating Pub/Sub as a work queue is the classic mistake — every message is delivered to every subscriber on the channel, not load-balanced. Use Streams with a consumer group instead.
- A Pub/Sub subscriber that processes messages synchronously and is slower than the publish rate gets buffered, then disconnected at
client-output-buffer-limit. Either subscribe and dispatch to a worker pool, or move to Streams. - Treating Streams as ephemeral is the other mistake — without a trim policy, a high-volume stream grows until the host runs out of memory.
- In a Cluster, a Stream is one key on one shard. If a stream’s throughput exceeds one shard’s capacity, partition with hash tags:
events:{0},events:{1}, and shard the work. - Pub/Sub messages do not respect ACL channel permissions unless the user has explicit
~*and+@pubsubgrants. ACL-locked Pub/Sub appears to silently drop messages.
In the engagements we run, the decision matrix above is a checklist on the architecture review for every new service: durability requirement, replay requirement, consumer-group semantics, message volume. We operate both patterns under Managed Operations — and clients adopting Streams for the first time usually pair the rollout with a refresher on Streams operations.