KatInterview

Live Metrics Pipeline for a Global Food-Ordering Platform

System DesignModel answer
MediumModel answerSystem Designsystem-designstream-processingkafka

Last updated

Design a streaming backend that serves order counts, revenue and best-selling dishes over 1-hour, 1-day and 7-day windows at 100K orders/s with data no more than 5 seconds stale.

Design a Live Metrics Backend for a Food-Ordering Platform

You are building the backend behind an operations dashboard for a worldwide food-ordering marketplace. Restaurant owners and internal staff use it to watch three numbers: how many orders came in, how much revenue they generated, and which dishes sell best. Each number must be available for the last 1 hour, the last 1 day and the last 7 days.

Constraints

  • Throughput: about 100,000 new orders per second across the whole platform.
  • Freshness: a new order must show up in dashboard widgets within 5 seconds.
  • Scope: every metric must be queryable for a single restaurant and for the whole platform.
  • Durability: short bursts of traffic must never cause order events to be lost.

Your answer should address

  1. Ingestion pipeline: how events travel from the order service to the aggregation layer, including buffering and stream processing.
  2. Long-term storage: a table design for the durable store and how you partition it for a heavy write load.
  3. Windowing: how you compute the three windows, and how you deal with late or out-of-order events and watermarks.
  4. Serving cache: a Redis key layout that lets the dashboard fetch any window at either scope cheaply.
  5. Resilience: how the system survives failures, and how you rebuild the cache if it drifts from the truth.

State your assumptions (event size, number of restaurants, accuracy expectations) and back them with rough numbers.

Hints

Hint 1

Start with back-of-envelope numbers: bytes per event, events per item line, restaurants active per second. They tell you where the real bottleneck is (write rate to the cache and hot keys, not raw ingest).

Hint 2

Avoid native sliding windows with a tiny slide. Pre-aggregate into small fixed time buckets (for example per minute and per hour) and build each window as a sum of buckets, adding new deltas and subtracting expired buckets.

Hint 3

A single global key is a hot spot. Aggregate in two stages (restaurant, then region, then global) and ship absolute values rather than increments to the cache so that retries and replays are harmless.

Hint 4

Think about what must be exact (counts, revenue, per-restaurant dishes) versus what may be approximate (platform-wide top dishes), and which data structure suits the approximate part.