| Scale | Users | Notifications/Second | System Changes |
|---|---|---|---|
| Small | 100 | 10-50 | Single server handles notification dispatch; simple queue; direct DB writes |
| Medium | 10,000 | 1,000-5,000 | Introduce message queue (e.g., Kafka); use worker pool; caching user preferences |
| Large | 1,000,000 | 100,000+ | Multiple distributed queues; microservices for notification types; horizontal scaling; CDN for push notifications |
| Very Large | 100,000,000 | 10,000,000+ | Global distributed system; sharded databases; multi-region queues; edge computing; advanced rate limiting |
Notification to all parties in LLD - Scalability & System Analysis
Start learning this pattern below
Jump into concepts and practice - no test required
The first bottleneck is the message queue and notification dispatch system. As user count and notification volume grow, the queue can become overwhelmed, causing delays. Also, the database storing notification status can become a bottleneck due to high write/read load.
- Horizontal scaling: Add more worker servers to process notifications concurrently.
- Message queue partitioning: Use multiple partitions or topics to distribute load.
- Caching: Cache user notification preferences to reduce DB hits.
- Sharding: Split notification data by user ID ranges or regions.
- CDN and push services: Use content delivery networks and push notification services to offload delivery.
- Rate limiting and batching: Control notification bursts and batch notifications to reduce load.
At 1 million users sending 100,000 notifications per second:
- Requests per second: ~100,000 (notification dispatch calls)
- Storage: Assuming 1 KB per notification record, 100,000 notifications/sec = ~100 MB/sec = ~8.6 TB/day
- Network bandwidth: 100,000 notifications * 1 KB = ~100 MB/s (800 Mbps), requires high bandwidth servers and network infrastructure
Start by clarifying notification types and delivery guarantees. Discuss expected user scale and notification volume. Identify bottlenecks early (queue, DB, network). Propose incremental scaling steps: caching, horizontal scaling, sharding. Mention trade-offs like latency vs cost. Use real numbers to justify design choices.
Your database handles 1000 QPS for notification status updates. Traffic grows 10x to 10,000 QPS. What do you do first?
Answer: Introduce read replicas and caching to reduce DB load, and consider sharding notification data to distribute writes. Also, optimize notification processing to reduce unnecessary DB writes.
Practice
What is the main purpose of a notification system that sends messages to all parties?
Solution
Step 1: Understand the role of notifications
Notifications are designed to deliver messages to users or parties quickly and efficiently.Step 2: Identify the main goal
The main goal is to share important information with all involved parties without delay.Final Answer:
To quickly share important messages with everyone involved -> Option AQuick Check:
Notification purpose = quick message sharing [OK]
- Confusing notifications with data storage
- Thinking notifications perform data processing
- Assuming notifications create user profiles
Which of the following is the correct way to represent a notification service that sends messages to all parties in pseudocode?
function notifyAll(parties, message) {
for (let i = 0; i < parties.length; i++) {
parties[i].send(message);
}
}Solution
Step 1: Analyze the pseudocode loop
The code loops through each party in the parties list using a for loop.Step 2: Check the send method call
Inside the loop, it calls send(message) on each party, ensuring all get notified.Final Answer:
Loop through parties and call send(message) on each -> Option CQuick Check:
Loop + send call = notify all [OK]
- Sending message only once
- Not looping through all parties
- Calling send outside the loop
Consider this code snippet for notifying parties:
parties = ["Alice", "Bob", "Charlie"]
function notifyAll(parties, message) {
let notified = []
for (const person of parties) {
notified.push(person + ": " + message)
}
return notified
}
console.log(notifyAll(parties, "Meeting at 5 PM"))What will be the output?
Solution
Step 1: Understand the loop behavior
The function loops over each person in parties and creates a string combining their name and the message.Step 2: Check the returned list
The notified list contains strings like "Alice: Meeting at 5 PM" for each party.Final Answer:
["Alice: Meeting at 5 PM", "Bob: Meeting at 5 PM", "Charlie: Meeting at 5 PM"] -> Option AQuick Check:
Loop + string concat = list of personalized messages [OK]
- Returning only messages without names
- Returning original party list
- Assuming function is undefined
Identify the bug in this notification function and select the fix:
function notifyAll(parties, message) {
for (let i = 0; i < parties.length; i++) {
parties.send(message)
}
}Solution
Step 1: Identify incorrect method call
The code calls send on the entire parties array instead of individual party objects.Step 2: Fix by indexing the array
Use parties[i].send(message) to call send on each party in the loop.Final Answer:
Changeparties.send(message)toparties[i].send(message)-> Option DQuick Check:
Call send on each party object [OK]
- Calling send on the whole array
- Using wrong loop condition
- Adding unnecessary return inside loop
You are designing a notification system to alert all parties involved in a project. Which design choice best ensures scalability and reliability?
- A. Use a single server to send notifications sequentially to all parties.
- B. Send notifications only to a random subset of parties to reduce load.
- C. Store all notifications in a database and send them manually when needed.
- D. Use a message queue to distribute notification tasks to multiple worker servers.
Solution
Step 1: Evaluate single server approach
Sending sequentially from one server limits scalability and can cause delays or failures.Step 2: Consider message queue with workers
Using a message queue allows distributing notification tasks to multiple workers, improving scalability and reliability.Step 3: Assess other options
Storing notifications for manual sending is slow; sending to random subset misses parties.Final Answer:
Message queue with multiple workers -> Option BQuick Check:
Queue + workers = scalable, reliable notifications [OK]
- Relying on single server for all notifications
- Sending notifications manually
- Skipping parties to reduce load
