A media company sends a weekly newsletter to 5 million subscribers. An editor presses 'send', and every subscriber should get exactly one copy within a few hours. Emails go out through an external email provider that accepts at most 1,000 messages per second per account and sometimes rejects requests or goes down for a few minutes. Subscribers must be able to unsubscribe with one click, and nobody who unsubscribed may receive the next issue. Sends are paced at about 500 emails per second, which leaves headroom under the provider's limit.
Functional requirements
Editors schedule or trigger a send of one issue to all active subscribers
Each subscriber receives exactly one copy of each issue
One-click unsubscribe that takes effect before the next send
Track delivered, bounced and failed emails per issue
Non-functional requirements
An issue reaches all 5 million subscribers within 4 hours
Stay under the provider's rate limit
A provider outage delays emails but never loses or duplicates them
Constraints and scale
5 million subscribers, growing 5% per month
Email provider limit: 1,000 messages per second
Send rate about 500 emails per second
You will practise
Break a large job into queued work items processed by workers
Respect a third party's rate limit and retry with backoff
Make sends idempotent so retries do not create duplicate emails
Show 2 hints
What happens if the process sending emails crashes at subscriber 2,400,000?
How could a retried job know the email was already sent?