KatInterview

Per-User Impression Limits for an Ad Serving Platform

System DesignModel answer
MediumModel answerSystem Designsystem-designdistributed-systemscounters

Last updated

Design a low-latency service that stops an ad platform from showing a user the same ad or campaign more than an allowed number of times per time window, across regions.

Limit How Often a User Sees an Ad

You are building part of a large advertising platform. Advertisers want to control exposure, so the platform must guarantee that a single user is not shown the same ad (or campaign) more than an allowed number of times in a given period. Example rules:

  • An ad may be shown to a given user at most 3 times per day.
  • A campaign may be shown to a given user at most 10 times per week.

Design the system that enforces these limits.

What your design should cover

  • How the ad server decides, in real time and before serving, whether a candidate ad is still allowed for this user.
  • How impressions are recorded, counted and stored.
  • How to support several scopes of limits: user + ad, user + campaign, user + advertiser, and household-level limits.
  • How to handle high request volume, tight latency and eventual consistency across multiple regions.
  • How to cope with impression events that are late, duplicated or out of order.
  • Retention: expiring old counts, and the trade-off between accuracy and latency.

Assumptions you may use

  • Very high ad-request QPS, with a budget of a few milliseconds per cap check (single-digit ms at p99), and a high-volume impression event stream.
  • Multiple configurable limits per scope over hourly, daily, weekly or rolling windows.
  • Reasonable accuracy is the goal. A small, bounded overshoot is acceptable by default, but a campaign may opt into stricter enforcement.
  • The serving path must remain highly available, and the system runs in several regions.

State any clarifying questions you would ask (for example: calendar vs. rolling windows, strictness, single vs. multi-region, fail-open vs. fail-closed) and the assumptions you pick.

Hints

Hint 1

Separate the two paths: a read-heavy, latency-critical eligibility check at serve time and a write path that records impressions and updates counts. They have different SLAs and can use different tools.

Hint 2

Think about the counter key. It should encode the scope (user, ad, campaign, household) and the window bucket (for example day number), so expiry is just a TTL and old buckets never need cleanup logic.

Hint 3

Strictness is a spectrum. Reading counts from a fast store and incrementing after the impression gives a small overshoot; reserving a slot atomically at decision time gives a tighter bound at higher cost. Match the approach to the campaign's needs.

Hint 4

Make the write path idempotent by keying each impression on a unique event ID, so retries and duplicates do not double-count, and bucket by event time so late events land in the right window.