Redis Pub/Sub Interview Questions

Master Redis Publish/Subscribe (Pub/Sub) with interview-focused questions covering Pub/Sub architecture, publishers, subscribers, channels, pattern subscriptions, event-driven systems, messaging, Redis Streams comparison, Spring Boot integration, and enterprise production best practices.

Introduction

Modern applications require components to communicate in real time.

Examples include

  • Chat Applications
  • Notification Systems
  • Order Processing
  • IoT Devices
  • Online Gaming
  • Stock Market Updates
  • Live Dashboards

Redis provides a lightweight messaging mechanism called Publish/Subscribe (Pub/Sub).

Unlike queues,

Redis Pub/Sub delivers messages immediately to all active subscribers.

It is widely used in

  • Microservices
  • Event-Driven Architecture
  • Real-Time Notifications
  • Distributed Applications

Redis Pub/Sub Architecture

flowchart LR

Publisher --> RedisChannel["Redis Channel"]

RedisChannel["Redis Channel"] --> Subscriber1["Subscriber 1"]

RedisChannel["Redis Channel"] --> Subscriber2["Subscriber 2"]

RedisChannel["Redis Channel"] --> Subscriber3["Subscriber 3"]

1. What is Redis Pub/Sub?

Answer

Redis Pub/Sub is a messaging model where

  • Publishers send messages
  • Subscribers receive messages
  • Redis Channels connect them

Neither publishers nor subscribers know about each other.

Redis acts as the message broker.


2. Why use Redis Pub/Sub?

Benefits

  • Real-Time Messaging
  • Simple Architecture
  • Low Latency
  • Loose Coupling
  • High Throughput

Without Pub/Sub

Service A

↓

Direct Call

↓

Service B

↓

Tightly Coupled

With Pub/Sub

Service A

↓

Redis Channel

↓

Service B

↓

Service C

↓

Loose Coupling

3. What are the main components?

Redis Pub/Sub consists of

  • Publisher
  • Channel
  • Subscriber
  • Redis Server

Pub/Sub Components

Publisher

↓

Channel

↓

Subscriber

4. What is a Publisher?

A Publisher sends messages to a Redis channel.

Example

PUBLISH orders

"Order Created"

5. What is a Subscriber?

A Subscriber listens for messages from one or more channels.

Example

SUBSCRIBE orders

6. What is a Channel?

A Channel is a logical topic used to deliver messages.

Examples

orders

payments

notifications

chat

Channel Architecture

flowchart TD

orders

payments

notifications

chat

7. Can multiple subscribers listen to one channel?

Yes.

One published message is delivered to all currently connected subscribers.


Multiple Subscribers

flowchart LR

Publisher --> OrdersChannel["Orders Channel"]

OrdersChannel["Orders Channel"] --> InventoryService["Inventory Service"]

OrdersChannel["Orders Channel"] --> NotificationService["Notification Service"]

OrdersChannel["Orders Channel"] --> BillingService["Billing Service"]

8. Can one subscriber subscribe to multiple channels?

Yes.

Example

SUBSCRIBE

orders

payments

notifications

9. What command publishes messages?

Example

PUBLISH

orders

"New Order"

10. What command subscribes?

Example

SUBSCRIBE orders

11. What is PSUBSCRIBE?

PSUBSCRIBE

supports

pattern matching.

Example

PSUBSCRIBE order*

Matches

orders

order-created

order-updated

Pattern Subscription

flowchart LR

order* --> orders

order* --> order-created

order* --> order-paid

12. What is PUNSUBSCRIBE?

Removes

pattern subscriptions.

Example

PUNSUBSCRIBE order*

13. What is UNSUBSCRIBE?

Stops listening

to one or more channels.

Example

UNSUBSCRIBE orders

14. Does Redis store Pub/Sub messages?

No.

Messages exist only while subscribers are connected.

If no subscriber is listening,

the message is lost.


Pub/Sub Delivery

Publisher

↓

Channel

↓

Active Subscriber

✓ Delivered

Offline Subscriber

✗ Lost

15. Is Redis Pub/Sub reliable?

No.

Redis Pub/Sub provides

At-most-once delivery.

There is

  • No Persistence
  • No Acknowledgment
  • No Retry

16. What is At-most-once Delivery?

Message

Published

↓

Delivered Once

↓

No Retry

If delivery fails,

the message is lost.


17. Does Pub/Sub guarantee ordering?

Messages published to the same channel are delivered to connected subscribers in the order Redis processes them.

However,

there is no replay for disconnected subscribers.


18. What happens if a subscriber disconnects?

Messages published

during the disconnect

are lost.

Redis does not replay them.


