0
0
Redisquery~10 mins

Pub/sub vs streams comparison in Redis - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Concept Flow - Pub/sub vs streams comparison
Publish message
Subscribers get message
No message history
Messages lost if offline
Simple, real-time only
Choose based on use case
Shows the flow of messages in Pub/Sub and Streams, highlighting real-time delivery vs durable storage.
Execution Sample
Redis
PUBLISH news "Hello"
SUBSCRIBE news
XADD mystream * message "Hello"
XREAD COUNT 1 STREAMS mystream 0
Publishes a message to a channel and adds a message to a stream, then reads from the stream.
Execution Table
StepCommandActionResult
1PUBLISH news "Hello"Send message to 'news' channelSubscribers to 'news' receive 'Hello' immediately
2SUBSCRIBE newsSubscribe client to 'news' channelClient will receive future messages published to 'news'
3XADD mystream * message "Hello"Add message to 'mystream' streamMessage stored with ID, durable in stream
4XREAD COUNT 1 STREAMS mystream 0Read one message from 'mystream' starting at ID 0Returns the stored message 'Hello'
5PUBLISH news "World"Send another message to 'news' channelSubscribers receive 'World' immediately
6XREAD COUNT 1 STREAMS mystream 0Read next message from 'mystream'No new message, returns empty
7Client offline during PUBLISHMessage sent to 'news' while client offlineClient misses message, no recovery
8Client offline during XADDMessage added to stream while client offlineClient can read message later from stream
💡 Execution stops after showing message delivery and storage differences between Pub/Sub and Streams.
Variable Tracker
VariableStartAfter Step 1After Step 3After Step 5After Step 8
PubSub Channel 'news'emptymessage 'Hello' sentmessage 'Hello' sentmessage 'World' sentmessage 'World' sent
Stream 'mystream'emptymessage 'Hello' storedmessage 'Hello' storedmessage 'Hello' storedmessage 'Hello' stored
Key Moments - 3 Insights
Why does a subscriber miss messages if offline in Pub/Sub?
Because Pub/Sub delivers messages only to connected clients at publish time (see execution_table step 7). Offline clients do not get stored messages.
How does Streams ensure message durability?
Streams store messages with IDs in a log, so clients can read messages later even if they were offline (see execution_table steps 3, 4, and 8).
Can Pub/Sub messages be replayed after delivery?
No, Pub/Sub messages are transient and not stored, so they cannot be replayed (see execution_table step 7).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what happens at step 4 when reading from the stream?
AThe stored message 'Hello' is returned
BNo message is returned
CA new message is published to the channel
DThe stream is deleted
💡 Hint
Check the 'Result' column in execution_table row for step 4
At which step does the Pub/Sub subscriber miss a message due to being offline?
AStep 2
BStep 7
CStep 3
DStep 8
💡 Hint
Look for the step describing client offline during PUBLISH in execution_table
If you want to replay messages after being offline, which Redis feature should you use?
APub/Sub
BSorted Sets
CStreams
DHashes
💡 Hint
Refer to key_moments about message durability and replay
Concept Snapshot
Pub/Sub delivers messages instantly to connected clients only.
No message history; offline clients miss messages.
Streams store messages with IDs for durability.
Clients can read and replay messages later.
Choose Pub/Sub for simple real-time needs.
Choose Streams for reliable, replayable messaging.
Full Transcript
This visual execution compares Redis Pub/Sub and Streams. Pub/Sub sends messages immediately to connected subscribers but does not store messages. If a subscriber is offline, it misses messages. Streams store messages with unique IDs, allowing clients to read messages later, even if they were offline. The execution table shows publishing and subscribing steps, message storage in streams, and how clients read messages. Key moments clarify why Pub/Sub messages are transient and Streams provide durability. The quiz tests understanding of message delivery, offline behavior, and replay capabilities. This helps beginners see the practical differences and choose the right Redis feature for their needs.