Question presented to candidate:
"Design an email service like Gmail or Outlook.com for a billion users. People send and receive mail from other providers over the internet, read it in a web and mobile app, search years of mail, and organise it into folders and threads. Walk me through receiving, sending and storing mail."
What a strong answer should cover:
The protocols and their roles: SMTP between servers (inbound and outbound), submission from clients, and IMAP, POP or an HTTP/JSON API (JMAP or a private one) for reading
The outbound path: a durable queue, per-domain delivery workers, handling of SMTP reply classes (2xx done, 4xx retry with backoff, 5xx bounce), a queue lifetime, bounces and a suppression list
Deliverability and trust: SPF, DKIM, DMARC on outbound mail and checks on inbound, spam and malware filtering, IP reputation; the 2024 Gmail and Yahoo bulk-sender rules
Storage: metadata (folders, labels, flags, threads) partitioned by user_id in a wide-column or sharded SQL store, bodies and attachments in blob storage, deduplication of attachments
Threading by Message-ID, In-Reply-To and References, unread counters, and a per-user search index
Worked numbers: send rate, storage per year, and why storage dominates
Clarifying questions expected:
Consumer webmail (Gmail) or a sending platform for businesses (SendGrid)? The design differs a lot.
Which clients must work: IMAP desktop clients, our own apps, or both?
Retention, attachment size limits and search requirements?
Code / implementation expected: Optional โ the examples simulate outbound delivery with retries, bounces and suppression, a DKIM body hash, and mailbox threading and counters.
system-design
case-study
2
Try it yourself
Sketch your approach before you read the solution. That is what the interview tests.
Stuck? Get a hint.
A short nudge toward the approach. It will not give the answer away.
3
Solution
Target Audience: Backend engineers preparing for a "design Gmail" round, and anyone curious how a message actually gets from one mailbox to another.
Difficulty: Hard
Verified with: Node 22.22 and Python 3.12 (identical output for both examples). SMTP reply classes are from RFC 5321; the Postfix default maximal_queue_lifetime of 5 days is from the Postfix queue manager documentation; the bulk-sender rules (more than 5,000 messages a day to Gmail: SPF, DKIM and DMARC, one-click unsubscribe, spam rate under 0.3%) are from Google's sender guidelines as summarised by several deliverability vendors; Gmail's 25 MB attachment limit is from Gmail help pages.
How to read this doc: Every idea is explained in plain language first, then tagged with ๐ Interview term: so you also learn the words an interviewer expects. Every number from the simulations comes from running the exa
The solution is hidden so you can try first
16 min read ยท 15 sections
4
Read the code
Outbound delivery: SMTP 2xx/4xx/5xx handling, exponential retry, a 5-day queue lifetime, suppression and the DKIM body hash