7 questions foundWhat is the Redis Pub/Sub feature, and how does it let different parts of an application communicate?
Beginner 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.
-- 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.
Common 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?
Streams;Keyspace Notifications
How do you subscribe to and publish messages on a specific Redis channel?
Beginner You use the SUBSCRIBE command with a channel name to start listening for messages on that channel, and the PUBLISH command with a channel name and message content from a different client to send a message that all current subscribers of that channel will immediately receive.
SUBSCRIBE weather_updates
PUBLISH weather_updates 'Storm warning issued for the area'
Real-world example A weather alert system publishes severe weather warnings to a dedicated channel, instantly notifying every subscribed application or device that is currently listening for updates.
Common follow-ups: What happens to a client's subscription if it disconnects and reconnects?;Can you unsubscribe from a channel without disconnecting entirely?
Keyspace Notifications;Redis as a Message Queue
What is pattern based subscription using PSUBSCRIBE, and how does it differ from subscribing to specific individual channels?
Intermediate PSUBSCRIBE lets you subscribe to multiple channels at once that match a specified wildcard pattern, rather than needing to individually subscribe to each specific channel name, which is useful when you want to receive messages from a whole category of related channels without knowing their exact names in advance.
PSUBSCRIBE news.*
-- Receives messages published to news.sports,
-- news.weather, news.technology, and any other matching channel
Real-world example A news aggregation application subscribes to all channels matching the news wildcard pattern, automatically receiving updates from any new category channel that gets created later without needing code changes.
Common follow-ups: What wildcard characters are supported in a pattern subscription?;Does pattern subscription have a performance cost compared to specific channel subscriptions?
Pub/Sub;Keyspace Notifications
What happens to a message published on a channel if there are currently no subscribers listening to that channel?
Intermediate If no client is currently subscribed to a channel when a message is published, that message is simply lost forever and never delivered to anyone, since Redis Pub/Sub does not store or queue messages for later delivery, which is an important limitation to understand before relying on Pub/Sub for anything that requires guaranteed delivery.
PUBLISH orders 'New order 456' -- lost if no subscribers are currently listening
Real-world example A team initially used Pub/Sub for order notifications, then discovered orders were being silently missed whenever their notification service briefly restarted, prompting them to switch to Redis Streams for guaranteed delivery instead.
Common follow-ups: What alternative Redis feature provides message persistence and guaranteed delivery?;How do you detect if messages are being missed due to no active subscribers?
Streams;Redis as a Message Queue
How would you design a real time notification system using Pub/Sub while working around its lack of guaranteed message delivery?
Advanced You would use Pub/Sub for the fast, real time delivery portion of the system, but also persist important notifications to a database or a Redis Stream as the source of truth, so if a client happens to be disconnected when a Pub/Sub message is sent, it can still retrieve any missed notifications by querying the persistent storage once it reconnects.
-- Publish for real time delivery
PUBLISH notifications:user123 'New message'
-- Also persist for reliability
XADD notifications_log '*' user 'user123' message 'New message'
Real-world example A messaging application delivers new message notifications instantly through Pub/Sub for currently connected users, while also logging every notification to a Redis Stream so a user who was briefly offline can catch up on anything they missed upon reconnecting.
Common follow-ups: How do you efficiently let a reconnecting client catch up on missed messages?;What is the tradeoff of maintaining both a Pub/Sub channel and a persistent log for the same events?
Streams;Redis as a Message Queue
How does Redis Pub/Sub behave differently in a Redis Cluster environment compared to a single instance setup?
Advanced In a standard Redis Cluster, published messages are automatically forwarded to all nodes in the cluster so that a subscriber connected to any node receives messages published from any other node, though this cluster wide message propagation adds some additional overhead, and Redis also offers sharded Pub/Sub as an alternative that restricts message propagation to reduce this overhead for cluster deployments with heavy Pub/Sub usage.
-- Sharded Pub/Sub commands, introduced for cluster efficiency
SSUBSCRIBE mychannel
SPUBLISH mychannel 'message'
Real-world example A large scale application running Redis Cluster switches from regular Pub/Sub to sharded Pub/Sub commands, reducing the cluster wide message propagation overhead that had been affecting performance under their heavy notification traffic.
Common follow-ups: What is the specific difference between regular and sharded Pub/Sub commands?;When does the overhead of cluster wide Pub/Sub propagation actually become a meaningful problem?
Clustering;Redis Performance Tuning & Benchmarking
How do you check how many subscribers are currently listening to a specific channel in Redis?
Intermediate You use the PUBSUB NUMSUB command followed by the channel name, which returns the number of clients currently subscribed to that specific channel, letting you monitor whether a channel actually has active listeners before publishing important messages to it.
PUBSUB NUMSUB notifications
Real-world example A monitoring dashboard periodically checks how many subscribers are currently listening on critical notification channels, alerting the team if a channel unexpectedly has zero active subscribers.
Common follow-ups: What other information can the PUBSUB command family provide besides subscriber counts?;How do you list all currently active channels that have at least one subscriber?
Redis Monitoring & Observability;Keyspace Notifications