| Users | Notifications/Day | System Changes |
|---|---|---|
| 100 | ~1,000 | Single server handles all; simple DB writes; no queue needed |
| 10,000 | ~100,000 | Introduce message queue; DB indexing; basic caching; multiple app instances |
| 1,000,000 | ~10,000,000 | Horizontal scaling of app servers; distributed queue; read replicas; CDN for media |
| 100,000,000 | ~1,000,000,000 | Sharded databases; multi-region deployment; advanced caching layers; push notification services |
Notification system in LLD - Scalability & System Analysis
At small to medium scale, the database is the first bottleneck. Writing and reading notification data for millions of users causes high load. The DB struggles with many writes and queries per second.
- Database: Use read replicas to spread read load; implement write queues to smooth writes; shard data by user ID.
- Application Servers: Horizontally scale by adding more servers behind load balancers.
- Message Queue: Use distributed queues (e.g., Kafka) to handle high notification throughput.
- Caching: Cache frequent notification metadata in Redis or similar to reduce DB hits.
- CDN: Use CDN to serve notification media (images, videos) efficiently.
- Push Services: Integrate with platform push notification services (APNs, FCM) for mobile delivery.
- At 1M users sending 10 notifications/day: ~10M notifications/day ≈ 115 notifications/sec.
- Database: Needs to handle ~200 QPS (writes + reads), requiring replicas and indexing.
- Message Queue: Must support 100-200 messages/sec throughput.
- Bandwidth: Assuming 10KB per notification payload, ~100 GB/day (~1.15 MB/sec avg, ~13 MB/sec peak).
- Storage: Storing notifications for 30 days -> 300M notifications ≈ 3TB assuming 10KB each.
Start by clarifying notification types and delivery methods. Discuss user scale and traffic patterns. Identify bottlenecks like DB writes or push service limits. Propose incremental scaling steps: queues, caching, sharding. Always justify why each solution fits the bottleneck.
Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first?
Answer: Introduce read replicas and write queues to distribute load and smooth writes before scaling app servers.
Practice
Solution
Step 1: Understand the role of event producers
Event producers create or detect events that require notifying users, such as a new message or alert.Step 2: Differentiate from other components
Notification service processes events, delivery channels send notifications, and user preferences store user settings.Final Answer:
Event Producer -> Option DQuick Check:
Event source = Event Producer [OK]
- Confusing notification service with event producer
- Thinking delivery channel generates events
- Assuming user preferences create events
Solution
Step 1: Identify the logical flow of notification
First, an event is generated by the event producer, then processed by the notification service, and finally sent via the delivery channel.Step 2: Eliminate incorrect sequences
Delivery channel cannot start the process; user preferences store is not part of the sending sequence.Final Answer:
Event Producer -> Notification Service -> Delivery Channel -> Option BQuick Check:
Event -> Process -> Send = A [OK]
- Reversing the order of components
- Including user preferences in the sending chain
- Confusing delivery channel as event source
Solution
Step 1: Understand user preference handling
If a user selects multiple delivery channels, the system should send notifications through all preferred channels to ensure delivery.Step 2: Confirm expected multi-channel delivery
Sending via both email and SMS respects user choice and increases notification reach.Final Answer:
Send notification via both email and SMS -> Option AQuick Check:
Multiple preferences = multiple channels [OK]
- Sending notification on only one channel
- Ignoring user preferences
- Not sending notification at all
Solution
Step 1: Analyze queue role in notification system
Queue buffers events to handle load. If overloaded, it causes delays in processing notifications.Step 2: Evaluate other options
Missing user preferences or instant delivery does not cause delay; too few events would reduce load, not increase delay.Final Answer:
Queue is overloaded with too many events -> Option AQuick Check:
Queue overload = delay [OK]
- Blaming delivery channel for delays
- Assuming missing preferences cause delay
- Thinking fewer events cause delays
Solution
Step 1: Consider scalability requirements
Millions of users require distributed services and sharded queues to handle load without bottlenecks.Step 2: Address user customization needs
Dynamic delivery channel selection per user allows personalized notifications respecting preferences.Step 3: Evaluate other options
Centralized service and single queue create bottlenecks; synchronous sending blocks processing; local files do not scale or support dynamic preferences.Final Answer:
Implement distributed notification services with sharded queues and dynamic delivery channel selection per user -> Option CQuick Check:
Distributed + dynamic preferences = scalable & customizable [OK]
- Choosing centralized design causing bottlenecks
- Using synchronous sending blocking system
- Storing preferences in non-scalable local files
Ready to prove it?
Pass the test and this pattern moves unknown
