← Amazon Interview Insights

Amazon·Data Scientist·Technical Phone Screen·Senior

SeniorPrefer not to say
May 2026

Summary

Amazon data scientist interview that went deep on streaming systems and real-time event processing. The whole session was basically one long multi-part problem about user session windows, and it got pretty hairy by part three. Not what I expected from a DS role.

Questions Asked (5)

Q1

Given a day of event-stream data with user enter/exit events per channel, compute the active user count for every 1-minute tumbling window per channel using pandas. Events may be out of order and users may have missing exit events.

Algorithms & Data StructuresData ModelingProduct Analytics & Metrics
Author's notes

The missing exit assumption tripped me up more than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the definition of 'active user' and how to handle missing exit events. Then, preprocess the data by sorting events, forward-filling missing exits, and computing active intervals. Finally, use pandas to bin intervals into 1-minute tumbling windows per channel and count unique users.

Pro tip: Explicitly state your assumptions about missing exits (e.g., assume user remains active until end of day) and validate with edge cases like overlapping sessions or out-of-order events. This shows you think about data quality and real-world messiness.

1. Clarify requirements and assumptions

Ask clarifying questions about the definition of 'active user' (e.g., any overlap with window) and how to handle missing exit events (e.g., assume active until end of day). Confirm the output format (e.g., per channel per minute).

2. Preprocess and sort events

Sort events by timestamp and user. For each user-channel, pair enter and exit events, handling missing exits by imputing a default exit time (e.g., end of day).

3. Compute active intervals

For each user-channel session, create an interval [enter_time, exit_time). Ensure intervals are valid (exit > enter) and handle overlapping sessions by merging if necessary.

4. Bin intervals into tumbling windows

Generate 1-minute tumbling windows per channel. For each window, determine which intervals overlap with it, and count unique users active in that window.

5. Aggregate and output results

Produce a DataFrame with columns: channel, window_start, window_end, active_user_count. Validate results with sanity checks (e.g., counts non-negative, no missing windows).

Key Points to Mention

  • Definition of active user: any overlap with the 1-minute window vs. active at any point within the window.
  • Handling missing exit events: impute with end of day or last event time, and document the assumption.
  • Out-of-order events: sort by timestamp and user to correctly pair enter/exit events.
  • Efficient computation: use pandas vectorized operations, interval overlap logic, and groupby to avoid loops.
  • Edge cases: sessions spanning multiple windows, overlapping sessions for same user, and users with multiple enter/exit pairs.
  • Scalability: consider memory usage and potential need for chunking if data is large.

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

Q2

For each 1-minute window, return the top 3 channels by active user count with ties broken lexicographically, and include a dense rank per minute.

Algorithms & Data StructuresData Modeling
Author's notes

Straightforward once the first part is done.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the input schema (event-level with timestamps and channel IDs) and define the 1-minute window boundaries (e.g., tumbling windows aligned to minute marks). Then outline a two-stage pipeline: first aggregate active user counts per channel per minute, then rank channels within each minute using a dense rank with lexicographic tie-breaking, and finally filter to the top 3.

Pro tip: Explicitly state your assumptions about windowing (tumbling vs. sliding) and tie-breaking order (ascending lexicographic on channel name) before diving into the algorithm—this shows you think about edge cases and data semantics, which is critical for production data science at Amazon.

1. Clarify requirements and data model

Ask about the input format (e.g., event stream or table with user_id, channel, timestamp), the definition of 'active user' (e.g., distinct users per minute), and whether windows are tumbling or sliding. Confirm that ties are broken by channel name in ascending lexicographic order.

2. Aggregate active users per channel per minute

Group events by 1-minute window and channel, then count distinct user IDs to get the active user count for each channel in each minute. This can be done with a windowing function or by truncating timestamps to the minute.

3. Rank channels within each minute

For each minute, sort channels by active user count descending, then by channel name ascending. Assign a dense rank (1,2,2,3,...) based on this ordering, ensuring that ties in count receive the same rank and the next distinct count gets the next consecutive rank.

4. Filter to top 3 and output

Select rows where dense rank <= 3, and return the minute, channel, active user count, and dense rank. Ensure the output is sorted by minute and rank for readability.

5. Discuss scalability and edge cases

Mention how to handle large data (e.g., using distributed processing like Spark or SQL window functions), empty minutes, channels with zero users, and ties at the boundary of top 3 (e.g., if multiple channels tie for 3rd place, all should be included).

Key Points to Mention

  • Definition of 'active user' as distinct users within the 1-minute window
  • Tumbling vs. sliding window semantics and alignment to minute boundaries
  • Dense rank vs. standard rank and how ties are handled
  • Lexicographic tie-breaking on channel name (ascending order)
  • SQL window functions (e.g., DENSE_RANK() OVER (PARTITION BY minute ORDER BY count DESC, channel ASC)) or equivalent in Spark/Pandas
  • Handling ties at the top-3 cutoff (include all tied channels if they share the 3rd rank)

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

Q3

Design a streaming system that produces the same windowed outputs with event-time semantics, 5-minute allowed lateness, and idempotent/exactly-once processing. Cover state keys, watermarks, late event handling, and long-lived state compaction.

System DesignTechnical Trade-offs
Author's notes

This is where I spent most of my mental energy and still felt like I left stuff on the table.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and defining the event-time windowing semantics, then walk through the architecture focusing on state management, watermark generation, and late event handling. Emphasize how idempotent writes and exactly-once processing are achieved, and discuss strategies for long-lived state compaction.

Pro tip: Demonstrate awareness of trade-offs between latency, completeness, and cost—e.g., using allowed lateness to balance accuracy and resource usage—and mention how you would monitor and tune watermarks in production.

1. Clarify Requirements and Semantics

Confirm window type (tumbling, sliding, session), event-time vs processing-time, and exactly-once expectations. Define what 'same windowed outputs' means in terms of determinism and idempotency.

2. Design Event-Time Windowing and Watermarks

Explain how watermarks are generated (e.g., bounded out-of-orderness) and propagated. Describe how windows are triggered based on watermarks and how allowed lateness extends window lifetime.

3. Handle Late Events and State Management

Detail how late events (within 5 minutes) are processed and how state is maintained per key. Discuss state keys (e.g., composite keys of window end + key) and state store choices (e.g., RocksDB).

4. Ensure Idempotent and Exactly-Once Processing

Describe mechanisms like transactional writes, idempotent sinks, and checkpointing to achieve exactly-once semantics. Explain how to deduplicate or upsert outputs to avoid duplicates.

5. Implement State Compaction and Cleanup

Outline strategies for compacting long-lived state: TTL-based eviction, periodic cleanup of expired windows, and using incremental checkpoints to manage state size.

Key Points to Mention

  • Watermark generation with bounded out-of-orderness and how it triggers window evaluation
  • State keys design: composite keys (e.g., window_end + key) to enable efficient lookups and updates
  • Late event handling: side outputs or state updates for events within allowed lateness, and dropping beyond
  • Exactly-once semantics via checkpointing, transactional sinks, and idempotent writes (e.g., upserts with unique keys)
  • State compaction: TTL for state entries, periodic cleanup, and using incremental checkpoints to reduce overhead
  • Trade-offs: latency vs completeness, cost of state storage, and impact of allowed lateness on resource usage

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

Q4

How would you detect and repair clock skew, deduplicate near-duplicate events, and bound memory usage when the active session set spikes? What's the big-O complexity in steady state and worst case?

System DesignTechnical Trade-offsAlgorithms & Data Structures
Author's notes

The clock skew piece I handled okay, comparing event timestamps against ingestion time and flagging anything suspiciously far in the future or past.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the data characteristics (event rate, skew magnitude, duplicate criteria, memory constraints) and then propose a streaming pipeline with three stages: skew detection/correction, deduplication, and memory bounding. For each stage, discuss algorithmic choices, trade-offs, and complexity, emphasizing how to maintain efficiency under spikes. Conclude with steady-state and worst-case big-O analysis, highlighting the impact of data structures and backpressure.

