Redis pub/sub vs Streams

Redis pub/sub vs Streams

Redis Pub/Sub and Redis Streams are two different features provided by Redis for messaging and event-driven architectures. While they can be used for similar purposes, there are some key differences between them.


Redis Pub/Sub:

Redis Pub/Sub (Publish/Subscribe) is a messaging pattern in which publishers send messages to channels, and subscribers receive messages from those channels. It follows a one-to-many communication model, where multiple subscribers can listen to the same channel and receive messages independently. Publishers and subscribers are decoupled, meaning they don’t have direct knowledge of each other.

With Redis Pub/Sub, messages are not persisted in Redis. If a subscriber is not actively listening to a channel when a message is published, the subscriber will miss that message. Redis Pub/Sub is useful for real-time notifications, broadcasting messages to multiple recipients, and building simple publish/subscribe systems.


Redis Streams:

Redis Streams is a more advanced feature introduced in Redis 5.0. It provides a log-like data structure that combines the functionality of a message broker and a distributed log. Streams allow you to append messages to a log and read them in a chronological order. Each message in a stream is assigned a unique ID, making it possible to process messages in an ordered and reliable manner.

In contrast to Pub/Sub, Redis Streams persist messages on the Redis server. Subscribers can consume messages at their own pace, and even if a subscriber is offline or disconnected, it can resume consuming messages from the point it left off. Streams also provide features like message acknowledgment, consumer groups, and automatic message retention policies.

Redis Streams are well-suited for building message queues, event sourcing systems, and processing streams of events in a reliable and ordered manner.


In summary, Redis Pub/Sub is a simple publish/subscribe messaging pattern for real-time notifications, while Redis Streams provide a more sophisticated message broker with ordered message processing and persistence capabilities. The choice between the two depends on the specific requirements of your use case.

#redis #streams #pub/sub #distributedsystems #messaging

要查看或添加评论,请登录

Osama Ahmed的更多文章

  • Exploring CQRS: How to Name Queries and Commands Effectively

    Exploring CQRS: How to Name Queries and Commands Effectively

    General Principles Be Specific and Descriptive: The name should clearly convey the intent of the handler (what action…

  • Stateful vs Stateless Architectures: Choosing the Right Fit for Your Application

    Stateful vs Stateless Architectures: Choosing the Right Fit for Your Application

    In today’s world of distributed applications and cloud-native design, understanding architectural approaches is key to…

  • Database Scaling: 10 must-know strategies to scale your?database

    Database Scaling: 10 must-know strategies to scale your?database

    As your application grows and the amount of data in your database increases, you’ll inevitably need to scale your…

  • Redis Sentinel vs Redis Cluster

    Redis Sentinel vs Redis Cluster

    Redis Sentinel and Redis Cluster are two different solutions provided by Redis for achieving high availability and…

  • Outbox Pattern: Reliable Event Publishing in Microservices

    Outbox Pattern: Reliable Event Publishing in Microservices

    Microservices architectures are becoming increasingly popular for building scalable and maintainable applications. One…

  • Pub/Sub System vs Queues

    Pub/Sub System vs Queues

    A Pub/Sub (Publish/Subscribe) system and queues are both messaging patterns used in distributed systems to facilitate…

    2 条评论
  • Rate Limiting in?.NET?6

    Rate Limiting in?.NET?6

    What is rate limiting ? Rate limiting is a technique used to control the rate at which requests are made to a network…

  • Monitoring Microservices

    Monitoring Microservices

    A key part of the production environment is monitoring and alerting. Monitoring microservices is crucial for…

  • Don't Build a Distributed Monoliths

    Don't Build a Distributed Monoliths

    Microservices architecture has become popular over the past few years. As a result, many developers, companies have…

社区洞察

其他会员也浏览了