Week 8 Day 4: Interview Walkthrough - Design a Notification Service
Interviewer (I): “Design a notification service that sends Emails and Push Notifications.”
Phase 1: Clarify
You: “Is this real-time? How many notifications?” I: “Real-time. 10M notifications/day.” You: “Do we need retry logic?” I: “Yes.”
Phase 2: High Level
You: “I propose:
- Notification Service: Accepts request.
- Message Queue (Kafka): Decouples intake from sending.
- Workers: Email Worker, Push Worker.
- Third Party integrations: SendGrid (Email), APNS/FCM (Push).”
I: “Looks good. How do you prevent duplicate emails?”
Phase 3: Deep Dive (Deduplication)
You: “We need a Distributed Lock or a Dedup Cache.
Before adding to Queue, we check Redis: SET notification:{userId}:{type} NX EX 60.
If it exists, we drop the request. This prevents spamming the user within 60s.”
I: “What if SendGrid is down?” You: “The Worker catches the error. It places the job into a Retry Queue with exponential backoff (retry in 1m, 2m, 4m).”
Phase 4: Wrap Up
You: “To monitor, we track ‘Delivery Rate’ and ‘Queue Lag’ in Grafana.”
I: “Great job.”
Tomorrow: Final Project. A real-time chat app! 💬