Design Real-time Analytics System

Real-time analytics pipeline inspired by Kafka, Flink and Druid/Pinot architectures: durable replayable ingestion, a raw event lake, event-time windowed aggregation with exactly-once rollups, late-event handling, an OLAP store for ad-hoc queries and anomaly alerts. A teaching design.

Functional requirements

  • Ingest high-throughput event streams via authenticated API.
  • Durably buffer events and support at-least-once delivery to processors.
  • Aggregate metrics in tumbling/sliding windows with late-event handling.
  • Power live dashboards and APIs with sub-minute freshness.
  • Support ad-hoc drill-down on raw events for debugging.
  • Backfill and reprocess history when aggregation logic changes.
  • Detect anomalies and trigger alerts on threshold/ML rules.
  • Multitenant isolation with per-tenant quotas and cost controls.

Non-functional requirements

  • Availability: 99.95%+; single AZ failure should not halt ingest or queries.
  • Latency: ingest API p99 < 150 ms; dashboard API p95 < 300 ms; end-to-end freshness < 60 s.
  • Durability: raw events persisted with replication and backups; immutability for audit.
  • Scalability: independently scale ingest, queues, processors, and query tiers across multi-AZ deployments.
  • Consistency: at-least-once across stream; idempotent processors; read-after-write for configs.
  • Security: TLS 1.2+ in transit, encryption at rest, per-tenant API keys/OAuth, and RBAC for dashboards.
  • Resilience: timeouts, circuit breakers, retries/backoff, DLQs, and backpressure.
  • Observability: traces/logs/metrics for queue depth, lag, watermark, window lateness, and query p99.

How the design evolves

Stage 1: Single Server, GROUP BY over Raw Rows

See why inserting every event and aggregating on read can't support live dashboards.

What was missing: Nothing yet.

Why that's risky: 200K inserts per second overwhelm a transactional database, and each dashboard refresh scans millions of rows while ingestion waits.

What gets added: One server inserting each event as a row, with dashboards running GROUP BY queries over raw rows.

Trade-offs: Exact and simple, but reads and writes fight over the same table.

Stage 2: Durable Ingestion, a Data Lake and Hourly Rollups

Never lose an event, keep every raw event cheaply, and stop dashboards from scanning raw data.

What was missing: Events went straight into a transactional table, and dashboards aggregated raw rows.

Why that's risky: Dashboards are up to an hour behind, which isn't 'real time'.

What gets added: An ingest API that authenticates and validates batches onto a durable, replayable raw event log; a lake archiver writing raw events as hourly columnar files to object storage; an hourly batch job producing rollups; and a query API reading those rollups.

Trade-offs: Batch rollups are simple and exact, but freshness is limited by the batch interval.

Stage 3: Streaming Aggregation by Event Time

Update dashboards within a minute, correctly, even when events arrive out of order.

What was missing: Rollups were computed hourly.

Why that's risky: Malformed events can stall a partition, and events arriving after their window closed are dropped.

What gets added: A stream processor that aggregates events into one-minute windows by event time, using watermarks to decide when a window is complete and checkpoints so each event counts exactly once; rollups are upserted idempotently. A query cache keeps finished windows so only the current one is recomputed.

Trade-offs: Waiting for the watermark delays a window by a few seconds in exchange for counting late-but-not-too-late events correctly.

Stage 4: Late Events, Dead Letters and Replays

Handle bad and late data without stopping the pipeline.

What was missing: One bad event could block a partition, and late events were lost.

Why that's risky: Questions the rollups weren't designed for (new dimensions, unique users over a quarter) can't be answered.

What gets added: Malformed events go to a dead-letter queue instead of blocking; a replayer reprocesses them once fixed. Windows accept events up to an allowed lateness and are re-upserted, and anything later is corrected by replaying from the lake.

Trade-offs: Allowing lateness means a past minute's number can still change slightly.

Stage 5: OLAP Store for Ad-hoc Questions

Answer questions nobody planned for, over long time ranges.

What was missing: Only pre-defined rollups could be queried.

Why that's risky: Nobody is told when a metric suddenly drops, and pipeline lag goes unnoticed.

What gets added: An OLAP loader feeding a columnar store of raw events in micro-batches, with HyperLogLog sketches for approximate distinct counts; the query API routes ad-hoc and long-range questions there.

Trade-offs: Distinct counts are approximate (about 1% error) in exchange for tiny memory and fast merges.

Stage 6: Anomaly Alerts, Quotas and Monitoring

Notice problems in the metrics and in the pipeline itself.

What was missing: No alerting on metrics, no producer quotas, no pipeline monitoring.

Why that's risky: Remaining risk is regional: each region's pipeline should keep running if another fails.

What gets added: Completed windows flow to an anomaly detector that compares them with seasonal baselines and alerts the owning team; per-producer quotas at ingest; and monitoring of ingest lag, consumer lag, watermark delay and dead-letter volume.

Trade-offs: Seasonal baselines need weeks of history before alerts are trustworthy.

Frequently asked questions

Exactly-once vs at-least-once: what should I pick?

Prefer at-least-once with idempotent processors and de-duplication keys. Exactly-once often adds complexity without clear benefits; track offsets and use transactional writes only where strictly required.

How do you handle late and out-of-order events?

Use event-time processing with watermarks and allowed lateness. Emit corrections to the same aggregate keys; maintain compactable state and a backfill worker to reconcile windows that exceed lateness thresholds.

