Redis Pub/Sub & Streams interview questions

25 questions from the Redis Pub/Sub & Streams course, each with the correct answer and an explanation. Try to answer before you open the answer.

Messaging with Redis

1. A subscriber is disconnected for 10 seconds while messages are published to its Pub/Sub channel. What happens to those messages for that subscriber?

  1. They are lost for that subscriber
  2. They are queued until it reconnects
  3. They move to a stream automatically
  4. They are delivered twice later
Show answer

Answer: They are lost for that subscriber

Redis Pub/Sub stores nothing; only currently connected subscribers receive messages.

Lesson: Three Messaging Tools in One Server

2. With the RESP2 protocol, what can a connection do after it issues SUBSCRIBE?

  1. Run any Redis command as usual
  2. Only PUBLISH
  3. Nothing until it disconnects
  4. Only subscription-related commands plus PING, RESET and QUIT
Show answer

Answer: Only subscription-related commands plus PING, RESET and QUIT

In RESP2 a subscribed connection is limited to subscription commands; RESP3 lifts this restriction.

Lesson: Running Redis and Using redis-cli

3. Which requirement suggests a dedicated log such as Kafka rather than Redis Streams?

  1. Low-latency fan-out to a few services
  2. A small job queue
  3. Months of retention of very high-volume events on disk
  4. Cache invalidation messages
Show answer

Answer: Months of retention of very high-volume events on disk

Redis keeps streams in memory, so very long, very large retention is better suited to disk-based logs.

Lesson: Choosing Between Pub/Sub, Lists, Streams and a Broker

Redis Pub/Sub

4. What does the PUBLISH command return?

  1. The message ID
  2. The channel length
  3. The number of clients that received the message
  4. Always OK
Show answer

Answer: The number of clients that received the message

PUBLISH returns how many subscribers the message was delivered to.

Lesson: PUBLISH and SUBSCRIBE

5. Why is Pub/Sub acceptable for cache invalidation even though messages can be lost?

  1. Redis guarantees delivery for invalidation messages
  2. Local cache entries also expire through a TTL, which bounds staleness if a message is missed
  3. Caches never become stale
  4. PSUBSCRIBE stores missed messages
Show answer

Answer: Local cache entries also expire through a TTL, which bounds staleness if a message is missed

A TTL acts as a safety net, so a lost invalidation only causes bounded staleness.

Lesson: Pattern Subscriptions and Common Uses

6. What does Redis do to a Pub/Sub subscriber whose output buffer exceeds the configured limit?

  1. Disconnects the subscriber, which then misses messages
  2. Pauses publishers
  3. Writes the messages to disk
  4. Converts the channel to a stream
Show answer

Answer: Disconnects the subscriber, which then misses messages

Output buffer limits protect Redis memory by disconnecting clients that cannot keep up.

Lesson: Limits: Slow Subscribers, Reconnects and Scale

Advanced Pub/Sub: Cluster, Keyspace Events and Real-Time Apps

7. Why does sharded Pub/Sub scale better than classic Pub/Sub in Redis Cluster?

  1. Each channel belongs to one shard, so messages are not broadcast to every node
  2. It stores messages on disk
  3. It removes the need for subscribers
  4. It compresses all messages
Show answer

Answer: Each channel belongs to one shard, so messages are not broadcast to every node

SPUBLISH keeps traffic within the shard that owns the channel's hash slot.

Lesson: Sharded Pub/Sub in Redis Cluster

8. Why might an expired-key notification arrive later than the key's TTL?

  1. Redis batches notifications hourly
  2. Notifications are stored on disk first
  3. Expired keys are never notified
  4. The event fires when Redis actually removes the key, which can happen after the TTL elapses
Show answer

Answer: The event fires when Redis actually removes the key, which can happen after the TTL elapses

Expiry is lazy or periodic, so the notification is emitted when deletion happens.

Lesson: Keyspace Notifications

9. Why do multiple WebSocket servers need a backplane such as Redis Pub/Sub?

  1. WebSockets cannot send JSON
  2. Redis encrypts WebSocket traffic
  3. A message must reach whichever server holds the target user's connection
  4. Load balancers cannot route WebSockets
Show answer

Answer: A message must reach whichever server holds the target user's connection

The backplane fans messages out so the server holding the right connection can deliver them.

Lesson: Scaling WebSockets and Server-Sent Events

Redis Streams Fundamentals

10. What does the first part of a stream entry ID such as 1727942712345-0 represent?

  1. A random number
  2. The consumer ID
  3. The millisecond Unix time when the entry was added
  4. The entry size in bytes
Show answer

Answer: The millisecond Unix time when the entry was added

Stream IDs combine a millisecond timestamp with a sequence number.

Lesson: The Stream Data Type

11. What does the special ID `$` mean in `XREAD ... STREAMS orders $`?

  1. Read from the very first entry
  2. Return only entries added after the call starts
  3. Read the last entry again
  4. Delete the stream
Show answer

Answer: Return only entries added after the call starts

`$` means the current last ID, so only newer entries are returned.

Lesson: XREAD and Blocking Reads

12. What does the `~` in `XADD orders MAXLEN ~ 100000 * ...` do?

  1. Allows approximate, cheaper trimming that may keep slightly more entries
  2. Makes trimming exact to the last entry
  3. Disables trimming
  4. Deletes the whole stream
Show answer

Answer: Allows approximate, cheaper trimming that may keep slightly more entries

Approximate trimming removes whole internal nodes, which is much more efficient.

Lesson: Trimming and Memory Management

