Labs

System lab · medium · 28 min

Gmail: Email

Accept, store, search and deliver mail without losing any of it.

Email is old, boring and everywhere. People keep receipts, contracts, medical reports and fifteen years of their life in it. They forgive a slow search. They don't forgive a lost message.

In this lab you'll design an email service like Gmail from a blank page: accept mail from the internet, store it forever, show an inbox fast, search it, and send mail out. The hard requirement is in the summary: never lose a message.

The brief

Every user has a mailbox. Mail arrives from other mail servers across the internet using SMTP, a protocol from 1982 that every mail system still speaks. Users read, label, archive, search and send from a web or mobile app.

Who uses it:

  • People reading and writing email, on web and phone.
  • Other mail servers sending us mail for our users, and receiving mail our users send.
  • Bulk senders like shops and banks sending millions of newsletters and alerts.

For this lab:

  • In: receiving and sending mail, storing mailboxes, threads and labels, the inbox view, full-text search, a spam filter as a box in the pipeline.
  • Out: calendar, chat, ads, attachment previews, how the spam model itself works.

Requirements

Functional

  • Receive mail for our users from any mail server on the internet.
  • Users see their inbox, grouped into threads, with labels.
  • Users can search all their mail by words, sender, date and label.
  • Users can send mail, with attachments, to anyone.
  • Spam goes to a spam folder, not the inbox.

Non-functional

  • Once we've accepted a message, it is never lost. Not by a crashed server, a full disk, a bad deploy or a lost data centre.
  • New mail appears in the inbox within a few seconds of arriving.
  • The inbox loads in under 500 ms. Search returns in under 1 second.
  • 15 GB of storage per user, kept forever unless they delete it.
  • Highly available for reading. Accepting new mail can briefly slow down, because SMTP senders retry (we'll use that).