Lesson 20 / 20
Redis as a Message Broker
Compare Redis Pub/Sub with Streams and know when to choose a dedicated broker such as Kafka or RabbitMQ.
Pub/Sub is fire-and-forget
Plain Pub/Sub delivers messages only to subscribers connected right now — nothing is stored, so an offline consumer misses it forever. Redis Streams (XADD/XREAD) add a durable, replayable log for when messages must not be lost.
Not a Kafka replacement
For lightweight, low-latency messaging Redis is excellent; for massive, guaranteed-durable, multi-day event streams, a dedicated broker like Kafka or RabbitMQ is usually a better fit.
Quick check: Does plain Redis Pub/Sub store messages for subscribers who are offline?
- Yes, forever
- Yes, but only for 24 hours
- No — only currently connected subscribers get it
- Only if AOF is disabled
Answer
No — only currently connected subscribers get it — Pub/Sub has no storage — use Redis Streams when messages need to survive for offline consumers.
Final quiz 1 of 8
Final quiz
Quick check: Which Redis data type is best for a live leaderboard?
- List
- String
- Sorted set
- Pub/Sub
Answer
Sorted set — Sorted sets keep members ranked by score automatically.
Final quiz 2 of 8
Final quiz
Quick check: Which command safely iterates keys on a production server?
- KEYS *
- FLUSHALL
- DEBUG
- SCAN
Answer
SCAN — SCAN walks the keyspace in small non-blocking batches.
Final quiz 3 of 8
Final quiz
Quick check: What does SET key value EX 60 do?
- Stores the value and expires it after 60 seconds
- Stores it for 60 days
- Appends 60 to the value
- Locks the key
Answer
Stores the value and expires it after 60 seconds — EX sets the TTL in seconds together with the value.
Final quiz 4 of 8
Final quiz
Quick check: In cache-aside, what happens on a cache miss?
- Redis queries the database itself
- The app reads the database and then fills the cache
- The request fails
- The cache is flushed
Answer
The app reads the database and then fills the cache — The application owns loading data into the cache.
Final quiz 5 of 8
Final quiz
Quick check: Which persistence option logs every write command?
- RDB
- Pub/Sub
- AOF
- Streams only
Answer
AOF — AOF replays commands to rebuild the dataset with minimal loss.
Final quiz 6 of 8
Final quiz
Quick check: Which maxmemory-policy suits a pure cache?
- noeviction
- volatile-ttl only
- none
- allkeys-lru
Answer
allkeys-lru — Evicting least recently used keys keeps hot data in memory.
Final quiz 7 of 8
Final quiz
Quick check: Why avoid exposing Redis directly to the internet?
- It was designed for trusted networks and can be hijacked
- It becomes slower
- It stops persisting
- It disables TTLs
Answer
It was designed for trusted networks and can be hijacked — Bind to private interfaces, require auth and use a firewall.
Final quiz 8 of 8
Final quiz
Quick check: Which Redis feature keeps a durable, replayable log of messages?
- Plain Pub/Sub
- Streams
- SCAN
- EXPIRE
Answer
Streams — Streams (XADD/XREAD) retain messages for consumers that connect later.