← Amazon Interview Insights

Amazon·Software Engineer·Onsite - System Design / Architecture·Senior

SeniorPrefer not to say
May 2026

Summary

System design round at Amazon for a software engineering role. The whole session was basically one giant question about building a real-time top-K item ranking service, and they just kept pulling on every thread until there was nothing left to say.

Questions Asked (8)

Q1

Design a real-time service that ingests a stream of purchase events and continuously computes the top-K most purchased items across multiple rolling windows simultaneously, such as a short sliding window, a 24-hour window, and per-calendar-day totals.

System DesignData ModelingTechnical Trade-offs
Author's notes

This was the whole interview, basically.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and scale, then propose a streaming architecture that decouples ingestion from computation using a message queue. For each window type, use appropriate data structures (e.g., count-min sketch for sliding windows, hash maps with TTL for 24-hour windows, and partitioned counters for daily totals) and periodically emit top-K results. Discuss trade-offs between accuracy, latency, and resource usage.

Pro tip: Emphasize that exact top-K over high-cardinality streams is often impractical; propose approximate algorithms like count-min sketch or space-saving, and explain how to handle late-arriving data and window boundaries. Also, mention the importance of idempotency and exactly-once processing in a distributed environment.

1. Clarify Requirements and Scale

Ask about event volume, cardinality of items, required accuracy, latency, and window definitions (e.g., sliding window size, 24-hour window semantics). Confirm whether approximate results are acceptable.

2. High-Level Architecture

Propose a pipeline: ingestion via a distributed queue (e.g., Kafka), stream processing (e.g., Flink, Spark Streaming), and storage for results. Discuss partitioning by item ID to parallelize counting.

3. Data Structures for Each Window

For sliding window: use a ring buffer or time-bucketed counters with a count-min sketch for approximate top-K. For 24-hour window: maintain a hash map of item counts with timestamps, evicting old entries. For daily totals: use a partitioned counter per day, resetting at midnight.

4. Top-K Computation and Emission

Periodically (e.g., every second) compute top-K from each window's data structure. Use a min-heap of size K to efficiently track top items. Emit results to a serving layer (e.g., Redis) for low-latency queries.

5. Trade-offs and Failure Handling

Discuss trade-offs: exact vs approximate, memory vs accuracy, latency vs throughput. Address late data, window boundaries, and fault tolerance (checkpointing, replay).

Key Points to Mention

  • Use of approximate algorithms (count-min sketch, space-saving) for memory efficiency in high-cardinality streams.
  • Partitioning strategy to scale horizontally and avoid hot spots.
  • Handling of late-arriving events and out-of-order processing (watermarks, allowed lateness).
  • Idempotency and exactly-once semantics to avoid double counting.
  • Efficient top-K computation using min-heaps and periodic emission.
  • Trade-offs between accuracy, latency, and resource consumption.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

What data structures would you use to maintain top-K at scale, and how do you handle the aggregation across distributed workers?

Algorithms & Data StructuresSystem Design
Author's notes

I went with count map plus a min-heap for the exact case and mentioned Space-Saving as the approximate alternative.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: are we dealing with exact or approximate top-K, and what are the latency and accuracy requirements? Then, discuss single-node data structures like heaps or count-min sketch, and explain how to aggregate across distributed workers using a mergeable structure or a two-phase approach with a coordinator.

Pro tip: Mention that for approximate top-K, you can use a count-min sketch with a heap per worker, and then merge the heaps at the coordinator; this balances memory and accuracy. Also, highlight the trade-off between communication cost and accuracy when deciding on the aggregation strategy.

1. Clarify requirements

Ask about data volume, velocity, latency, accuracy (exact vs approximate), and whether the top-K is over a sliding window or all-time.

2. Choose single-node data structures

For exact top-K, use a min-heap of size K; for approximate, consider count-min sketch or Space-Saving algorithm to handle high cardinality with limited memory.

3. Design distributed aggregation

Each worker computes local top-K (or sketch) and sends to a coordinator; coordinator merges results. For exact, merge heaps; for approximate, merge sketches or use a second-level heap.

4. Optimize communication

Reduce data sent by having workers send only their top-K or a compact sketch; consider hierarchical aggregation (tree) to avoid coordinator bottleneck.

5. Handle updates and faults

For streaming, use sliding windows or decaying counts; ensure fault tolerance by checkpointing sketches or using replication.

