linkjobai revisou este gist 5 days ago. Ir para a revisão
1 file changed, 36 insertions
notify.md(arquivo criado)
| @@ -0,0 +1,36 @@ | |||
| 1 | + | # System Design: A Notification Service (Push, Email, SMS) | |
| 2 | + | ||
| 3 | + | "Design a notification system" tests queues, fan-out, retries and user preferences, all common follow-up areas. | |
| 4 | + | ||
| 5 | + | ## Requirements | |
| 6 | + | ||
| 7 | + | - Send push, email and SMS notifications, triggered by other services or scheduled campaigns. | |
| 8 | + | - Respect user preferences, opt-outs and quiet hours. | |
| 9 | + | - At-least-once delivery, with idempotency so users don't get duplicates. | |
| 10 | + | - Scale example: 10M notifications a day, with bursts during campaigns. | |
| 11 | + | ||
| 12 | + | ## High-level flow | |
| 13 | + | ||
| 14 | + | 1. **Notification API:** producers call `POST /notify {user_id, template, data, priority}`. | |
| 15 | + | 2. **Validation and preferences:** check opt-outs, rate limits per user, and quiet hours. | |
| 16 | + | 3. **Message queue per channel** (Kafka or SQS): separate queues so a slow SMS provider doesn't block push. | |
| 17 | + | 4. **Channel workers:** render the template and call the provider (APNs, FCM, an email service, an SMS gateway). | |
| 18 | + | 5. **Delivery log:** store status per message for retries, analytics and support. | |
| 19 | + | ||
| 20 | + | ## Reliability details | |
| 21 | + | ||
| 22 | + | - **Retries** with exponential backoff and a dead-letter queue for permanent failures. | |
| 23 | + | - **Idempotency key** per notification so a retried job doesn't send twice. | |
| 24 | + | - **Priority lanes:** one-time passwords must not wait behind a marketing blast. | |
| 25 | + | - **Provider failover:** keep a second SMS or email vendor ready. | |
| 26 | + | ||
| 27 | + | ## Data model | |
| 28 | + | ||
| 29 | + | `users_devices(user_id, device_token, platform)`, `preferences(user_id, channel, enabled, quiet_hours)`, `notifications(id, user_id, channel, status, created_at)`. | |
| 30 | + | ||
| 31 | + | ## Good extras | |
| 32 | + | ||
| 33 | + | Template versioning, per-tenant throttling, tracking opens and clicks for email, and batching low-priority messages into digests. | |
| 34 | + | ||
| 35 | + | --- | |
| 36 | + | *Disclosure: I work on [Linkjob AI](https://www.linkjob.ai/), an AI interview assistant. This is general prep material.* | |
Próximo
Anterior