Design an In-Memory Pub-Sub Model
Company: Amazon
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Technical Screen
Design an object-oriented, in-memory publish-subscribe model.
Requirements:
- A publisher can publish a message to a topic.
- A subscriber can subscribe to or unsubscribe from a topic.
- When a message is published to a topic, all current subscribers of that topic should receive the message.
- The design should support multiple topics and multiple subscribers.
- Define the main classes, interfaces, and public APIs.
- Explain the delivery behavior, thread-safety considerations, and how you would extend the design for retries, persistence, or asynchronous delivery.
Quick Answer: This question evaluates object-oriented design and API modeling skills, knowledge of messaging/pub-sub semantics, concurrency and thread-safety, and the ability to reason about extensibility for retries, persistence, and asynchronous delivery.