Redis PubSub Flow
Redis PubSub is a lightweight in-memory publish-subscribe mechanism built into Redis that enables real-time message broadcasting to multiple subscribers with sub-millisecond latency but no message persistence.
Redis PubSub is a lightweight in-memory publish-subscribe mechanism built into Redis that enables real-time message broadcasting to multiple subscribers with sub-millisecond latency but no message persistence.
Redis implements pub/sub via three commands: SUBSCRIBE channel, PUBLISH channel message, and UNSUBSCRIBE. Subscribers open a long-lived connection to Redis and issue a SUBSCRIBE command, putting the connection into a dedicated subscriber mode. In this mode the connection can only receive messages — it cannot issue normal Redis commands like GET or SET. Redis then acts as a pure relay: when a publisher calls PUBLISH, Redis immediately forwards the message to all active subscribers on that channel and returns the count of recipients.
The key characteristic of Redis pub/sub is its fire-and-forget nature. Redis does not persist messages. If a subscriber is offline when a message is published — even for a fraction of a second during a restart — it simply misses that message. There is no offset tracking, no replay, and no acknowledgment. This makes Redis pub/sub excellent for genuinely ephemeral data: live user presence indicators, real-time cursor positions in collaborative tools, chat messages where a brief gap is acceptable, or cache invalidation signals.
For use cases requiring durability, Redis Streams (XADD/XREADGROUP) provide consumer group semantics with message persistence and replay — combining the low-latency characteristics of Redis with the reliability guarantees more commonly associated with Kafka Producer Consumer Flow. Pattern subscriptions (PSUBSCRIBE) extend the basic model by matching channels using glob patterns (news.*), enabling a single subscriber to listen to families of channels.
Use Redis pub/sub for low-latency broadcast of transient data; use a durable broker for any message you cannot afford to lose.