Pub/Sub Interview Questions
Pub/Sub interview questions for Redis — fundamentals through advanced scenarios.
- 20Questions with answers
- 3Difficulty levels
Questions (20)
Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.
Why do interviewers call Redis Pub/Sub fire-and-forget?
PUBLISH is fire-and-forget: if a subscriber is disconnected, the message is gone. There is no XACK and no backlog. That is the first sentence interviewers want before you mention speed.
Why must SUBSCRIBE use a dedicated connection?
SUBSCRIBE switches that connection into subscriber mode, so you cannot GET on it until you UNSUBSCRIBE. Use a dedicated connection. Sharing a pool connection for Pub/Sub is a classic production incident.
When is PSUBSCRIBE a better fit than listing channels?
PSUBSCRIBE matches glob patterns such as news.*, which is convenient and easy to over-subscribe. One bad pattern can flood a client. Prefer explicit SUBSCRIBE channels when the set is known.
When do you pick Pub/Sub versus STREAM?
Redis Streams persist and replay; Pub/Sub does not. Choose Pub/Sub for live fan-out where loss is acceptable, such as presence ticks or UI invalidate. Choose STREAM when a consumer can be down for minutes and must catch up.
What does the integer returned by PUBLISH actually mean?
PUBLISH returns the subscriber count at that instant, which is a debugging hint, not a delivery guarantee. Zero means nobody was listening, not that Redis queued it. Never use the return value as an ack.
How would you use Pub/Sub for cache invalidation, and what still breaks?
Cache invalidation over Pub/Sub is a hint to drop a local cache, not a source of truth. A missed message means stale local data until TTL. Pair with CLIENT TRACKING or a short local TTL.
What happens to a PUBLISH when no client is subscribed?
Dropped-on-the-floor is the Pub/Sub contract: with zero subscribers the payload is not stored. There is no later replay when someone SUBSCRIBE. If that is unacceptable, XADD on a STREAM is the model you wanted.
What problem does sharded Pub/Sub solve in Cluster?
SPUBLISH sharded Pub/Sub in Cluster pins a channel to a hash slot so messages are not broadcast to every node. Classic PUBLISH in Cluster is cross-node expensive. Migrate high-volume channels to sharded Pub/Sub on Redis 7+.
What happens to a slow Pub/Sub subscriber?
Output buffer limits disconnect slow Pub/Sub clients when they cannot keep up; there is no catch-up later. That is the backlog story: there is none. Tune client-output-buffer-limit pubsub or the subscriber must be faster.
How do keyspace notifications relate to Pub/Sub, and why are they lossy?
Keyspace notifications such as PSUBSCRIBE __keyevent@0__:expired are Pub/Sub under the hood and inherit fire-and-forget loss. Expired events can drop under load. Do not use them as the only sweeper for billing.
How should websocket fan-out use Redis Pub/Sub?
Fan-out to tens of thousands of websocket clients usually needs a local process that SUBSCRIBEs once and copies to sockets. Letting every browser hold a Redis Pub/Sub connection will exhaust clients and buffers. Redis is the bus, not the websocket server.
What must subscribers do after Sentinel or Cluster failover?
Message loss on Sentinel or Cluster failover is expected for Pub/Sub; subscribers must resubscribe and tolerate a gap. Replicas do not replay missed publishes. If that gap is unacceptable, you needed STREAM.
Can MULTI/EXEC make a HASH write and PUBLISH a reliable notify pair?
Pub/Sub does not become a transaction log just because you wrap HSET and PUBLISH in MULTI/EXEC. The publish still has no backlog if listeners are down. Pipeline those two commands for latency; do not confuse that with durable notify.
Why can pattern subscriptions get expensive on Cluster?
Pattern subscriptions in Cluster historically required broadcasting publishes more widely than a single channel. That extra chatter shows up as internode bandwidth. Explicit channels or sharded Pub/Sub reduce it.
Why is MONITOR the wrong way to "subscribe to every command"?
MONITOR is not Pub/Sub and must never be used to subscribe to all commands in production. It streams every command to one client and stalls the instance. Pub/Sub is the supported fan-out; MONITOR is a debug gun.
What ordering can you actually claim for Pub/Sub messages?
Ordering in Pub/Sub is per-publisher on a single node, not a global timeline across publishers. Two services PUBLISH to the same channel can interleave. If you need a total order, XADD on a STREAM.
Why do thousands of PSUBSCRIBE patterns hurt PUBLISH latency?
Thousands of PSUBSCRIBE patterns increase CPU on every PUBLISH because Redis matches patterns. Explicit channel names scale better. Collapse to a small set of channels with a payload type field.
How can STREAM and Pub/Sub work together without pretending Pub/Sub is durable?
Combining a STREAM for the durable log with a Pub/Sub ping for "something new" lets workers XREAD from the last ID after a notify. The notify can drop; the STREAM cannot if persisted. That hybrid is a strong senior answer.
How do ACL rules differ for PUBLISH versus SUBSCRIBE?
ACL can allow PUBLISH but deny SUBSCRIBE on a user, which is how you stop a compromised app from eavesdropping. Treat channels as sensitive if payloads have PII. TLS still matters because Pub/Sub is plaintext otherwise.
If pubsub output buffers keep disconnecting clients, what should change in the design?
Slow consumers get disconnected when the pubsub output buffer hits client-output-buffer-limit; they never receive a replay. Instrument disconnects. If that happens often, the design should have been STREAM with XREADGROUP.
Practice with AI mock interviews
Run Redis mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.
Free to start · No credit card required