Design a pub/sub message broker
The interviewer asks you to design the classes of a small message broker inside one program. A publisher sends a message to a topic, and every subscriber of that topic gets its own copy. Picture a hiking club's mailing room. The secretary numbers each newsletter and puts one copy in a tray for each member on its list. A few volunteers each take one tray and walk to that member's door. A member who talks for an hour keeps one volunteer, and only that member's tray waits.
It is also asked as "design a message broker" or "an in-memory event bus". The closest other case study is the logging framework, which has one reader where this has many. Interviewers like it because the obvious code, a loop that calls each subscriber, lets one slow subscriber hold back everyone. This page is the class-level part. Pub/sub owns the concept, and Distributed message queue owns the broker on many machines.
Below is a full 45-minute round on the LLD framework. You are the candidate. At each Guess before you read on, stop and answer first. The full runnable project, with its tests, is a download in Java, JavaScript and Python.
Run the full project
This design as a project you can run, with its tests and a demo. You only need Java 21, Node 24 or Python 3.13. The README says how to run it.
Step 1 · Clarify the requirements and cut the scope
Minutes 0–5 · How this step works
Interviewer: Design a pub/sub message broker.
You: Is this inside one program, or across machines?
Interviewer: One program, with many threads.
You: Does a publisher ever wait for a subscriber?
Interviewer: Never. A slow subscriber must not hold back the publisher or the other subscribers.
You: Must every subscriber of a topic see its messages in the same order?
Interviewer: Yes.
You: What if a subscriber throws, or can't keep up?
Interviewer: One that throws keeps getting messages. One that can't keep up may lose messages, but I want a count.