Amazon·Software Engineer·Onsite - System Design / Architecture
- Design an in-process publish/subscribe messaging system supporting multiple topics, multiple subscribers per topic, and a subscriber registered on more than one topic.
- How would you handle concurrency when publishers and subscribers run on separate threads? Walk through your locking strategy.
- What delivery semantics does your broker provide, and what happens if a subscriber's callback throws an exception during message delivery?
- How do you prevent a slow subscriber from causing memory to grow unboundedly in the broker?
- Can you extend this design to support per-subscription priority, where higher-priority subscribers receive a message before lower-priority ones?
“I started with the class structure: a Broker holding a map of topic to subscriber sets, a Subscriber interface with an onMessage callback, and Topic as a string wrapper.”