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 logs→Anonymize sample→Daily aggregate→Normalize 0-100
Lambda: speed layer for today
Batch corrects yesterday
⑥ API & interfaces
| Endpoint / flow | Purpose | Notes |
|---|---|---|
| GET /trends | Term + geo + range | normalized index |
| GET /related | Related queries | from co-occurrence |
⑦ Data model & storage
Domain-specific entities sharded by user_id or geographic key.
| Store | What | Why |
|---|---|---|
| Distributed store | Primary data | Sharded for scale |
| Kafka / Pub/Sub | Event log | Async pipelines |
| Object store | Media / blobs | GCS-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
| Decision | Option A | Option B | Pick when |
|---|---|---|---|
| Freshness | Hourly speed | Daily batch | Hybrid lambda architecture |
| Granularity | City | Country | Fine geo risks privacy |
⑩ 45-minute interview script
- 0–5 min: Requirements + Google-scale assumptions
- 5–12 min: Back-of-envelope QPS and storage
- 12–22 min: Architecture diagram
- 22–35 min: Deep dive on hot path
- 35–42 min: Failure modes and trade-offs
⑪ Likely follow-up questions
| Question | Short answer |
|---|---|
| How roll out globally? | Regional cells + gradual feature rollout |
⑫ Revision checklist
- Anonymization
- Normalization 0-100
- Materialized rollups
- Privacy thresholds
- Lambda layers