Google SD

Design Gmail Fast Search

Search billions of mailboxes — inverted index per user, sharding, and instant query completion.

Interview tip User mailbox shard, inverted index segments, async indexing on delivery, prefix suggest trie + ranking by recency.

① Functional requirements

  • Full-text search in mailbox
  • Filter by sender, label, attachment, date
  • Autocomplete query suggestions
  • Search as you type
  • Snippets with highlights
  • Include spam/trash optional

② Non-functional requirements

  • p99 < 200ms per user search
  • Index new mail within seconds
  • Petabyte total corpus
  • Per-user data isolation

③ Back-of-the-envelope scale

Assumptions
  • 1.5B users
  • Sharding by user_id
  • Average 10GB mailbox index overhead

④ High-level architecture

Gmail Search
Mail delivery
Per-user index shard
Query coordinator
Suggest trie

⑤ Data flow & execution path

Search query
Parse queryRoute user shardIntersect postingsRank + snippet
CDC from mail store to index
Bloom pre-filter spam corpus

⑥ API & interfaces

Endpoint / flowPurposeNotes
GET /mail/searchQuery DSLuser auth
GET /suggestPrefix completecached

⑦ Data model & storage

Domain-specific entities sharded by user_id or geographic key.
StoreWhatWhy
Distributed storePrimary dataSharded for scale
Kafka / Pub/SubEvent logAsync pipelines
Object storeMedia / blobsGCS-style durability

⑧ Deep dive — core components

Per-user sharding

All mail for user_id on same index shard — query never cross-shard fan-out.

Ranking

BM25 + strong recency boost + personal signals (frequent correspondents).

⑨ Trade-offs & alternatives

DecisionOption AOption BPick when
IndexPer-userGlobalPer-user isolates blast radius
SuggestTrieML rankTrie fast; ML for quality

⑩ 45-minute interview script

  1. 0–5 min: Requirements + Google-scale assumptions
  2. 5–12 min: Back-of-envelope QPS and storage
  3. 12–22 min: Architecture diagram
  4. 22–35 min: Deep dive on hot path
  5. 35–42 min: Failure modes and trade-offs

⑪ Likely follow-up questions

QuestionShort answer
How roll out globally?Regional cells + gradual feature rollout

⑫ Revision checklist

  • User shard
  • Inverted index
  • CDC indexing
  • Query DSL
  • Suggest trie
googlegmailsearch