System Design LabSystem Design QuestionsDesign Email Service (Gmail)

Design Email Service (Gmail)

MediumMessaging Systemsmessagingstoragesearchsecuritydistributed🔵 Google

Question Overview

Design an email service like Gmail that sends and receives mail over SMTP for hundreds of millions of daily users. The core challenges are never losing an accepted message, storing petabytes of mail and attachments per day, per-user search and threading, and filtering spam before it reaches the inbox.…

Sign up to see the full question and AI interviewer

Requirements

  • Send and receive mail with any internet domain over SMTP, with attachments up to 25 MB
  • Durable delivery: acknowledge inbound mail only after it is replicated, and retry outbound mail until delivered or bounced
  • Conversation threading, labels, and read/starred state kept in sync across web, mobile, and IMAP clients
  • Full-text search over a user's own mailbox with results in under 500 ms
  • Spam and phishing filtering on inbound mail, improved by user reports
  • Listing and opening mail within 200 ms at p99 with 99.99% read availability

Back-of-the-envelope numbers

  • Inbound deliveries: 500M DAU × 40 emails/day = 20B/day ÷ 86,400 s ≈ 231K/s average, ~700K/s at 3× peak
  • Sends: 500M × 10 = 5B/day ÷ 86,400 s ≈ 58K/s average, ~175K/s at peak, each fanning out to one or more mailboxes
  • Reads: 500M × 20 = 10B/day ÷ 86,400 s ≈ 116K/s average, ~350K/s at peak, mostly mailbox list and message open calls
  • Body storage: 20B × 50 KB = 1 PB/day ≈ 365 PB/year before compression and deduplication of messages sent to many recipients
  • Attachments: 20% × 20B = 4B/day × 500 KB = 2 PB/day ≈ 730 PB/year, stored once per unique content hash
  • Per user: 40 × 50 KB + 8 × 500 KB = 6 MB/day ≈ 2.2 GB/year, so an active user reaches the 15 GB quota in about 7 years
  • Search index: at roughly 25% of body size ≈ 250 TB/day of new index data, partitioned by user_id so each query hits one shard

Key components

  • Inbound MTA fleet behind MX records: TLS, SPF, DKIM, and DMARC checks, replying 250 OK only after the message is durably queued
  • Spam and phishing classifier scoring sender reputation, content, and links, filing suspects under a Spam label and learning from user reports
  • Mailbox store sharded by user_id holding metadata, thread_id, labels, and flags; bodies and attachments live in content-addressed blob storage
  • Threading service grouping messages by Message-ID, In-Reply-To, and References headers, with normalized subject and participants as a fallback
  • Per-user inverted search index built asynchronously from the mailbox change stream, so indexing never slows delivery
  • Sync service with a per-mailbox change log and increasing modification sequence, so clients fetch only deltas and receive push notifications
  • Outbound MTA with a persistent retry queue, exponential backoff over days, DKIM signing, bounce handling, and monitored sending IP pools

Common mistakes

  • Acknowledging SMTP DATA before the message is replicated, so a crash loses mail the sending server believes was delivered
  • Storing attachments and large HTML bodies inline in the mailbox database, bloating the hot metadata store
  • Building one global search index across all users when every query is scoped to a single mailbox and should hit one shard
  • Threading by subject alone, which merges unrelated messages titled Hello and splits threads when someone edits the subject
  • Copying a message body per recipient for large mailing lists instead of storing it once and referencing it from each mailbox
  • Silently dropping suspected spam instead of filing it in a Spam folder, making false positives unrecoverable
  • Treating outbound delivery as synchronous even though remote servers can be unavailable for hours and need retries

Likely follow-ups

  • How would you deliver one message to a 100,000-member mailing list hosted on your service?
  • How do you keep IMAP UIDs and flags consistent when web and desktop clients change the same mailbox concurrently?
  • How would you protect your sending IP reputation if a compromised account starts sending spam?
  • How would you implement undo send and scheduled send?
  • How would you make text inside PDF and document attachments searchable?
  • How would you move a user's mailbox to another region without downtime or lost mail?

No community solutions yet

Be the first to publish your solution

Practice ‘Design Email Service (Gmail)’ with an AI Interviewer

Get scored feedback on your diagram, scalability approach, and trade-offs. Free while we grow — up to 3 full interviews a day.