Key Points to Mention

  • Min-heap for exact top-K with O(N log K) time and O(K) space per worker.
  • Count-min sketch or Space-Saving for approximate top-K with sublinear space.
  • Mergeable summaries: sketches can be combined by adding counts; heaps can be merged by taking top-K of union.
  • Two-phase aggregation: map (local top-K) then reduce (global top-K).
  • Trade-offs: exact vs approximate, memory vs accuracy, communication cost vs latency.
  • Amazon leadership principles: customer obsession (accuracy), dive deep (trade-offs), and deliver results (scalability).

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

How would you handle late-arriving, out-of-order, and duplicate events in your event-time processing pipeline?

System DesignTechnical Trade-offs
Author's notes

Watermarks I know, so that part was fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements: event-time semantics, acceptable latency, and exactly-once vs at-least-once processing. Then describe a layered approach using watermarks for late events, windowing with allowed lateness, deduplication via unique IDs, and buffering/reordering with a bounded delay. Finally, discuss trade-offs between latency, completeness, and cost, and mention how you'd monitor and tune the system.

Pro tip: Emphasize that you'd first align with stakeholders on the business impact of late/duplicate data—e.g., whether a slightly delayed but complete result is better than a fast but approximate one—and design the pipeline accordingly. This shows you think beyond pure technology and consider product requirements.

1. Clarify requirements and constraints

Ask about event-time vs processing-time semantics, acceptable latency, data completeness, and delivery guarantees (at-least-once, exactly-once). This sets the stage for choosing the right techniques.

2. Handle late and out-of-order events

Use watermarks to track event-time progress and define allowed lateness. Buffer events in a reorder buffer or use a windowing mechanism that emits results after a grace period, possibly with speculative early results.

3. Deduplicate events

Assign unique event IDs and maintain a deduplication store (e.g., a distributed cache or state store) with a time-to-live. For exactly-once semantics, leverage idempotent writes or transactional sinks.

4. Choose the right processing framework

Leverage a stream processing engine like Apache Flink, Kafka Streams, or Google Cloud Dataflow that natively supports event-time processing, watermarks, and stateful deduplication. Explain how you'd configure it.

5. Discuss trade-offs and monitoring

Articulate trade-offs: higher allowed lateness increases completeness but adds latency and state size; deduplication adds overhead. Describe metrics to monitor (e.g., late event rate, duplicate rate) and how you'd tune parameters.

Key Points to Mention

  • Watermarks and allowed lateness for handling late/out-of-order events
  • Windowing strategies (tumbling, sliding, session) and triggers for early/on-time/late results
  • Deduplication using unique event IDs and state stores with TTL
  • Exactly-once processing semantics via idempotent writes or transactions
  • Trade-offs between latency, completeness, cost, and complexity
  • Monitoring and tuning: metrics like late event rate, watermark lag, and duplicate detection rate

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

How would you manage state across windows, including TTL and eviction policies, to avoid unbounded memory growth?

System DesignTechnical Trade-offs
Author's notes

Talked about per-window namespaces in an embedded state store and TTL-based eviction.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the context: what kind of state, across which windows (browser tabs, desktop windows, microservices), and the expected scale. Then propose a layered architecture with a bounded store (e.g., LRU cache) and TTL-based expiration, and discuss eviction policies and monitoring to prevent unbounded growth.

Pro tip: Emphasize that TTL alone is not enough—you need a hard cap on memory and a proactive eviction policy like LRU or LFU, plus metrics to detect when you're approaching the limit. Also mention that state should be partitioned or sharded to avoid a single point of failure and to scale horizontally.

1. Clarify requirements and scope

Ask questions to understand the type of state, number of windows, expected state size, and consistency needs. This shows you don't jump to solutions without context.

2. Choose a storage strategy

Decide where state lives: in-memory per window, centralized store (Redis, DynamoDB), or a hybrid. Discuss trade-offs like latency, consistency, and durability.

3. Implement TTL and eviction

Describe how to set TTLs per state entry and enforce eviction policies (LRU, LFU, FIFO) with a max size cap. Mention using libraries like Guava Cache or Redis TTL.

4. Monitor and adapt

Explain how you'd track memory usage, hit/miss ratios, and eviction rates. Use metrics to tune TTLs and eviction policies dynamically.

5. Handle failure and consistency

Discuss what happens when state is evicted or TTL expires: fallback to recomputation, graceful degradation, and ensuring consistency across windows.

