CodePark/ questions / Pub/Sub & Streams
START PRACTICINGPRACTICE
Backend question · Redis & caching › Pub/Sub & Streams

A Pub/Sub subscriber restarts and is disconnected for 10 seconds. What happens to messages published to its channel during that time?

They are lost for that subscriber

The messages are lost for that subscriber. Pub/Sub delivers only to subscribers that are connected right now, and it keeps no history. PUBLISH just returns how many clients received the message, and this number can be 0. It does not return an error, so "Publishers get an error and must retry" is wrong. Redis also does not keep the messages, so "Redis buffers them and delivers them on reconnect" is wrong. Channels have no TTL either. If you need to replay messages after downtime, use Streams.