DEV Community

Athreya aka Maneshwar
Athreya aka Maneshwar

Posted on

Redis Pub/Sub vs Redis Streams: A Dev-Friendly Comparison

Redis Pub/Sub vs Redis Streams: A Developer-Friendly Comparison

Redis has two powerful messaging mechanisms: Pub/Sub and Streams.

Both cater to specific needs, and understanding the difference can help you make the right choice for your use case.

Let’s break it down, developer-style.

Feature-by-Feature Breakdown

Feature Redis Pub/Sub Redis Streams
Data Structure Publish/subscribe mechanism Append-only logs
Message Persistence No message persistence by default Messages are persisted in a stream
Message History No message history is maintained Message history is stored in the stream
Message Filtering All messages are received by subscribers Subscribers can filter by pattern or consumer groups
Message Delivery At-least-once delivery semantics Exactly-once delivery semantics
Consumer Groups Not supported Supported for multiple consumers
Scalability Limited scalability Scales better for large numbers of consumers
Message Retention No built-in message retention Configurable message retention
Use Cases Real-time notifications Event sourcing

What Does This Mean for You?

Redis Pub/Sub

  • Good for: Real-time notifications, chat apps, or any use case where speed and simplicity are key.
  • Think of it like: A group chat where everyone hears what’s said, but once it’s said, it’s gone forever.

Image description

Redis Streams

  • Good for: Event sourcing, durable message queues, and systems requiring replayable logs or advanced processing.
  • Think of it like: A detailed logbook where every entry is stored and can be read whenever needed.

Image description


TL;DR

Redis Pub/Sub or Redis Streams?

The answer depends on your use case.

For real-time notifications, go with Pub/Sub. For persistence and scalability, Redis Streams is your best bet.

By the way, if you’re working on building queuing systems or event-driven architectures, check out LiveAPI.

LiveAPI helps you get all your backend APIs documented in a few minutes. 🚀

With LiveAPI, you can quickly generate interactive API documentation that allows users to execute APIs directly from the browser.

Image description

Top comments (3)

Collapse
 
kamalhinduja profile image
Kamal Hinduja

Great Explanation.

Collapse
 
lovestaco profile image
Athreya aka Maneshwar

Thanks :)

Collapse
 
imthedeveloper profile image
ImTheDeveloper

What's the downside to using streams Vs pub sub. It feels like you can almost use it as a queue as well if you force some concurrency in processing limit.

From what I've read you can set a limit on the stream length which actually means you can have a small level of durability or large. It just seems to offer lots of benefits.