Katkat

Implement a Single-Node Priority Pub/Sub

AmazonSoftware Engineer · Onsite

Last updated

This question evaluates understanding of concurrent system design, in-memory publish–subscribe semantics, prioritized delivery ordering, API and data structure selection, and thread-safety within the Software Engineering Fundamentals domain.

Implement a simplified in-memory publish-subscribe system that runs on a single machine.

The system should support users subscribing to topics with a priority.

Requirements

  1. A user can subscribe to a topic with an integer priority.
  2. A user can unsubscribe from a topic.
  3. A publisher can publish a message to a topic.
  4. When a message is published, it should be delivered to all current subscribers of that topic in descending priority order.
  5. If two subscribers have the same priority, deliver to the one who subscribed earlier first.
  6. The implementation should be thread-safe enough to support concurrent subscribe, unsubscribe, and publish calls on a single process.

Design the classes, main APIs, data structures, and explain the trade-offs.