KatInterview

Design a Real-Time Click Counter and a Cross-Device File Sync Service

System DesignModel answer
HardModel answerSystem Designstreamingkafkaflink

Last updated

Design two systems: a high-throughput ad click aggregator with idempotent deduplication, and a Dropbox-style file sync service with delta uploads and conflict resolution.

Overview

You are asked to design two independent but related distributed systems. Spend roughly equal time on each. For both, walk through API design, data modeling, architecture, and key trade-offs.


Part 1: Real-Time Click Counter

Build a backend system that records ad clicks and serves per-ad click counts aggregated by minute, at high throughput.

Each click event carries four fields: a unique click identifier, the ad identifier, the user identifier, and an event timestamp.

Requirements

  • Aggregate counts must be available within roughly one minute of the click occurring.
  • The system must deduplicate retries: if a client sends the same click twice due to a network retry, it must be counted only once.
  • Events may arrive slightly out of order (up to a few minutes late) due to network jitter. Late events should still be counted correctly.
  • The aggregates must be accurate enough for billing purposes.

Scale target: sustain at least 100,000 clicks per second, with the ability to absorb short peaks around 3× that.


Part 2: Cross-Device File Sync Service

Build a service that lets users store files in the cloud and keep them in sync across all their devices, similar to Dropbox.

Requirements

  • Support uploading new files, downloading files, and propagating edits made on one device to all others.
  • When two devices edit the same file at the same time, the system must detect the conflict and offer a resolution strategy rather than silently overwriting data.
  • Keep a version history so users can restore a previous state.
  • For large files, avoid re-uploading the entire file when only a small portion changes (delta sync).

Scale target: 10 million active users, approximately 3 devices each, average storage around 5 GB per user.


What Your Answer Should Cover

  1. API design — the key endpoints for both systems, including request and response shapes.
  2. Data model — schema choices suited to high-frequency writes (clicks) versus durable, versioned storage (files).
  3. Architecture — the core components, how they communicate, and which storage technologies you would use and why.
  4. Trade-offs — for the click aggregator, discuss consistency versus availability; for the sync service, discuss latency versus bandwidth efficiency and your conflict resolution strategy.

You are not expected to produce a fully production-ready spec. Focus on the most interesting design decisions and be explicit about where you are making trade-offs.

Hints

Hint 1

For the click aggregator, think about where deduplication should live (stream processor state vs. an external store like Redis) and what the cost of each approach is in memory and latency. Also consider what happens to clicks that arrive after your dedup window closes — how does a batch reconciliation job save you?

Hint 2

For the file sync service, content-addressable block storage (keying blocks by their SHA-256 hash) is the key insight that unlocks deduplication, immutable storage, and cheap delta uploads all at once. Walk through the upload flow step by step: chunk → hash → check which blocks the server already has → upload only the diff → commit metadata.

Hint 3

On conflict resolution: the classic approach is optimistic concurrency — the commit carries the parent revision the client based its edit on, and the server rejects the commit with a 409 if someone else has already advanced that revision. The client then has enough information to merge or surface a conflict copy. Be ready to explain why last-write-wins is dangerous for billing or document edits.