Design Google Global Real-time Analytics
Unified metrics across Search, Ads, YouTube — stream processing + batch correction at planetary scale.
Interview tip Lambda architecture: Kafka/Pub/Sub → Flink speed layer + BigQuery batch; mention exactly-once, regional aggregation, global merge.
① Functional requirements
- Collect events from all product surfaces
- Real-time dashboards (last hour)
- Accurate daily reports
- Alerting on anomaly thresholds
- Per-product and global views
- Role-based access to metrics
② Non-functional requirements
- Speed layer latency < 1 minute
- Trillions of events/day
- No double-count in aggregates
- Regional fault isolation
③ Back-of-the-envelope scale
Assumptions
- Trillions events/day
- Flink on Kafka
- BigQuery batch reconcile nightly
④ High-level architecture
Global Analytics
Product event collectors
Pub/Sub global bus
Flink speed layer
BigQuery batch layer
Serving + dashboards
⑤ Data flow & execution path
Event to metric
Event→Regional aggregate→Global merge→Dashboard
Watermarks for late events
Batch layer fixes speed approximations
⑥ API & interfaces
| Endpoint / flow | Purpose | Notes |
|---|---|---|
| POST /events | High-volume ingest | batched |
| GET /metrics | Query API | scoped by product |
⑦ 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
Lambda merge
Dashboard queries sum speed layer (today) + batch tables (history) with documented staleness.
Cardinality control
HyperLogLog for UV; rollups pre-aggregate high-cardinality dimensions.
⑨ Trade-offs & alternatives
| Decision | Option A | Option B | Pick when |
|---|---|---|---|
| Processing | Flink | Spark Streaming | Flink lower latency ops |
| Accuracy | Approximate RT | Exact batch | Standard lambda trade-off |
⑩ 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
- Pub/Sub ingest
- Flink speed
- BigQuery batch
- Lambda merge
- HLL for UV
- Late data