Design an ad click event aggregation system for real-time reporting and billing

Quick Overview

Design a system that ingests a continuous stream of ad impressions and clicks, aggregates them over minute, hour and day windows, and feeds both advertiser dashboards and billing. It tests how you count each click exactly once, handle late events, keep dashboard queries fast at high volume, and remove fraudulent clicks before they are billed.

Design an ad click event aggregation system for real-time reporting and billing

Role: Software Engineer

Category: System Design

Difficulty: hard

Interview Round: Other

Design a system that ingests a massive, continuous stream of ad impressions and clicks and aggregates them for real-time reporting and for billing advertisers. Functional requirements: 1. Track ad impressions and clicks sent by client applications (mobile apps and web browsers). 2. Aggregate events in real time by several dimensions, over minute, hour and day windows. 3. Let advertisers view dashboards and query performance metrics with dynamic filtering and grouping. 4. Identify and discard invalid or bot-generated clicks before they affect billing. Define the non-functional requirements yourself, with concrete targets, for example an availability figure for ingestion and a latency budget for dashboard queries. After the high-level design, expect the interviewer to go deeper on four topics: counting each click exactly once, handling events that arrive late, answering dashboard queries in under a second, and detecting and reversing click fraud. ```hint Retries A mobile client that loses the HTTP response sends the same click again. Decide what lets every later stage recognize it as the same click, then check that your answer still holds when a stream worker crashes and replays its input. ``` ```hint Which clock A click recorded on a phone in a subway tunnel can reach the server 15 minutes after it happened. Decide which timestamp puts it in a window, and how long a window that has already reported can still change. ``` ```hint Fast numbers and final numbers Dashboards want counts within seconds. Invoices want counts that are exactly right, even if they take hours. Ask whether one pipeline has to deliver both. ``` ### Clarifying Questions to Ask - What peak event rate must ingestion sustain, and how large are the spikes during big live events or when an ad goes viral? - Are advertisers billed per click, per impression or both, and is the bill computed from the real-time counts or from a later final count? - How fresh must dashboard numbers be, and may they change after the fact when late or fraudulent events are found? - How long can a client hold events offline before it sends them? - How long must raw events be kept for audits and reprocessing? ### What a Strong Answer Covers - Concrete non-functional targets backed by estimates (event rate, data volume per day, size of any per-event state), and which parts of the system favor availability and which need strong consistency. - A path from the client to the dashboard and to the billing ledger, with a reason for each data store and an explanation of how dashboard queries stay fast at this volume. - A deduplication scheme that survives both client retries and worker crash recovery, including where its state lives and how long it is kept. - Event-time windowing: how a window is declared complete, what happens to late events, and how corrected counts reach the dashboard without double counting. - Fraud filtering at more than one time scale, and how fraud found after the fact is removed from dashboards and bills. ### Follow-up Questions - One ad goes viral and most clicks share a single `ad_id`. Where does the load concentrate, and how do you spread it without breaking the counts? - A bug inflated yesterday's counts. How do you recompute the day and replace the stored aggregates without double counting? - Spend totals reach the dashboard minutes late. How do you stop a campaign from running far past its daily budget? - Clicks arrive in several regions. How do you keep latency low for clients and still count each click once?

Overview: Design a system that ingests a continuous stream of ad impressions and clicks, aggregates them over minute, hour and day windows, and feeds both advertiser dashboards and billing. It tests how you count each click exactly once, handle late events, keep dashboard queries fast at high volume, and remove fraudulent clicks before they are billed.

General logo
General
Nov 24, 2026
hardSoftware EngineerOtherSystem Design
0
0

Design a system that ingests a massive, continuous stream of ad impressions and clicks and aggregates them for real-time reporting and for billing advertisers.

Functional requirements:

  1. Track ad impressions and clicks sent by client applications (mobile apps and web browsers).
  2. Aggregate events in real time by several dimensions, over minute, hour and day windows.
  3. Let advertisers view dashboards and query performance metrics with dynamic filtering and grouping.
  4. Identify and discard invalid or bot-generated clicks before they affect billing.

Define the non-functional requirements yourself, with concrete targets, for example an availability figure for ingestion and a latency budget for dashboard queries.

After the high-level design, expect the interviewer to go deeper on four topics: counting each click exactly once, handling events that arrive late, answering dashboard queries in under a second, and detecting and reversing click fraud.

Clarifying Questions to Ask Guidance

  • What peak event rate must ingestion sustain, and how large are the spikes during big live events or when an ad goes viral?
  • Are advertisers billed per click, per impression or both, and is the bill computed from the real-time counts or from a later final count?
  • How fresh must dashboard numbers be, and may they change after the fact when late or fraudulent events are found?
  • How long can a client hold events offline before it sends them?
  • How long must raw events be kept for audits and reprocessing?

What a Strong Answer Covers Guidance

  • Concrete non-functional targets backed by estimates (event rate, data volume per day, size of any per-event state), and which parts of the system favor availability and which need strong consistency.
  • A path from the client to the dashboard and to the billing ledger, with a reason for each data store and an explanation of how dashboard queries stay fast at this volume.
  • A deduplication scheme that survives both client retries and worker crash recovery, including where its state lives and how long it is kept.
  • Event-time windowing: how a window is declared complete, what happens to late events, and how corrected counts reach the dashboard without double counting.
  • Fraud filtering at more than one time scale, and how fraud found after the fact is removed from dashboards and bills.

Follow-up Questions Guidance

  • One ad goes viral and most clicks share a single ad_id . Where does the load concentrate, and how do you spread it without breaking the counts?
  • A bug inflated yesterday's counts. How do you recompute the day and replace the stored aggregates without double counting?
  • Spend totals reach the dashboard minutes late. How do you stop a campaign from running far past its daily budget?
  • Clicks arrive in several regions. How do you keep latency low for clients and still count each click once?