AlgoMaster Logo

Design Pub Sub System

Ashish

Ashish Pratap Singh

medium

In this chapter, we will explore the low-level design of a simple in-memory pub-sub system.

Lets start by clarifying the requirements:

1. Clarifying Requirements

Before starting the design, it's important to ask thoughtful questions to uncover hidden assumptions and better define the scope of the system.

Here is an example of how a conversation between the candidate and the interviewer might unfold:

After gathering the details, we can summarize the key system requirements.

1.1 Functional Requirements

  • Support creation and management of multiple topics
  • Allow multiple publishers to publish messages to a topic
  • Allow multiple subscribers to subscribe to one or more topics
  • Deliver messages to all active subscribers of a topic in the order they were published
  • Ensure non-blocking, asynchronous message delivery
  • Follow a "fire-and-forget" delivery model: no retries, or acknowledgments

1.2 Non-Functional Requirements

  • Modularity: The system should follow object-oriented principles with clear separation of responsibilities
  • Scalability: The system should efficiently support many concurrent publishers and subscribers
  • Extensibility: The design should be flexible enough to support future enhancements such as message persistence, retries, or delivery guarantees
  • Reliability: While exact delivery guarantees are not required, message ordering and dispatching must remain consistent and predictable within each topic

After the requirements are clear, lets identify the core entities/objects we will have in our system.

2. Identifying Core Entities

Premium Content

This content is for premium members only.