Redis

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.

Question 1
Interview Beginner
Question

Why do interviewers call Redis Pub/Sub fire-and-forget?

Answer:

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.

Question 2
Interview Beginner
Question

Why must SUBSCRIBE use a dedicated connection?

Answer:

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.

Question 3
Interview Beginner
Question

When is PSUBSCRIBE a better fit than listing channels?

Answer:

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.

Question 4
Interview Beginner
Question

When do you pick Pub/Sub versus STREAM?

Answer:

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.

Question 5
Interview Beginner
Question

What does the integer returned by PUBLISH actually mean?

Answer:

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.

Question 6
Interview Beginner
Question

How would you use Pub/Sub for cache invalidation, and what still breaks?

Answer:

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.

Question 7
Interview Beginner
Question

What happens to a PUBLISH when no client is subscribed?

Answer:

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.

Question 8
Interview Intermediate
Question

What problem does sharded Pub/Sub solve in Cluster?

Answer:

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+.

Question 9
Interview Intermediate
Question

What happens to a slow Pub/Sub subscriber?

Answer:

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.

Question 10
Interview Intermediate
Question

How do keyspace notifications relate to Pub/Sub, and why are they lossy?

Answer:

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.

Question 11
Interview Intermediate
Question

How should websocket fan-out use Redis Pub/Sub?

Answer:

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.

Question 12
Interview Intermediate
Question

What must subscribers do after Sentinel or Cluster failover?

Answer:

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.

Question 13
Interview Intermediate
Question

Can MULTI/EXEC make a HASH write and PUBLISH a reliable notify pair?

Answer:

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.

Question 14
Interview Intermediate
Question

Why can pattern subscriptions get expensive on Cluster?

Answer:

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.

Question 15
Interview Advanced
Question

Why is MONITOR the wrong way to "subscribe to every command"?

Answer:

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.

Question 16
Interview Advanced
Question

What ordering can you actually claim for Pub/Sub messages?

Answer:

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.

Question 17
Interview Advanced
Question

Why do thousands of PSUBSCRIBE patterns hurt PUBLISH latency?

Answer:

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.

Question 18
Interview Advanced
Question

How can STREAM and Pub/Sub work together without pretending Pub/Sub is durable?

Answer:

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.

Question 19
Interview Advanced
Question

How do ACL rules differ for PUBLISH versus SUBSCRIBE?

Answer:

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.

Question 20
Interview Advanced
Question

If pubsub output buffers keep disconnecting clients, what should change in the design?

Answer:

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