BLUEPRINT #03Media & Streaming
Design Real-Time Ad Click Event Aggregation
Referenced Architecture Primitives (7)
Click any primitive to study its algorithmic deep dive10-Stage Structure:1. Requirements→2. Sizing→3. Topology→4. Data Model→5. AWS Topology→6. Deep-Dive→7. Failures→8. SRE Playbooks
1. Problem Statement & Scope
System Mission
Design a mission-critical, low-latency, real-time ad click event ingestion and aggregation pipeline capable of processing hundreds of thousands of ad clicks per second, computing multi-granularity tumbling/sliding window metrics (1-minute, 1-hour, 24-hour CTR and spend), filtering click fraud and botnet attacks in real time, and maintaining strict exactly-once processing guarantees for advertiser billing.
Interactive Architecture DiagramSynthesizing vector architecture diagram...
Functional Requirements
- Ad Click Ingestion: Securely collect, authenticate, and validate ad click tokens globally with sub- response times.
- Multi-Window Real-Time Aggregation: Aggregate click counts, conversion counts, and total monetary spend partitioned by
ad_id,campaign_id, andpublisher_idacross 1-minute, 1-hour, and 24-hour sliding/tumbling windows. - Real-Time Click Fraud & Botnet Filtering: Discard duplicate clicks, bot click-farms, and rapid replay clicks before aggregating billing figures.
- Advertiser Analytics Query API: Provide sub- query responses for advertiser campaign dashboards tracking Click-Through Rate (CTR) and budget pacing.
- Historical Replay & Data Lake Audit: Persist raw click streams in a Snappy-compressed Parquet data lake for regulatory reconciliation and ML model retraining.
Non-Functional Requirements (SLAs/SLOs)
- High Throughput: Baseline ; peak capacity up to .
- Aggregation Freshness / Pipeline Latency: Aggregated metrics reflected in advertiser dashboards within ().
- Data Accuracy & Billing Consistency: Strict Exactly-Once processing semantics. Zero duplicate billing for advertiser clicks.
- High Availability: uptime for click ingestion endpoints.
- Fault Tolerance: Lossless stream recovery with stateful checkpoints in during worker failure.
Out-of-Scope
- Real-Time Bidding (RTB) auctions and ad serving exchange matchmaking (sub- DSP/SSP ad bidding covered in dedicated ad serving blueprints).
- Conversion attribution attribution modeling (e.g. multi-touch Shapley value attribution algorithms).
2. Capacity & Scale Estimation
Traffic & Event Volume Calculations
- Daily Ad Impressions: impressions/day.
- Average Click-Through Rate (CTR): .
Storage & Data Sizing Math
- Raw Click Event Payload Size: (JSON/Protobuf:
click_id,ad_id,campaign_id,user_token,ip_hash,cpc_cents,timestamp). - Aggregated Metric Record Volume:
- 100,000 active campaigns aggregated per minute to DynamoDB (vs. 100,000 raw writes/sec, a write load reduction).
3. High-Level Architecture & AWS Component Mapping
Interactive Architecture DiagramSynthesizing vector architecture diagram...
Component Responsibility Breakdown
| Component | AWS Technology | Operational Role & Configuration |
|---|---|---|
| Ingestion Load Balancing | Network Load Balancer (NLB) | Ultra-low latency layer 4 load balancing terminating TLS, distributing millions of concurrent TCP streams across ECS workers. |
| Click Ingestion Fleet | Amazon ECS Fargate (Go binary) | Lightweight stateless HTTP receivers validating cryptographic click signatures, producing records to Kinesis partitioned by hash(ad_id). |
| Event Streaming Pipeline | Amazon Kinesis Data Streams | 64-shard stream partitioned by ad_id guaranteeing FIFO ordering per ad and absorbing massive traffic spikes. |
| Stream Processing Engine | Managed Apache Flink | RocksDB state backend, event-time watermarking with 1-minute tumbling and 1-hour sliding windows, emitting aggregated deltas via Two-Phase Commit sinks. |
| Deduplication & Fraud Filter | Amazon ElastiCache Redis | In-memory Bloom filters (tracking unique click_id in 10-minute sliding windows) and atomic IP velocity sliding rate limiters. |
| Real-Time Aggregate Store | Amazon DynamoDB | High-performance NoSQL store holding pre-aggregated CTR metrics with Global Secondary Indexes for campaign-level rollups. |
| Data Lake & Audit Store | Amazon S3 + Kinesis Firehose | Buffers raw events into S3 partitioned by /year=YYYY/month=MM/day=DD/hour=HH/ in columnar Snappy Parquet format. |
4. API Interface Design & Wire Protocols
1. Ingest Ad Click Event
httpPOST /v1/events/adclick HTTP/1.1 Host: click.ads.aws.internal User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X)... X-Forwarded-For: 203.0.113.195 Content-Type: application/json { "click_id": "clk_88a91c74f0b21a", "ad_id": "ad_nike_airmax_2026", "campaign_id": "camp_nike_spring_global", "publisher_id": "pub_techcrunch_01", "user_id": "usr_998124a87", "cost_per_click_cents": 45, "impression_timestamp": 1718000000100, "click_timestamp": 1718000002340, "click_token_sig": "HMAC_SHA256(ad_id + timestamp + salt)" }
Response: 202 Accepted
json{ "status": "ACCEPTED", "redirect_url": "https://www.nike.com/air-max-2026?utm_source=ad_campaign" }
2. Query Real-Time Campaign Performance
httpGET /v1/analytics/campaigns/camp_nike_spring_global/metrics?window=1h&start_time=1718000000&end_time=1718003600 HTTP/1.1 Host: dashboard.ads.aws.internal Authorization: Bearer <jwt_token>
Response: 200 OK
json{ "campaign_id": "camp_nike_spring_global", "window": "1_HOUR", "total_clicks": 142850, "total_conversions": 4285, "total_spend_cents": 6428250, "ctr_percentage": 2.85, "cvr_percentage": 3.00, "fraud_clicks_blocked": 1820 }
5. Data Models & Storage Architecture
Interactive Architecture DiagramSynthesizing vector architecture diagram...
DynamoDB Schema (AdAggregatesTable)
Partition Key (PK) | Sort Key (SK) | Attributes | GSI1-PK / GSI1-SK |
|---|---|---|---|
AD#<ad_id> | WIN#1M#<epoch_minute> | clicks: 840, spend_cents: 37800, fraud_count: 12, updated_at | CAMP#<campaign_id> / DATE#<epoch_minute> |
AD#<ad_id> | WIN#1H#<epoch_hour> | clicks: 50400, spend_cents: 2268000, fraud_count: 720 | CAMP#<campaign_id> / DATE#<epoch_hour> |
AD#<ad_id> | WIN#1D#<YYYY-MM-DD> | clicks: 1209600, spend_cents: 54432000 | CAMP#<campaign_id> / DATE#<YYYY-MM-DD> |
Part 2: Production Deep-Dive Locked1 Coin = 24 Hours
Unlock Complete Architecture & Production Runbooks
Your Balance:40 Coins
You have explored the free architectural preview (~41%). Spend 1 Coin to unlock the remaining 6 production deep-dive sections for a full 24 hours.
Sections Included in This 24-Hour Pass:
6. Core Algorithms & Deep-Dive Workflows
7. Architectural Trade-Off Matrix & Primitive Links
8. Critical Failure Modes, Resiliency & Edge Cases
9. Production Pitfalls & Anti-Patterns (The "Top 5 Gotchas")
10. Production Runbook & Observability Guide
11. System Design Interview Rubric & Deep-Dive Strategy
Keeps page unlocked for exactly 24 hoursSpend coins to fund LLM & compute infrastructure