19. What is Redis Streams?

Redis Streams

provide

persistent messaging

with

  • Message IDs
  • Consumer Groups
  • Acknowledgments
  • Replay

Streams are recommended for reliable event processing.


Pub/Sub vs Streams

Pub/Sub Streams
Real-Time Persistent
No Storage Stores Messages
No Replay Replay Supported
No Ack Acknowledgment
Simple Messaging Reliable Messaging

20. When should Pub/Sub be used?

Use Pub/Sub for

  • Notifications
  • Chat
  • Live Dashboards
  • Monitoring
  • Real-Time Events

21. When should Pub/Sub NOT be used?

Avoid Pub/Sub for

  • Financial Transactions
  • Order Processing
  • Payment Systems
  • Guaranteed Delivery
  • Event Replay

Use Redis Streams or Kafka instead.


22. How does Spring Boot support Redis Pub/Sub?

Spring Data Redis provides

  • RedisTemplate
  • RedisMessageListenerContainer
  • MessageListener
  • ChannelTopic

Spring Boot Publisher

redisTemplate.convertAndSend(
    "orders",
    "Order Created"
);

Spring Boot Subscriber

@Component
public class OrderSubscriber {

    @RedisListener(topics = "orders")
    public void receive(String message) {

        System.out.println(message);

    }

}

23. Banking Example

Transaction Completed

Publish

Notification Service

SMS Service

Email Service


24. E-Commerce Example

Order Created

Publish

Inventory

Billing

Notification

Analytics


25. Chat Application Example

User Sends Message

Redis Channel

All Connected Users

Instant Delivery


26. Gaming Example

Player Score Updated

Leaderboard Service

Live Dashboard

Mobile Notification


27. IoT Example

Temperature Sensor

Publish

Monitoring System

Alert Service

Dashboard


28. Production Example

Microservice A

Publish Order Event

Inventory Service

Email Service

Shipping Service

Audit Service

All receive the event simultaneously.


29. Common Pub/Sub Limitations

  • No Persistence
  • No Message Replay
  • No Acknowledgment
  • No Consumer Groups
  • Offline Subscribers Miss Messages
  • Not Suitable for Critical Events

Redis Pub/Sub Workflow

flowchart LR

Publisher --> Redis --> Channel --> Subscribers

Subscribers --> BusinessServices["Business Services"]

Enterprise Best Practices

  • Use Pub/Sub for real-time notifications.
  • Keep published messages small.
  • Avoid business-critical workflows with Pub/Sub alone.
  • Use Redis Streams for reliable messaging.
  • Use meaningful channel names.
  • Monitor subscriber health.
  • Separate notification channels by business domain.
  • Avoid excessive channel creation.
  • Secure Redis using authentication and network isolation.
  • Consider Kafka or RabbitMQ for durable enterprise messaging.

Quick Revision

Topic Key Point
Pub/Sub Publish Subscribe Messaging
Publisher Sends Messages
Subscriber Receives Messages
Channel Message Topic
SUBSCRIBE Listen to Channel
PUBLISH Send Message
PSUBSCRIBE Pattern Subscription
UNSUBSCRIBE Stop Listening
At-most-once No Retry
Streams Persistent Messaging

Interview Tips

Interviewers frequently ask

  • What is Redis Pub/Sub?
  • Publisher vs Subscriber.
  • What is a Channel?
  • How does Pub/Sub work?
  • Pub/Sub vs Redis Streams.
  • Does Pub/Sub store messages?
  • What happens if a subscriber disconnects?
  • Is Pub/Sub reliable?
  • How does Spring Boot integrate Redis Pub/Sub?
  • Give a real-world production example.

A strong interview explanation is:

"Redis Pub/Sub is a lightweight messaging system where publishers send messages to channels and all active subscribers immediately receive them. It is ideal for real-time notifications, chat systems, dashboards, and event broadcasting. Since Pub/Sub provides at-most-once delivery without persistence or acknowledgments, it should not be used for business-critical workflows. For reliable messaging with replay and acknowledgments, Redis Streams is the preferred choice."


Summary

Redis Pub/Sub provides a fast, lightweight messaging mechanism for building event-driven and real-time applications. By decoupling publishers and subscribers through channels, it enables scalable communication between distributed services. However, because Pub/Sub does not persist messages or support acknowledgments, it is best suited for transient events rather than mission-critical messaging.

Understanding Publishers, Subscribers, Channels, Pattern Subscriptions, Spring Boot integration, and the differences between Pub/Sub and Redis Streams is essential for Backend Developers, Microservices Engineers, DevOps Engineers, and Solution Architects designing modern distributed systems.