KatInterview

Year-Long Ad Click Aggregation with External Logging Integration

System DesignModel answer
HardModel answerSystem Designaggregationdata-pipelinestimeseries

Last updated

Design an aggregator that answers queries over a rolling one-year window of ad clicks, ingesting from an existing logging API rather than a real-time stream.

You are tasked with building an aggregation service for advertising click data. The system must support queries that span up to one year of historical data, and all click events arrive via an external logging API that your team does not control.

This problem differs from the typical real-time click counter in two critical ways: the query window extends to a full year rather than minutes or hours, and you must work within the constraints of a third-party logging interface instead of designing your own event pipeline.

What You Should Clarify

Before proposing a design, ask questions to understand:

  • Time window semantics: Does "last year" mean a rolling 365-day window, the most recent calendar year, or arbitrary ranges within the past year?
  • Logging API characteristics: Does it offer a push stream, a pull-based query interface, or periodic batch dumps? What are its delivery semantics (at-least-once, exactly-once, best-effort), latency, throughput limits, and can it serve historical data for backfills?
  • Query patterns: What dimensions are queried (per ad, per campaign, per advertiser)? What time granularities (hourly, daily)? What is the expected query latency and volume?
  • Accuracy requirements: Are counts used for billing (requiring exact deduplication and auditability) or analytics dashboards (where approximation is acceptable)?
  • Scale: How many distinct ads exist? What is the daily click volume? What query throughput must the system sustain?
  • Data quality: Must the system filter invalid or fraudulent clicks before aggregating?

What You Should Deliver

Present a complete architecture that addresses ingestion from the external API, storage optimized for year-long queries, query serving, and operational concerns such as backfill, correctness guarantees, and failure recovery.

Hints

Hint 1

Think about how pre-aggregation at different time granularities can make year-long queries efficient without scanning raw events.

Hint 2

Consider how you will track ingestion progress and handle replay or backfill when the logging API allows it.

Hint 3

Deduplication across a year requires a different strategy than keeping recent IDs in memory—what persistent, space-efficient structure fits?