Advertisement
Beginner Redis, Pub/Sub

What is the Redis Pub/Sub feature, and how does it let different parts of an application communicate?

Short answer

Pub/Sub lets one client publish a message to a named channel, and any other clients currently subscribed to that same channel instantly receive the message, providing a simple way for different parts of a distributed application to communicate in real time without needing to…

Save Redis mock interview
Advertisement
AModel answer
Pub/Sub lets one client publish a message to a named channel, and any other clients currently subscribed to that same channel instantly receive the message, providing a simple way for different parts of a distributed application to communicate in real time without needing to know about each other directly.
Example

-- Subscriber SUBSCRIBE notifications -- Publisher PUBLISH notifications 'New order received'

Real-world example
A live chat application uses Pub/Sub to instantly deliver a new message to every connected user in a chat room, with the message being published once and received by every subscribed client immediately.
Likely follow-ups
  • Do messages published to a channel get stored anywhere if no one is currently subscribed?
  • Can a single client subscribe to multiple channels at once?
Related topics