Part 6 of 8 · 2 min read
Extra parts
What makes it a product.
The book lists several extra components.
Notification templates. Many notifications share a layout, such as "your order [number] has shipped". A template is a ready-made notification with places for parameters, styling and tracking links. It keeps the format consistent, reduces mistakes and saves time.
Notification settings. Users who get too many messages feel swamped, so they want fine control. A settings table holds user id, channel (push, email or SMS) and an opt-in flag. Before sending, the server checks whether the user opted in to this kind. This is a hard rule, not a hint, and it also matters for law (Level 9, page 8).
Rate limiting. To avoid overwhelming users, cap how many notifications one user gets in a period. If senders go too far, users turn notifications off altogether. This reuses the limiter of module 1, keyed by user and channel.
Security. Only verified clients should be able to send. For mobile push, an app key and app secret pair secures the API. Without this, anyone could use the system to spam.
Monitoring. The key number is the queue depth, how many notifications are waiting. A large and growing value means workers cannot keep up, so add workers. Also watch send failures per provider, delivery time and retry counts.
Event tracking. Open rate, click rate and engagement show how users react. The notification system sends events to an analytics service at each stage: sent, delivered, opened, clicked.
The updated design. Put it all together: notification servers with authentication and rate limiting; templates and settings in the database and cache; a queue and worker pool for each channel with retry; a notification log; monitoring and event tracking.
A worked example (made up) of settings and limits together. A user opted in to email but not SMS, and has a limit of 3 marketing messages per day. A marketing service sends 5 messages by email and 2 by SMS. The SMS ones are dropped by the opt-out check. Of the 5 emails, 3 pass, and 2 are dropped by the limit. The service gets a clear answer for each.
Common mistake
Sending to the provider straight from the API call. If the provider is slow or down, the caller waits or fails, and a burst overloads the provider. Put a queue between them, and let workers send at a pace the provider can take.
Check yourself: 1. Why check opt-in before every send? 2. What does queue depth tell you? 3. In the example, which checks drop which messages?