Design ad click tracking and dashboard at scale
MetaSoftware Engineer · OnsiteLast updated
This problem tests your ability to design a high-throughput, fault-tolerant ingestion pipeline and an aggregation service for real-time analytics dashboarding.
Problem Statement
Design a distributed system to track ad clicks for a major advertising platform. The system must process millions of click events per second and provide real-time metrics (e.g., clicks per ad, click-through rates) to advertisers via a dashboard.
Functional Requirements
- Ingestion: Capture incoming click events with attributes:
ad_id,user_id,timestamp,geo, anddevice_type. - Aggregation: Provide real-time reporting of click counts, grouped by
ad_idover time windows (e.g., 1-minute, 5-minute, and hourly buckets). - Querying: Advertisers should be able to view current-day metrics with low latency (< 500ms).
Non-Functional Requirements
- Scale: Handle 5 million clicks per second during peak hours.
- Reliability: Ensure minimal data loss (at-least-once delivery is acceptable, but minimize double-counting).
- Consistency: Dashboard counts should be accurate within a few seconds of the actual event.
- Storage: Data must be retained for at least 90 days for historical reporting.
Deliverables
- Provide a high-level system architecture diagram (described in text).
- Define the data model for the ingestion pipeline and the storage layer.
- Explain how you would handle high-volume write traffic and partitioning strategies.
- Address how the system handles late-arriving events or out-of-order data.
Hints
Hint 1
Consider using a distributed message queue like Kafka to buffer incoming events before they are consumed by a stream processing engine.
Hint 2
Think about using a two-tier storage approach: an in-memory OLAP data store for real-time dashboards and a distributed object store or data warehouse for long-term storage.
Hint 3
For massive scale, partitioning your data by `ad_id` allows you to distribute the aggregation load across multiple processing nodes.
Follow-up questions
- How would you identify and filter out fraudulent clicks (e.g., click bots) in real-time without introducing significant latency?
- If the system needs to support 'exactly-once' processing semantics, what specific architectural changes would you implement?
- How would you optimize the dashboard queries if an advertiser wants to see a breakdown by 'geo' and 'device_type' for the last 30 days?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.