Design Gmail
Understanding the Problem
✉️ What is Gmail? Gmail is an email service: a mailbox per user, a web and mobile client to read and write mail, and a mail server that exchanges messages with every other email provider on the internet over SMTP. Mail is grouped into conversations, organized with labels instead of folders, and searchable across years of history.
A common variant is "design a temporary email service" (10 Minute Mail, temp-mail): anyone gets a random address without signing up, can receive mail at it for a while, and then the inbox and everything in it disappears. It reuses the receiving half of Gmail with no accounts and a hard TTL on all data. We'll design Gmail first and cover the temp-mail inbox as a deep dive.
Functional Requirements
Core Requirements
- Users should be able to send email, with attachments, to anyone on any email provider.
- Users should be able to receive email from anyone and see new mail appear in their inbox within seconds.
- Users should be able to organize mail with labels (including Inbox, Sent, Archive and Trash) and view it as conversations.
- Users should be able to search their mail by words, sender, date, label and attachments.
Below the line (out of scope)
- Building the spam classifier itself (we'll show where it plugs in).
- Contacts, calendar, chat and smart features like auto-replies.
- IMAP/POP access for third-party clients, beyond noting it reads the same storage.
Non-Functional Requirements
Ask your interviewer for scale. For our design: 1B users, 500M daily active, each receiving about 40 messages per day and sending about 5.
Core Requirements
- Once we accept a message (inbound or outbound), we must never lose it.
- New mail should show up in the recipient's client within a few seconds of our server accepting it.
- Opening the inbox or a thread should take under ~300 ms; search results should return in under a second.
- The system should be highly available. Email is asynchronous, so a brief delay is tolerable, but losing a message or bouncing valid mail isn't.
- Storage must scale to many GB per user, for years, at reasonable cost.
Below the line (out of scope)
- Strong cross-device consistency for read/unread flags. A second of lag between devices is fine.
Back of the envelope. 500M users × 40 messages is 20B inbound messages per day, about 230,000 per second on average and roughly double that at peak. Messages average maybe 75 KB including attachments (most are a few KB of text; a few carry megabytes), so that's around 1.5 PB of new mail per day. Over years, with users keeping everything, total storage reaches the exabyte range.
The insight: almost everything in email is scoped to one mailbox. Reading, labeling and searching never look across users. That means we can partition storage and even the search index by user, and every query hits one partition. The only cross-user parts are message delivery and shared attachment bytes.