How do you keep dashboards fast at scale?

Front the query API with a cache for hot dashboards, denormalize aggregates for the most common queries, and use replicas for read scaling. Limit query shapes, paginate, and pre-warm caches around known spikes.

What do you alert on for stream health?

Alert on consumer lag, watermark stall, processing error rate, queue depth, and end-to-end freshness. Create SLOs and burn-rate alerts to react before users notice.

How do you run backfills safely in production?

Throttle backfills, write to side tables or temp partitions, and validate results before swapping. Use idempotent jobs and pause conflicting online tasks. Monitor impact on primary queues and stores.

PRISM
System Design Interview
Round 1 of 4 · Architecture Design · 60:00 remaining
PRISM logo PRISM logo
Problems
AI Interview
Interview Challenges
Build & Stress Test NEW
System Architectures
Design & Fix NEW
Interactive Roadmap
System Design Guides Interview Prep Guide
Problems
Today's mission
Notifications
    Theme
    Pricing Community NEW Send feedback Report a problem NEW
    Sign in
    Theme
    Community NEW Send feedback Report a problem NEW
    All problems
    Phase
    Build & Stress Test
    Phase 01: Thinking in Systems
    Upcoming

    Components

    User
    CDN
    Load Balancer
    Server
    Cache
    Database
    Blob Storage
    Search Index
    Queue
    Worker
    Rate Limiter
    Service
    API Gateway
    Reverse Proxy
    WebSocket Server
    Third-party API

    Inspector

    Notes
    Use clear names so your design intent is easy to understand.
    Good
    Name by business meaning
    "Order API", "Restaurant Service"
    Avoid
    Generic names = zero signal
    "Server 1", "API", "Queue"
    A short description for each component makes feedback much better.
    100%
    Start by identifying:
    • Users & entry points
    • APIs & services
    • Databases & storage
    • Traffic flow & scale

    Round 1 of 4 Architecture Design

    Run a simulation to see results.

    Time Remaining
    60:00
    System Design Interview

    What are the core functional requirements?
    What are the key non-functional constraints?

    Questions

    Start Evaluation to unlock questions.

    EVALUATE MODE

    Test yourself like it's the real thing.

    A structured 4-module evaluation that mirrors how top companies assess system design candidates.

    Architecture Design
    Draw your system on the canvas. Define components, connections, and data flow.
    FR & NFR Requirements
    Answer functional and non-functional requirement questions about your design.
    MCQ Round
    Multiple choice questions testing your depth on the chosen system.
    Tradeoff Analysis
    Justify your design decisions and defend your architectural tradeoffs.
    AI Report Generated
    Choose a Problem
    No problem selected
    • 30 min
    • 45 min
    • 60 min
    Round 2 of 4
    MCQ Round
    Answer multiple-choice questions based on your design.

    Exit Interview?

    You're in the middle of an interview session. Leaving now will end your current attempt.

    Your progress will be saved.

    Open a saved design

    Select a design to load into the canvas.

    My Evaluations

    Your past evaluation sessions

    Here’s a simple request flow that follows the expected layer order.

    External User
    →
    Edge CDN → API Gateway → Load Balancer
    →
    Compute App Servers / Services
    →
    DataAccess Cache
    →
    Storage Database / Search Index
    →
    Async Queue → Worker

    Tip: keep arrows moving forward through layers (Edge → Compute → Storage). Avoid sending storage back to compute.

    Evaluation Instructions

    Read the rules carefully before starting. The test auto-submits on refresh.

    Before you start

    • Build your architecture on the canvas. The timer starts when you click Start Evaluation.
    • Don't forget to answer Functional Requirement and Non Functional Requirements.
    • When satisfied with your design, click Next to lock it and view the questions.
    • Please answer final step questions to complete the evaluation.

    Dos

    • Do read each question carefully before answering.
    • Do include required components to maximize component coverage.
    • Do save a copy of your design if you want to keep it before submission.

    Don'ts

    • Don't refresh or close the tab during an active evaluation — this will auto-submit your answers.
    • Don't switch app modes or open another tab while the evaluation is running.
    • Don't attempt to edit the design after clicking Next; the workspace will be locked.

    All the best!!

    Confirm

    Input

    Notice

    Evaluation Report
    Report a problem

    Evaluation Complete

    Generating Your Report

    Hang tight — our AI is evaluating your design…

    Did you know?

    Loading…

    Share feedback

    Tell us what worked well and what we can improve.

    Let's personalize this

    Answer a couple of quick questions so we can tailor your journey and missions.

    Your welcome gift: of Full PRISM Access

    Your Pro access starts as soon as you press Start my journey.

    SYSTEM BRIEF

    System Constraints

    What the system must do — every item is a user-facing behaviour your architecture must support.

      ↑ Engineering Constraints

      These are the failure modes you must design against — latency SLAs, durability targets, traffic ceilings.

        ⇆ Architecture Constraints

        Core Concepts to Master

        Your Journey
        PHASE – –
        0 / 0 0%
        0
        Mock Interview Checklist

        Pick a topic to start

        Explore concept overviews, real-system examples, key tradeoffs, and interview talking points for each roadmap section.

        Phase Mastered

        You've conquered this phase. These are the skills you now own:

          +500 XP

          Company Interview Paths

          Progress Summary