Consumer Groups

13. Two consumers in the same group call XREADGROUP with `>`. What happens to a new entry?

  1. Exactly one of them receives it
  2. Both consumers receive it
  3. Neither receives it until acknowledged
  4. It is deleted immediately
Show answer

Answer: Exactly one of them receives it

Within a group, each entry is delivered to a single consumer.

Lesson: Creating Groups and Reading with XREADGROUP

14. What does calling XREADGROUP with ID `0` instead of `>` return?

  1. All entries in the stream
  2. Only the newest entry
  3. Entries from other groups
  4. Entries already delivered to this consumer but not yet acknowledged
Show answer

Answer: Entries already delivered to this consumer but not yet acknowledged

Using 0 reads the consumer's own pending history, useful for recovery after restarts.

Lesson: Acknowledgements and the Pending Entries List

15. What does XAUTOCLAIM do?

  1. Deletes all pending entries
  2. Creates a new consumer group
  3. Transfers pending entries that have been idle too long to the calling consumer
  4. Trims the stream
Show answer

Answer: Transfers pending entries that have been idle too long to the calling consumer

XAUTOCLAIM takes ownership of idle pending entries so another consumer can process them.

Lesson: Recovering Stuck Messages and Dead Letters

Design Patterns with Streams

16. What problem does BLMOVE solve compared with a plain BRPOP job queue?

  1. It makes jobs smaller
  2. It removes the need for workers
  3. It keeps the job in a processing list so it is not lost if the worker crashes
  4. It sorts jobs by priority
Show answer

Answer: It keeps the job in a processing list so it is not lost if the worker crashes

Moving atomically to a processing list preserves the job until the worker confirms completion.

Lesson: Job Queues: Streams vs Lists

17. How should several services each receive every event from the same Redis stream?

  1. Use one consumer group shared by all services
  2. Give each service its own consumer group
  3. Use XDEL after each read
  4. Publish a copy of each event per service
Show answer

Answer: Give each service its own consumer group

Each group tracks its own position, so every service sees every event.

Lesson: Event Streams Between Services

18. Why partition events across several streams in a Redis Cluster?

  1. A single stream lives on one shard, so partitioning spreads load across shards
  2. Streams cannot hold more than 100 entries
  3. To remove the need for consumer groups
  4. To make IDs shorter
Show answer

Answer: A single stream lives on one shard, so partitioning spreads load across shards

Each stream is one key on one shard; multiple streams use multiple shards.

Lesson: Partitioning Streams and Ordering

Durability, Monitoring and Operations

19. Why can a Redis failover lose recently added stream entries?

  1. Replication is asynchronous, so the promoted replica may not have the latest writes
  2. Streams are never replicated
  3. XADD deletes old entries
  4. Consumer groups are not replicated
Show answer

Answer: Replication is asynchronous, so the promoted replica may not have the latest writes

Acknowledged writes may not have reached replicas when the primary fails.

Lesson: Persistence, Replication and Data Loss

20. Which XINFO GROUPS field (Redis 7+) shows how many entries a group has not yet received?

  1. idle
  2. radix-tree-nodes
  3. last-generated-id
  4. lag
Show answer

Answer: lag

The lag field reports entries added to the stream that the group has not yet read.

Lesson: Monitoring Streams and Consumer Groups

21. Which practice helps most with sustained high-rate XADD workloads?

  1. Calling XRANGE on the whole stream after each write
  2. Using exact MAXLEN trimming on every write
  3. Pipelining or batching writes and reading with COUNT
  4. Storing multi-megabyte payloads in entries
Show answer

Answer: Pipelining or batching writes and reading with COUNT

Batching reduces round trips; reading in bounded batches keeps commands cheap.

Lesson: Memory Sizing and Performance

Clients, Comparisons and Revision

22. Why should blocking stream reads use a dedicated connection?

  1. Blocking reads require TLS
  2. Redis allows only one blocking read per server
  3. They hold the connection while waiting, delaying other commands sent on it
  4. They disable pipelining globally
Show answer

Answer: They hold the connection while waiting, delaying other commands sent on it

A blocked connection cannot serve other commands until the call returns.

Lesson: Streams in Application Frameworks

23. Which requirement favours Redis Streams over Kafka?

  1. Retaining two years of events cheaply
  2. Very low latency messaging with short retention in an existing Redis deployment
  3. Hundreds of partitions of disk-backed data
  4. Synchronous replication on every write
Show answer

Answer: Very low latency messaging with short retention in an existing Redis deployment

Redis is ideal for lightweight, low-latency messaging when retention is bounded.

Lesson: Redis Streams vs Kafka vs RabbitMQ

24. In the case study, why is live tracking sent with Pub/Sub rather than Streams?

  1. Tracking updates are ephemeral and the app can refetch the current status after reconnecting, so occasional loss is acceptable
  2. Pub/Sub stores messages longer
  3. Streams cannot be used with WebSockets
  4. Pub/Sub guarantees exactly-once delivery
Show answer

Answer: Tracking updates are ephemeral and the app can refetch the current status after reconnecting, so occasional loss is acceptable

Ephemeral, refreshable data does not need the storage and acknowledgement overhead of streams.

Lesson: Case Study: Notifications and Order Events

25. Which command acknowledges that a consumer in a group has processed a stream entry?

  1. XADD
  2. XTRIM
  3. PUBLISH
  4. XACK
Show answer

Answer: XACK

XACK removes the entry from the group's Pending Entries List.

Lesson: Revision and Interview Questions

← Back to the course