← back to stream

Redis Pub/Sub

#backend#redis

Redis Pub/Sub is a fire-and-forget messaging primitive: publishers PUBLISH channel message, subscribers SUBSCRIBE channel and receive whatever arrives while they're connected. Simple, low-latency, zero setup. The catch that bites everyone: no persistence, no delivery guarantees — a subscriber that's disconnected for 3 seconds misses everything in those 3 seconds, full stop. Good uses: live notifications to connected WebSocket clients, cache invalidation broadcasts across app servers, presence updates — things where "lost = doesn't matter, new one is coming". Bad uses: anything where the event is the source of truth. For that, use Redis Streams (persistent, consumer groups, replay) or a real message broker (Kafka, RabbitMQ). Pattern subscriptions (PSUBSCRIBE user:*:notifications) work but add CPU cost per match. Pub/Sub is great exactly when it fits; the trap is using it for something it can't do.