Google SD

Design Google Trends

Aggregate search interest over time — anonymized counts, normalization, and geographic breakdown.

Interview tip Explain scaling counts (0–100 index), spike smoothing, sampling at query time, and batch rollups in warehouse.

① Functional requirements

  • Plot search interest over time
  • Compare multiple terms
  • Geographic breakdown
  • Related queries and topics
  • Export data
  • Anonymize — no raw counts exposed

② Non-functional requirements

  • Query warehouse in seconds
  • Data refreshed daily/hourly
  • Privacy — no individual queries revealed
  • Global scale aggregation

③ Back-of-the-envelope scale

Assumptions
  • Trillions of queries logged
  • Batch rollups to BigQuery
  • Materialized daily cubes

④ High-level architecture

Google Trends
Search log stream
Batch rollup jobs
Trends serving DB
Trends UI API

⑤ Data flow & execution path

Trend computation
Raw logsAnonymize sampleDaily aggregateNormalize 0-100
Lambda: speed layer for today
Batch corrects yesterday

⑥ API & interfaces

Endpoint / flowPurposeNotes
GET /trendsTerm + geo + rangenormalized index
GET /relatedRelated queriesfrom co-occurrence

⑦ 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

Normalization

Scale to max=100 in window — hides absolute volume, preserves shape.

Privacy

Threshold small regions — suppress low volume to prevent re-identification.

⑨ Trade-offs & alternatives

DecisionOption AOption BPick when
FreshnessHourly speedDaily batchHybrid lambda architecture
GranularityCityCountryFine geo risks privacy

⑩ 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

  • Anonymization
  • Normalization 0-100
  • Materialized rollups
  • Privacy thresholds
  • Lambda layers
googletrendsanalytics