Pub/sub
In publish/subscribe, a service sends a message to a topic without knowing who will read it, and every subscriber gets its own copy. It's how one "order placed" reaches email, analytics and fraud, and how a chat server finds the gateway holding someone's connection. Interviewers ask what a subscriber misses while it's down, and how the fan-out scales.
The radio and the magazine
A radio station broadcasts the news. Anyone tuned in hears it, and the station has no idea who's listening. If your radio was off, you missed it; nobody kept a copy for you.
A magazine posts a copy to every subscriber's letterbox. If you're away for two weeks, the issues pile up in the letterbox and you read them when you're back. You can ask for just the sports supplement. The publisher still doesn't care what you do with your copy.
- the station or the magazine → the publisher
- you, the listener or reader → a subscriber
- the frequency, or the magazine's title → the topic (Redis calls it a channel)
- tuning in → an ephemeral subscription: only listeners connected right now get the message (Redis pub/sub, plain NATS)
- the letterbox → a durable subscription: a queue of its own that holds messages until they're read (Amazon SNS into SQS, Google Cloud Pub/Sub, a Kafka consumer group)
- the sports supplement → a filter