Design a real-time ad frequency capping system for an ads platform.
When the ad server is deciding whether to show an ad, it must enforce caps such as:
-
Per user
per campaign
: at most
K
impressions in the last
T
hours (rolling window).
-
Optional: per user per advertiser, per user per creative, etc.
Requirements:
-
Very low latency on the serving path (single-digit ms budget).
-
Very high QPS (millions/sec) and large cardinality (users × campaigns).
-
Events are generated on every impression and may arrive late/out of order.
-
Define what consistency you need (strict vs best-effort) and justify tradeoffs.
-
Support multiple time windows (e.g., 1 hour, 24 hours, 7 days).
-
Provide APIs for: (1) check-and-reserve (decision time) and (2) impression logging.
Explain data model, storage choices, write/read paths, deduplication, TTL/expiry, sharding strategy, and how you monitor/alert on correctness and system health.