← Lessons

quiz vs the machine

Gold1380

Databases

Redis Pub Sub

Fire and forget messaging between decoupled clients.

4 min read · core · beat Gold to climb

Channels, Not Queues

Redis publish subscribe lets clients send messages to named channels without knowing who receives them. Subscribers express interest in channels and get every message published while they are connected.

  • SUBSCRIBE listens to one or more channels.
  • PUBLISH sends a message to a channel.
  • PSUBSCRIBE matches channels by pattern, like news dot star.

Fan Out in Real Time

Pub sub fans a single message out to many listeners instantly. It powers live notifications, chat, and cache invalidation broadcasts, where you want every interested service to hear an event right now.

The Big Caveat

Pub sub is fire and forget. Messages are not stored. If a subscriber is offline or slow, it simply misses whatever was published while it was away. There is no replay, no acknowledgment, and no delivery guarantee.

That makes pub sub great for ephemeral signals but wrong for tasks that must not be lost. When you need durability, ordering, consumer groups, and replay, reach for Redis Streams instead. A common rule of thumb: pub sub for notifications, streams for work that matters.

Key idea

Redis pub sub broadcasts messages to subscribed channels in real time but does not store them, so offline subscribers miss messages and durable work needs streams.

Check yourself

Answer to earn rating on the learn ladder.

1. What happens to a pub sub message if no subscriber is listening?

2. When should you choose streams over pub sub?