Key Points to Mention

  • TTL (time-to-live) per state entry to automatically expire stale data.
  • Eviction policies: LRU, LFU, or FIFO with a maximum size limit to bound memory.
  • Use of bounded caches (e.g., Caffeine, Guava) or Redis with maxmemory-policy.
  • Monitoring and alerting on memory usage, eviction rates, and cache hit ratios.
  • Partitioning/sharding state across windows or nodes to distribute load.
  • Trade-offs between consistency, latency, and memory footprint.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q5

How do you handle hot keys and partition skew in the ingestion pipeline?

System DesignAlgorithms & Data Structures
Author's notes

I suggested salting the partition key and doing a two-level aggregation.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining hot keys and partition skew, then explain how they cause bottlenecks in ingestion pipelines. Describe a multi-layered strategy: detection, mitigation, and prevention, using techniques like salting, dynamic partitioning, and load balancing. Conclude with trade-offs and how you would monitor and adapt the solution.

Pro tip: Emphasize that hot keys are often transient and context-dependent; a robust solution should include automatic detection and dynamic rebalancing rather than static partitioning. Also, mention that sometimes the best fix is to change the data model or ingestion pattern upstream.

1. Define the problem

Explain what hot keys and partition skew are and why they matter in ingestion pipelines (e.g., uneven load, latency, throttling).

2. Detection and monitoring

Describe how to detect skew: metrics per partition, key frequency analysis, and alerting on imbalance.

3. Mitigation techniques

List strategies to handle skew: salting keys, dynamic partitioning, load balancing, and backpressure.

4. Prevention and design

Discuss proactive design: choosing good partition keys, using composite keys, and designing for scalability.

5. Trade-offs and iteration

Acknowledge trade-offs (e.g., added complexity, latency) and how to iterate based on monitoring.

Key Points to Mention

  • Salting: adding a random prefix to hot keys to distribute load across partitions.
  • Dynamic partitioning: adjusting partition boundaries based on load.
  • Load balancing: using a load balancer or consistent hashing to distribute traffic.
  • Backpressure: applying backpressure to slow down producers when partitions are overwhelmed.
  • Monitoring: tracking partition-level metrics and key distribution.
  • Trade-offs: increased complexity, potential for hotspots elsewhere, and latency impact.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q6

Walk through your serving layer design. How do clients query the current top-K per window, and would you support any kind of push-based streaming to clients?

System DesignAPI & Integrations
Author's notes

Shorter part of the conversation.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements (window size, top-K, latency, consistency) and then describe the serving layer architecture: a query API for top-K per window and an optional push mechanism. Explain the data model and storage choices (e.g., precomputed top-K in a low-latency store) and how clients can retrieve results. Finally, discuss trade-offs of pull vs. push and propose a streaming solution if needed.

Pro tip: Emphasize that push-based streaming is often implemented via a pub/sub system (e.g., WebSocket, SSE, or Kinesis) with backpressure handling, but only if the use case demands real-time updates; otherwise, polling with caching is simpler and more scalable.

1. Clarify Requirements

Ask about window types (tumbling, sliding), K value, update frequency, latency tolerance, and client scale to tailor the design.

2. Design Query API

Define a RESTful endpoint like GET /topk?window=5m&k=10 that returns the current top-K list, backed by a fast key-value store (e.g., DynamoDB, Redis) with precomputed results.

3. Explain Data Flow

Describe how top-K results are computed (e.g., stream processing with Flink/Kafka Streams) and written to the serving store, ensuring low-latency reads.

4. Evaluate Push-Based Streaming

Discuss when push is needed (real-time dashboards) and propose a pub/sub model where clients subscribe to window updates via WebSocket or SSE, with server pushing new top-K lists.

5. Address Trade-offs

Compare pull vs. push in terms of scalability, complexity, and cost; mention backpressure, fan-out, and consistency guarantees.

Key Points to Mention

  • Precomputation of top-K per window to enable O(1) reads
  • Choice of storage: Redis sorted sets or DynamoDB with GSIs for low-latency queries
  • API design: versioning, pagination, and caching headers for scalability
  • Push mechanism: WebSocket/SSE with a message broker (e.g., Kinesis, SNS) for real-time updates
  • Backpressure and client-side throttling to handle high fan-out
  • Consistency model: eventual vs. strong consistency and its impact on client experience

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q7

Where do you land on exactly-once vs. at-least-once semantics for this system, and what are the practical implications of that choice?

