- Update the home feeds of everyone who follows the uploader.
- Add the photo to the search index.
- Run a banned-content scanner.
- And more as features are added.

SavePhoto function calling each downstream service directly, SavePhoto publishes a single event (for example, photo:99:posted) to a topic and moves on. The publisher does not need to know who subscribes — it only announces what happened.
Subscribers register interest in that topic and process their own copy of the event:
- The Thumbnail Service subscribes to create thumbnails.
- The Feed Service subscribes to update followers’ home feeds.
- The Search Indexer subscribes to add the photo to the search index.
- The Banned Content Scanner subscribes to check for illicit content.

The main advantages of pub/sub are loose coupling and fault isolation. Services don’t need to know about one another: to add a new feature (such as a banned-content scanner), you don’t modify
SavePhoto; you simply subscribe the scanner to the photo:posted topic and it starts receiving events.
Fault isolation: each subscriber can be slow or fail without blocking others. With a durable pub/sub system, events are retained so a subscriber that was down can resume and catch up. For example, if the Search Indexer is down when an upload happens, the Thumbnail and Feed updates still run; when the indexer restarts it consumes the backlog and updates the index.


- Use pub/sub when one occurrence must trigger many independent reactions and those reactions should evolve independently.
- Use a queue when exactly one worker must process each job and the work is a single responsibility.
Pub/Sub is ideal for decoupling and scaling many independent reactions to the same event. For simple one-off work items where exactly one worker must process the job, a queue is still the simpler and more appropriate choice.
Links and references
- Kafka (event streaming): https://learn.kodekloud.com/user/courses/event-streaming-with-kafka
- Pub/Sub pattern overview: https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern