What if you could tell millions about your news with just one click, perfectly every time?
Why Design a notification system in HLD? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you run a small online store and want to tell your customers about new deals. You try sending emails or messages one by one, copying and pasting each time.
It feels like shouting in a crowded room, hoping the right people hear you.
Sending notifications manually is slow and tiring. You might forget someone or send the wrong message. It's hard to keep track of who got what and when.
This causes unhappy customers and lost sales.
A notification system automates sending messages to many users at once. It organizes who should get what and when, making sure no one is missed.
This system can send emails, texts, or app alerts quickly and reliably.
for user in users: send_email(user.email, 'Sale today!')
notification_service.send('Sale today!', users)With a notification system, you can reach thousands instantly, keeping customers informed and engaged without extra effort.
Social media apps use notification systems to alert you about likes, comments, or messages right away, so you never miss important updates.
Manual notifications are slow and error-prone.
A notification system automates and scales message delivery.
This keeps users informed and improves engagement effortlessly.
Practice
Solution
Step 1: Understand the role of event processor
The event processor detects events that trigger notifications, deciding when a message should be sent.Step 2: Differentiate from other components
The notification sender delivers messages, user preference manager stores user choices, and message storage keeps records.Final Answer:
Event processor -> Option AQuick Check:
Event detection = Event processor [OK]
- Confusing sender with event detector
- Thinking user preferences trigger events
- Assuming storage decides timing
Solution
Step 1: Identify quick lookup needs
User preferences require fast access by user ID or key, so a data structure with O(1) average lookup is ideal.Step 2: Match data structures to lookup speed
Hash maps provide constant time lookup, unlike linked lists, queues, or stacks which are slower for direct access.Final Answer:
Hash map -> Option BQuick Check:
Fast key-value access = Hash map [OK]
- Choosing linked list which is slow for lookup
- Confusing queue or stack with lookup structures
- Ignoring key-based access needs
Solution
Step 1: Understand queue capacity limits
Queues have fixed or limited size; when full, they cannot accept new items immediately.Step 2: Identify common handling of full queues
Systems usually drop new notifications or delay them until space frees up; automatic unlimited expansion is rare to avoid resource exhaustion.Final Answer:
New notifications are dropped or delayed -> Option DQuick Check:
Full queue = drop or delay new notifications [OK]
- Assuming infinite queue size
- Thinking notifications bypass queue
- Believing system crashes on full queue
Solution
Step 1: Analyze duplicate message causes
Duplicates often occur if the system processes the same event multiple times without checking if notification was already sent.Step 2: Evaluate other options
Missing user preferences or synchronous sending do not cause duplicates; a single queue can still handle duplicates if deduplication exists.Final Answer:
No deduplication in event processing -> Option CQuick Check:
Duplicates = missing deduplication [OK]
- Blaming user preferences for duplicates
- Confusing synchronous sending with duplication
- Assuming single queue causes duplicates
Solution
Step 1: Identify scalability and multi-channel needs
Supporting multiple notification types and scaling requires decoupling components and asynchronous processing.Step 2: Match architecture patterns
Event-driven microservices with message queues allow independent scaling, handle user preferences, and support multiple channels efficiently.Step 3: Eliminate unsuitable options
Monolithic apps limit scalability; polling causes delays; batch processing is too slow for timely notifications.Final Answer:
Event-driven microservices with message queues and preference service -> Option AQuick Check:
Scalable multi-channel = event-driven microservices [OK]
- Choosing monolithic for scalability
- Using batch processing for real-time needs
- Relying on polling causing delays