System DesignTechnical Trade-offs
Author's notes

I said at-least-once with idempotent consumers is usually the pragmatic call for this kind of analytics workload, and that exactly-once adds overhead that often isn't worth it unless the counts feed billing or something high-stakes.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the system's requirements and constraints, then compare exactly-once and at-least-once semantics in terms of complexity, cost, and correctness. Recommend a pragmatic choice based on the use case, and discuss how to mitigate the downsides of that choice.

Pro tip: Emphasize that exactly-once is often an illusion in distributed systems and that true exactly-once requires end-to-end idempotency and transactional guarantees, which can be costly. Show you understand the trade-offs and can make a decision that balances business needs with engineering effort.

1. Clarify Requirements

Ask about the system's tolerance for duplicates, data loss, and latency. Determine if the use case is financial transactions, logging, or analytics, as this dictates the necessary semantics.

2. Define Semantics

Briefly explain exactly-once and at-least-once: exactly-once means each message is processed once, while at-least-once means messages may be reprocessed. Note that exactly-once is harder to achieve and often requires coordination.

3. Evaluate Trade-offs

Discuss the implications: exactly-once offers stronger guarantees but at the cost of higher latency, lower throughput, and increased complexity. At-least-once is simpler, more performant, but requires idempotent processing to handle duplicates.

4. Make a Recommendation

Based on requirements, recommend a choice. For example, if duplicates are acceptable or can be handled via idempotency, at-least-once is often sufficient. If not, consider exactly-once with transactional processing.

5. Discuss Implementation

Outline how to implement the chosen semantics: for at-least-once, use retries and idempotent consumers; for exactly-once, use transactional messaging or deduplication with unique IDs. Mention monitoring and failure handling.

Key Points to Mention

  • Exactly-once semantics typically require distributed transactions or idempotent processing with deduplication, which can be complex and impact performance.
  • At-least-once is the default in many systems (e.g., Kafka) and is often sufficient if consumers are idempotent.
  • Consider the end-to-end guarantee: even if the messaging system provides exactly-once, downstream systems may not, so overall exactly-once requires coordination across services.
  • Idempotency is key to handling duplicates in at-least-once systems; use unique message IDs and deduplication stores.
  • Trade-offs include latency, throughput, cost, and operational complexity; exactly-once can reduce throughput and increase latency.
  • Amazon's leadership principles: customer obsession (choose based on customer impact), dive deep (understand the technical details), and deliver results (pragmatic solutions).

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q8

How would you tune the system to balance latency against accuracy in the top-K results?

Technical Trade-offsSystem Design
Author's notes

Talked about slide cadence, approximate vs.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the system context and the specific latency and accuracy requirements. Then describe a systematic tuning process: identify knobs, measure trade-offs, and iterate based on business priorities. Emphasize that the optimal balance depends on the use case and can be adjusted dynamically.

Pro tip: Mention that you would instrument the system to collect real-time metrics and use A/B testing to validate changes, ensuring that tuning decisions are data-driven and aligned with business KPIs.

1. Clarify Requirements and Constraints

Ask about the specific latency SLA, accuracy targets, and the nature of the top-K results (e.g., search, recommendations). Understand the business impact of latency vs. accuracy.

2. Identify Tuning Knobs

List the parameters that affect latency and accuracy, such as model complexity, candidate generation size, ranking depth, pruning thresholds, and hardware resources.

3. Measure and Analyze Trade-offs

Describe how to benchmark different configurations to quantify the latency-accuracy curve. Use metrics like p99 latency, NDCG, recall@K, and precision@K.

4. Iterate and Optimize

Propose an iterative approach: start with a baseline, adjust one knob at a time, and use techniques like grid search or Bayesian optimization to find the sweet spot.

5. Monitor and Adapt

Emphasize continuous monitoring and dynamic adjustment based on traffic patterns, user feedback, and business goals. Consider multi-armed bandits or reinforcement learning for adaptive tuning.

Key Points to Mention

  • Latency-accuracy trade-off is not static; it depends on query type, user context, and load.
  • Techniques like early termination, cascading models, and approximate nearest neighbors (ANN) can reduce latency with minimal accuracy loss.
  • Use of caching and precomputation to serve top-K results faster.
  • Importance of defining clear metrics and SLAs to guide tuning decisions.
  • Consideration of cost implications: more accurate models may require more compute resources.
  • A/B testing and online evaluation to validate offline tuning results.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.