News · New this week
Gmail system design: email delivery and spam detection
MX lookup, SMTP, SPF, DKIM, spam filter, mail store and push, in the order an interviewer expects to hear them.
Riya's offer letter lands in spam and a lottery mail lands in the inbox. Then the interviewer says, "design a Gmail-like app." This is the standard interview answer, not Gmail's own system.
Why the obvious answer fails
The common first answer is to write each mail to a database and have the app ask for new mail every minute. Reject it. It breaks down at millions of mails.
A better design starts from three needs. Mail must not get lost. Fake mail must be stopped. The phone must find out right away.
From sender to inbox
Think of it as a pipeline, one stage after another.
MX lookup and SMTP. The sender's server checks the MX record, which works like a phonebook entry that says where your mail server is. Then it sends the mail over SMTP, the internet's way of sending mail.
Auth check. This is how you catch a fake sender. SPF asks whether the sending server is on that domain's list. DKIM asks whether the digital seal on the mail is genuine.
Spam filter. The filter gives a score based on content and reputation. Reputation is the sender's past record. A high score sends the mail to the spam folder.
One "Not spam" click is a small signal. The filter learns because millions of users send signals like it.
Mail store. The mail is saved, and an index is saved with it. An index is like the contents page of a book, so search can find things right away.
Push. The server tells the phone about the new mail. The phone doesn't ask. That's why the app doesn't need to check every minute.
When the filter is slow
At peak load the spam filter can slow down. The mail waits, but it isn't lost. The sender retries later.
This matters in an interview. Lost mail is the worst failure here, so the design lets mail be late and doesn't let it vanish. Retry is the answer to "what happens under load."
How to say it in the room
You can compress the whole design into one line. MX tells you where to deliver. SPF and DKIM tell you who sent it. The filter sorts the mail. Push delivers the news.
Each stage has one job, and you can explain why it sits where it does. Auth comes before the filter, so a fake sender is caught before content scoring. Storage and indexing come after the filter, and push comes last, once the mail is saved.
Next time you practise this design, say the five stages out loud in order, then add the retry story for a slow filter. If you can do that in a minute, you're ready.



