Scenario
You are building a backend that helps an ad server decide whether a candidate ad can be delivered (e.g., not over budget / within pacing). The system must track:
-
Impressions (ad view counts)
-
Spend
(money spent attributed to those impressions/clicks/etc.)
Requirements
-
Event collection
: For each ad view, the system should record an event (at least:
ad_id
,
campaign_id
,
user_id
optional,
timestamp
, and fields needed to compute spend).
-
Near real-time decisioning
: When a user requests an ad, the ad server evaluates up to
10,000 candidate ads
and needs current counters (impressions/spend and remaining budget) to filter/score them.
-
Latency
: The ad server request path should be low-latency (assume single-digit to tens of milliseconds for fetching counters).
-
Scale
: High QPS for both event ingestion and read traffic from ad servers.
-
Correctness
: Counters should be accurate enough for budget enforcement; clarify acceptable freshness (e.g., seconds) and consistency model.
Deliverables
Design the end-to-end system:
-
APIs (event ingestion + read APIs for ad server)
-
Data model
-
Storage/streaming components
-
How you serve counters for 10k ads per request efficiently
-
Handling duplicates, retries, and late events
-
Monitoring and failure recovery