Scaling Notification Systems
Scaling notifications is not just "add more servers." More workers can overload providers. More queues can complicate ordering. More database writes can create hot partitions. Scaling is controlled pressure management.
Baseline Capacity Math
If one worker safely handles 25 jobs/second, you need at least 23 workers before headroom.
Horizontal Worker Scaling
Parallel branches
Fan-outWorkers should be stateless. State belongs in the database, queue, cache, or provider.
Priority Isolation
This prevents campaigns from delaying OTP and fraud alerts.
Database Scaling
Hot tables:
Use indexes for common queries, partition large append-heavy tables, and archive old delivery attempts.
CREATE INDEX notifications_tenant_status_created_idx
ON notifications (tenant_id, status, created_at);
For multi-tenant SaaS, tenant-aware indexes are often essential.
Caching
Cache stable reads:
Redis is common, but cache invalidation matters. When a user unsubscribes, preference cache must expire or be invalidated.
Provider Rate Limits
If SendGrid allows 10,000 requests/minute, scaling workers to 100,000 sends/minute creates failures. Rate limit before the provider.
await rateLimiter.consume(`provider:sendgrid`, 1);
await sendgrid.send(email);
Provider Failover
Failover should be selective. Sending every marketing email through backup can be expensive and may hurt reputation.
Regional Deployment
For global products, region matters:
Regional routing can reduce latency, cost, and compliance risk.
Scaling without throttling can turn a provider limit into a failure storm.
Common Mistakes
- Scaling workers without provider rate limits.
- Mixing marketing and security traffic.
- No database archiving plan.
- Cache invalidation missing for preferences.
- Assuming one provider works equally well in every country.
Interview Questions
- How would you estimate worker count?
- Why separate queues by priority?
- How do provider rate limits affect scaling?
- When would you use regional routing?
Exercise
Calculate workers needed for 5 million notifications/day with 1.8 channel jobs each and each worker processing 20 jobs/second.
What you will learn
How to scale workers and queues horizontally.
How sharding and partitioning affect throughput.
How caching reduces preference and template load.
How provider failover and regional routing improve resilience.
Production checklist
- Workers scale independently
- Priority queues are separated
- Database hot queries are indexed
- Preferences and templates are cached
- Provider failover exists
- Regional needs are understood