Medium · 12 steps · ~70 min
Design an email service
Send, receive, search, and never lose a message.
People search mailboxes constantly and expect every message to be stored safely. Incoming mail arrives in bursts.
Same problem as GmailOutlookProton Mail
How it works
- Receive: accept mail fast, store it, index it for search.
- Search: query an index instead of scanning every message.
What you'll build
- The API and the data behind it
- A server, a database and a search index
- A queue and workers that absorb a newsletter burst
- A rate limiter against a spam flood
- A design that survives a cold cache, a lost index node and a lost primary
Steps
- 1Design the API
- 2Design the data model
- 3Handle 500 requests/sec
- 4Handle 5,000 requests/sec for $1,000 a month
- 5Handle 25,000 requests/sec
- 6Absorb a 50,000 requests/sec mail burst
- 7Survive a spam flood on a budget
- 8Survive a cache restart
- 9Lose a search node
- 10Lose the primary database
- 11Mail is missing from search
- 12Deep dive: duplicate deliveries