Pro tip: Mention that clock skew can be handled with a bounded reordering buffer and watermarking, but be explicit about the latency vs. correctness trade-off. Also, note that deduplication often uses probabilistic structures like Bloom filters, but for exact dedup, a time-windowed LRU cache is more appropriate.

1. Clarify Requirements and Constraints

Ask about event rate, acceptable latency, skew bounds, duplicate definition (exact vs. near), memory limits, and whether the system is distributed. This ensures the solution is tailored to the problem.

2. Detect and Repair Clock Skew

Propose using per-source clock offset estimation (e.g., NTP-like) and a bounded reordering buffer with watermarks to correct timestamps. Discuss how to handle out-of-order events and the trade-off between latency and completeness.

3. Deduplicate Near-Duplicate Events

For exact duplicates, use a time-windowed hash set (e.g., LRU cache). For near-duplicates, use locality-sensitive hashing (LSH) or MinHash to compute similarity, then cluster and keep one representative. Explain how to bound memory with windowing or probabilistic structures.

4. Bound Memory Usage During Spikes

Implement backpressure, load shedding, or dynamic memory allocation. Use fixed-size buffers, eviction policies (e.g., LRU), and possibly spill to disk. Discuss how to maintain correctness under memory constraints.

5. Analyze Complexity

For steady state, assume constant event rate and bounded skew: O(1) amortized per event for dedup and skew correction. Worst case (spike or large skew): O(n) for sorting/reordering, O(n) memory for dedup if window grows, but with bounding, it's O(k) where k is window size.

Key Points to Mention

  • Watermarking and bounded reordering for clock skew correction
  • Time-windowed deduplication with LRU cache or Bloom filter for memory efficiency
  • Locality-sensitive hashing (LSH) for near-duplicate detection
  • Backpressure and load shedding to handle spikes
  • Amortized O(1) per event in steady state, O(n log n) worst-case for sorting/reordering
  • Trade-offs between accuracy, latency, and memory

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

Q5

How do you handle an exit event with no prior enter event, or overlapping sessions from the same user in the same channel?

Data ModelingRoot Cause Analysis
Author's notes

I said orphan exits get dropped or logged for monitoring, which felt safe.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the business context and data pipeline assumptions, then walk through a systematic approach to detect and resolve these anomalies. Emphasize the importance of defining sessionization rules and validating with stakeholders before implementing fixes. Conclude with how you would monitor and prevent future occurrences.

Pro tip: Mention that you would first quantify the impact of these anomalies on key metrics to prioritize the fix, and always document your assumptions and edge-case handling for reproducibility.

1. Clarify the data and business context

Ask about the data source, session definition, and how these anomalies affect downstream metrics. Understand if there are known causes like logging errors or bot traffic.

2. Detect and quantify the anomalies

Write queries to identify exit-without-enter and overlapping sessions, and measure their frequency and impact on key metrics. Use window functions to flag these cases.

3. Define handling rules

Propose rules such as dropping orphan exits, merging overlapping sessions, or assigning them to the earliest enter event. Consider business implications of each rule.

4. Implement and validate

Apply the rules in the ETL pipeline, validate results with sample data, and compare metrics before and after. Ensure the solution is scalable and automated.

5. Monitor and prevent

Set up alerts for anomaly rates and work with engineering to fix root causes like logging bugs. Document the process for future reference.

Key Points to Mention

  • Sessionization logic and window functions (e.g., LAG, LEAD) to detect anomalies
  • Impact on metrics like session duration, conversion rate, and user engagement
  • Trade-offs between different handling strategies (e.g., dropping vs. merging)
  • Root cause analysis: data pipeline issues, bot traffic, or user behavior
  • Stakeholder communication and documentation of assumptions
  • Automated monitoring and alerting for data quality

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