Loading LLD design...
Design an object-oriented publish-subscribe messaging system where publishers send messages to named topics and subscribers receive those messages either via push (immediate notification) or pull (offset-based polling).
The system should support topic management, subscriber registration with independent offset tracking, subscription pause/resume, and message filtering. The broker acts as a mediator between publishers and subscribers.
Create and delete topics
Register named topics that act as message channels
Subscribe to a topic
Subscribers register interest in a topic and receive messages
Unsubscribe from a topic
Remove a subscriber from a topic's notification list
Publish a message
Publishers send messages to a topic; all active subscribers are notified (push model)
Poll for messages
Subscribers pull the next unread message using an offset-based cursor (pull model)
Pause and resume subscriptions
Temporarily halt delivery without losing the subscriber's position
Message filtering
Some subscribers only process messages matching a predicate
Before diving into code, clarify the use cases and edge cases. Understanding the problem deeply leads to better class design.
Identify the primary actions users will perform. For a parking lot: park vehicle, exit vehicle, check availability. Each becomes a method.
Who interacts with the system? Customers, admins, automated systems? Each actor type may need different interfaces.
What are the limits? Max vehicles, supported vehicle types, payment methods. Constraints drive your data structures.
What happens on overflow? Concurrent access? Payment failures? Thinking about edge cases reveals hidden complexity.