PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/System Design/Amazon

Design real-time top-K products service

Last updated: Jun 15, 2026

Quick Overview

An Amazon software-engineer system-design screen: design a real-time service that ingests a stream of purchase events (customer_id, item_id, timestamp) and continuously serves the top-K most purchased items over multiple rolling windows (e.g. last 5 minutes, last 1 hour, 24 hours, and daily totals). The answer covers ingestion and partitioning, event-time windowing with watermarks, exact min-heap vs. approximate Count-Min-Sketch / Space-Saving top-K, late/duplicate/out-of-order handling, state and TTL, exactly-once fault tolerance, horizontal scaling, serving APIs, and latency-vs-accuracy trade-offs.

  • hard
  • Amazon
  • System Design
  • Software Engineer

Design real-time top-K products service

Company: Amazon

Role: Software Engineer

Category: System Design

Difficulty: hard

Interview Round: Technical Screen

##### Question Design a real-time service that ingests a continuous stream of purchase events with the schema `(customer_id, item_id, timestamp)` and continuously computes and serves the **top-K most purchased items**. The service must support multiple rolling windows at once, for example: - A short sliding window (e.g. last 5 minutes, or a configurable window `T` such as the last 1 hour), and - A long window and **daily rolling totals** (e.g. last 24 hours, plus per-calendar-day totals with both a running "today" view and finalized prior days). Work through the full design and address each of the following: 1. **Data model** for the ingested event and for the materialized top-K result records. 2. **Ingestion pipeline and partitioning** — durable log, partition key choice, and hot-key mitigation. 3. **Windowing and aggregation strategy** — sliding windows vs. tumbling micro-buckets with add/subtract, keyed windows, slide cadence, and how daily totals are finalized. 4. **Algorithms and data structures** for maintaining top-K at scale (e.g. count map + min-heap for exact, or approximate heavy-hitters such as Space-Saving / Misra-Gries and Count-Min Sketch + heap), including the two-stage local-then-global merge pattern. 5. **Event-time processing** with watermarks: handling **late, out-of-order, and duplicate** events; allowed-lateness budgets per window. 6. **State management and TTL** — embedded state store, checkpointing, per-window namespaces, and eviction. 7. **Fault tolerance and exactly-once vs. at-least-once** semantics. 8. **Horizontal scalability** — partitioning, key-splitting for skew, autoscaling. 9. **Serving and query APIs** — how clients fetch the current top-K per window/day, plus optional streaming push. 10. **Latency vs. accuracy trade-offs** and how you would tune them.

Quick Answer: An Amazon software-engineer system-design screen: design a real-time service that ingests a stream of purchase events (customer_id, item_id, timestamp) and continuously serves the top-K most purchased items over multiple rolling windows (e.g. last 5 minutes, last 1 hour, 24 hours, and daily totals). The answer covers ingestion and partitioning, event-time windowing with watermarks, exact min-heap vs. approximate Count-Min-Sketch / Space-Saving top-K, late/duplicate/out-of-order handling, state and TTL, exactly-once fault tolerance, horizontal scaling, serving APIs, and latency-vs-accuracy trade-offs.

Related Interview Questions

  • Design a Library Management System (API and Schema) - Amazon (hard)
  • Design a Perishable-Goods Inventory and Location Tracking System - Amazon (medium)
  • Design a Log Collection System - Amazon (medium)
  • Design Human Avoidance for Warehouse Robots - Amazon (medium)
  • Design a High-Availability Load Balancer - Amazon (hard)
Amazon logo
Amazon
Sep 6, 2025, 12:00 AM
Software Engineer
Technical Screen
System Design
6
0
Question

Design a real-time service that ingests a continuous stream of purchase events with the schema (customer_id, item_id, timestamp) and continuously computes and serves the top-K most purchased items. The service must support multiple rolling windows at once, for example:

  • A short sliding window (e.g. last 5 minutes, or a configurable window T such as the last 1 hour), and
  • A long window and daily rolling totals (e.g. last 24 hours, plus per-calendar-day totals with both a running "today" view and finalized prior days).

Work through the full design and address each of the following:

  1. Data model for the ingested event and for the materialized top-K result records.
  2. Ingestion pipeline and partitioning — durable log, partition key choice, and hot-key mitigation.
  3. Windowing and aggregation strategy — sliding windows vs. tumbling micro-buckets with add/subtract, keyed windows, slide cadence, and how daily totals are finalized.
  4. Algorithms and data structures for maintaining top-K at scale (e.g. count map + min-heap for exact, or approximate heavy-hitters such as Space-Saving / Misra-Gries and Count-Min Sketch + heap), including the two-stage local-then-global merge pattern.
  5. Event-time processing with watermarks: handling late, out-of-order, and duplicate events; allowed-lateness budgets per window.
  6. State management and TTL — embedded state store, checkpointing, per-window namespaces, and eviction.
  7. Fault tolerance and exactly-once vs. at-least-once semantics.
  8. Horizontal scalability — partitioning, key-splitting for skew, autoscaling.
  9. Serving and query APIs — how clients fetch the current top-K per window/day, plus optional streaming push.
  10. Latency vs. accuracy trade-offs and how you would tune them.

Solution

Show

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More System Design•More Amazon•More Software Engineer•Amazon Software Engineer•Amazon System Design•Software Engineer System Design
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.