The Notification Challenge
Push notifications seem simple until you need to send millions of them reliably. Delivery speed, device token management, rate limiting, and user preferences all matter at scale.
Architecture Overview
[Event Trigger] → [Notification Service] → [Priority Queue] → [Delivery Workers] → [APNs/FCM]Device Token Management
Device tokens change when users reinstall the app or update their OS. We maintain a token registry with automatic cleanup.
class DeviceTokenService {
async registerToken(userId, token, platform) {
await this.db.devices.upsert({
where: { token },
update: { userId, platform, lastSeen: new Date() },
create: { userId, token, platform, lastSeen: new Date() }
});
}
async removeToken(token) {
await this.db.devices.delete({ where: { token } });
}
}Priority Queue System
| Priority | Type | Latency Target |
|---|---|---|
| Critical | Security alerts, 2FA codes | < 1 second |
| High | Order updates, messages | < 5 seconds |
| Normal | Marketing, newsletters | < 30 seconds |
| Low | Weekly digest, recommendations | < 1 hour |
Rate Limiting and Throttling
Prevent notification fatigue by limiting how many notifications each user receives per hour. Different limits apply to different notification types.
Analytics and Delivery Tracking
- Delivery rate tracking (sent vs. delivered)
- Open rate measurement and optimization
- A/B testing notification content and timing
- User preference management and quiet hours
Best Practices
Personalize notifications based on user behavior, not just demographics. Send at the right time for each user's timezone and activity patterns.