Katkat

Design real-time ad impression and spend tracking

SnapchatSoftware Engineer · Onsite

Last updated

This question tests the ability to design a high-throughput, fault-tolerant system capable of tracking massive volumes of ad impression events and calculating real-time budget spending.

System Design: Real-time Ad Tracking Platform

Design a distributed system for a social media platform that tracks ad impressions and updates the total spend for each active advertisement in real-time.

Requirements

  • Scale: The system must support 1 million impressions per second (IPS) globally.
  • Functionality:
    • Ingest ad impression events (AdID, UserID, Timestamp, Cost).
    • Provide a query API to retrieve the total spend of an ad campaign within the last N minutes.
    • Enforce a hard budget limit per ad campaign; if the budget is reached, stop serving the ad.
  • Accuracy: We need high accuracy for billing. Dropped events are unacceptable.
  • Latency: The budget-check mechanism must be extremely low latency (under 10ms) to ensure we do not overspend.

What to include in your design:

  1. Data Model: How to store campaign budgets and impression counters efficiently.
  2. Architecture: Describe the ingestion pipeline, storage layer, and the path for budget checks.
  3. Scalability & Consistency: Explain how you handle spikes in traffic and ensure the budget constraint is enforced even during partition events.
  4. Trade-offs: Discuss the balance between strong consistency (for billing) and high availability/low latency (for ad serving).

Hints

Hint 1

Consider using a distributed message queue like Kafka to buffer incoming impression events before processing them.

Hint 2

Use a fast, in-memory data store like Redis with atomic operations to maintain counters and perform real-time budget checks.

Hint 3

Think about the difference between the 'write path' for billing logs (durable storage) and the 'read path' for budget enforcement (fast, cached state).

Follow-up questions

  • How would you handle a scenario where an ad campaign needs to be paused immediately across all data centers?
  • If the Redis cache fails, how do you prevent the system from overspending before the cache is recovered?
  • How would you evolve this system to support 'per-user' frequency capping in addition to budget spending limits?