Quick revision
The short answer
In Redis Cluster, classic PUBLISH is broadcast: the node that receives it forwards the message over the cluster bus to every other node, so subscribers connected anywhere get it, which means bus traffic grows with the number of nodes and pub/sub does not scale out. Sharded pub/sub, added in Redis 7.0 with SPUBLISH, SSUBSCRIBE and SUNSUBSCRIBE, maps each channel to a hash slot like a key, and its messages stay within the shard that owns the slot. Subscribers connect to that shard, and many channels spread the load; keyspace notifications, by contrast, stay local to each node.
What to remember
In this answer, we saw that classic PUBLISH in Redis Cluster is broadcast over the cluster bus to every node, so bus traffic and latency grow with the node count and pub/sub does not scale out, which explains the tripled traffic after moving to 30 nodes. Sharded pub/sub in Redis 7.0 hashes each channel to a slot, keeps messages within the owning shard, and requires subscribers to connect there, which cluster-aware clients handle. Many channels spread the load across shards, and keyspace notifications stay local to each node, so we must subscribe on every primary.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
In Redis Cluster, classic PUBLISH is broadcast: the node that receives it forwards the message over the cluster bus to every other node, so subscribers connected anywhere get it, which means bus traffic grows with the number of nodes and pub/sub does not scale out. Sharded pub/sub, added in Redis 7.0 with SPUBLISH, SSUBSCRIBE and SUNSUBSCRIBE, maps each channel to a hash slot like a key, and its messages stay within the shard that owns the slot. Subscribers connect to that shard, and many channels spread the load; keyspace notifications, by contrast, stay local to each node.
Why this question is asked
Moving to a cluster is supposed to spread load, so it is surprising when pub/sub gets slower and internal traffic triples at the same message rate. The reason lies in how classic pub/sub was made to work in a cluster at all. Interviewers ask about it to see whether we understand the cluster bus, why broadcast cannot scale, and what sharded pub/sub changes for both servers and clients. In this answer, we will recap the cluster and its bus, follow a classic PUBLISH through 30 nodes, see how sharded pub/sub keeps messages local, cover what clients must do, design channels so load spreads, and finish with keyspace notifications.
1A Quick Recap of Redis Cluster and Its Bus
Redis Cluster splits the key space into 16,384 hash slots, and each primary owns a range of them; replicas copy their primary. A key's slot is a hash of its name (or of the hash tag inside braces), and a client sends each command to the node that owns that slot.
Nodes talk to each other over a separate connection called the cluster bus, using a binary protocol. They use it for heartbeats, failure detection, configuration updates and, as we will see, to forward pub/sub messages. Every node is connected to every other node.
2Following a Classic PUBLISH Through 30 Nodes
Classic pub/sub channels are not keys and have no slot. A subscriber may be connected to any of the 30 nodes, so for PUBLISH to reach everyone, the node that receives it delivers the message to its own subscribers and also sends it over the cluster bus to every other node, which delivers it to theirs. Each message therefore crosses the bus 29 times, whether or not those nodes have any subscribers for that channel.
With one primary there was no bus at all. With 30 nodes, every message is multiplied across the cluster, so internal traffic rises with the node count even though the message rate is unchanged, which is exactly the tripling the team saw. Each node also spends CPU receiving and processing messages it may not need, and the extra hop adds latency. Adding nodes makes this worse, not better, so classic pub/sub does not scale out.
| Classic PUBLISH | Sharded SPUBLISH | |
|---|---|---|
| Channel placement | no slot, any node | hash slot, like a key |
| Bus copies per message | 29 (every other node) | only to the shard's replicas |
| Where subscribers connect | any node | the shard owning the slot |
| Adding nodes | more bus traffic | more shards to spread channels |
3What Sharded Pub/Sub Changes
Redis 7.0 added sharded pub/sub. SSUBSCRIBE subscribes to a shard channel, SPUBLISH publishes to it, and SUNSUBSCRIBE unsubscribes. A shard channel is hashed to a slot exactly like a key, so it has an owning shard, and the commands must be sent to a node of that shard. A message is delivered to subscribers on the primary and its replicas and propagated only within that shard, never across the whole cluster.
So the bus carries a message only within one shard, and total pub/sub capacity grows with the number of shards: 15 shards can each handle their own channels' traffic independently. Hash tags work as for keys, so room:{42} and other channels tagged {42} land together if we need that.
5 messages in order. Play them, or step through them one at a time.
No copy goes to the other 28 nodes.
The MOVED reply is the same redirection we get for a key on the wrong node, and cluster-aware clients follow it automatically.
4What Clients Must Do
A subscriber must now connect to the shard that owns each channel's slot, possibly holding connections to several shards if it subscribes to channels in many slots. Cluster-aware clients such as Lettuce, Jedis and redis-py handle the routing in versions that support sharded pub/sub, but support arrived at different times and APIs differ, so we check our client and framework versions before migrating.
The migration itself is gradual: publishers send to both the classic and the shard channel for a while, subscribers move to SSUBSCRIBE, and then the classic PUBLISH is turned off.
5Designing Channels So Load Spreads
Sharded pub/sub spreads load only if there are many channels. If the whole application publishes to one global channel, such as live-updates, that channel hashes to one slot on one shard, which now carries all pub/sub traffic alone. We get the opposite of what we wanted.
So we use many channels, per room, per document or per user, such as room:42 or updates:user:4711. Their slots spread across all shards, and each subscriber instance subscribes only to the channels it needs. If a single channel is genuinely hot, we can split it into several numbered channels and have subscribers listen to all of them.
6Keyspace Notifications Are Local to Each Node
Keyspace notifications, the events Redis can publish when keys change or expire, are delivered only to clients connected to the node where the event happened. They are not broadcast across the cluster. So a service that wants every expiry event must connect to every primary and subscribe on each, and handle failovers and resharding by reconnecting to the new owners. This catches teams out when they move from a single primary, where one subscription saw everything.
7Follow-up questions
What happens to sharded subscribers when their slot migrates?
When a slot moves to another shard during resharding, or its shard fails over, the server unsubscribes the clients from shard channels in that slot, and they receive an unsubscribe notification. The client must then subscribe again on the new owner, which cluster-aware clients can do automatically (check your client version). Messages published during that short gap are lost, as with any pub/sub, so durable catch-up still matters.
Should we go back to a single primary for pub/sub?
For moderate traffic, a dedicated non-cluster Redis for classic pub/sub is a valid choice: no bus, simple clients. If pub/sub must scale beyond one node, sharded pub/sub in a cluster is the way, with many channels so load spreads.
Does classic PUBLISH still work in a cluster?
Yes, it is fully supported and convenient, because subscribers can connect to any node. Its cost is the broadcast, so it suits low message rates or small clusters, and we should not assume adding nodes increases its capacity.
8Conclusion
In this answer, we saw that classic PUBLISH in Redis Cluster is broadcast over the cluster bus to every node, so bus traffic and latency grow with the node count and pub/sub does not scale out, which explains the tripled traffic after moving to 30 nodes. Sharded pub/sub in Redis 7.0 hashes each channel to a slot, keeps messages within the owning shard, and requires subscribers to connect there, which cluster-aware clients handle. Many channels spread the load across shards, and keyspace notifications stay local to each node, so we must subscribe on every primary.
Open with
In Redis Cluster, classic pub/sub channels don't belong to any slot, and a subscriber can be connected to any node. So when a node receives a PUBLISH, it delivers locally and forwards the message over the cluster bus to every other node, which then delivers to its own subscribers.
Then, if they want more
With 30 nodes, each message crosses the bus 29 times, whether or not those nodes have subscribers, so internal traffic and latency go up with node count even at the same message rate. That's why classic pub/sub doesn't scale out. Sharded pub/sub, added in Redis 7.0, uses SPUBLISH, SSUBSCRIBE and SUNSUBSCRIBE.
A shard channel is hashed to a slot exactly like a key, so it has an owning shard, and messages are propagated only within that shard, the primary and its replicas. Subscribers have to connect to the owning shard, which cluster-aware clients handle by following MOVED, but I'd check our client version supports it.
To actually spread load I'd use many channels, per room or per user, because one global channel would land on a single shard. And I'd remember keyspace notifications are local to each node in Cluster, so a subscriber needs to connect to every primary to see all events.
About this answer
- Last updated
- 13 November 2026
- Versions it names
- Redis 7
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Redis documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Explain how classic pub/sub works in Redis Cluster and what sharded pub/sub changes.": https://scrivio-interview-library.netlify.app/databases/redis-patterns/0faab7f523/