← Amazon Interview Insights

Amazon·Data Scientist·Onsite - System Design / Architecture·Senior

SeniorPrefer not to say
Apr 2026

Summary

Amazon system design round for a Data Scientist role, which turned out to be way more engineering-heavy than I expected. The whole thing was basically one giant multi-threaded crawler problem and they wanted actual pseudocode, not just hand-waving.

Questions Asked (5)

Q1

Design and write pseudocode for a multi-threaded web crawler that prioritizes breadth-first discovery while running continuous analysis tasks on fetched pages. Your design must respect robots.txt and per-host rate limits, deduplicate URLs with at-most-once processing, use bounded memory with disk spillover, implement back-pressure between crawling and analysis, and support graceful shutdown with exactly-once checkpointing on restart.

System DesignAlgorithms & Data StructuresTechnical 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 outline a high-level architecture with distinct components for frontier management, fetching, and analysis. Walk through the pseudocode for each component, emphasizing how they interact to satisfy constraints like BFS prioritization, rate limiting, and back-pressure. Conclude by discussing trade-offs and potential optimizations.

Pro tip: Explicitly call out how you handle failure modes (e.g., crashes during checkpointing) and ensure exactly-once semantics, as this demonstrates production-level thinking. Also, mention using a distributed queue like Kafka or SQS for scalability, which aligns with Amazon's infrastructure.

1. Clarify Requirements and Scale

Ask about expected scale (pages, hosts), latency requirements, and whether the system is distributed. Confirm constraints like robots.txt compliance, rate limits, and memory bounds.

2. High-Level Architecture

Sketch components: URL Frontier (priority queue with BFS ordering), Fetcher Pool (with per-host rate limiters and robots.txt cache), Analyzer Pool, and a Coordinator for back-pressure and checkpointing. Use bounded queues and disk-based storage for spillover.

3. Pseudocode for Core Components

Write pseudocode for the frontier (enqueue/dequeue with dedup), fetcher (respect robots.txt, rate limit, fetch, parse links), analyzer (process page), and coordinator (back-pressure, checkpointing). Highlight thread synchronization and disk spillover.

4. Address Constraints and Trade-offs

Explain how BFS is maintained (e.g., using multiple queues per depth), how dedup is done (Bloom filter + disk-based set), how back-pressure is implemented (bounded queues, blocking), and how graceful shutdown with exactly-once checkpointing works (write-ahead log, atomic commits).

5. Summarize and Discuss Extensions

Recap how the design meets all requirements, then mention potential improvements like distributed coordination, adaptive rate limiting, or using a database for frontier persistence.

Key Points to Mention

  • BFS prioritization via multiple FIFO queues per depth level, ensuring breadth-first discovery.
  • Robots.txt compliance: cache robots.txt per host with TTL, respect disallow rules, and handle fetch errors.
  • Per-host rate limiting: token bucket or leaky bucket per host, with a global rate limiter if needed.
  • Deduplication: use a Bloom filter for quick checks and a disk-based hash set for exact dedup, ensuring at-most-once processing.
  • Bounded memory with disk spillover: use bounded queues; when full, spill to disk (e.g., append to log-structured files) and reload when space frees.
  • Back-pressure: bounded queues between stages; fetchers block when analysis queue is full, and frontier blocks when fetch queue is full.
  • Graceful shutdown and exactly-once checkpointing: periodically checkpoint frontier state and processed URLs to disk; on restart, resume from last checkpoint, ensuring no duplicate processing via idempotent operations or transactional writes.

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

Q2

For the crawler design, define your core data structures for the frontier, the seen-set, and per-host token buckets. What are the big-O characteristics of each?

Algorithms & Data StructuresSystem Design
Author's notes

Felt okay here.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the crawler's requirements (scale, politeness, deduplication) to justify your data structure choices. Then describe each structure—frontier, seen-set, and per-host token buckets—with its operations and big-O complexities, and explain how they work together to ensure efficient and polite crawling.

Pro tip: Emphasize that the seen-set must be memory-efficient and support fast lookups; mention probabilistic structures like Bloom filters as a trade-off between memory and false positives, showing you understand real-world constraints.

1. Clarify requirements and assumptions

Ask about scale (billions of URLs), politeness constraints (per-host rate limits), and deduplication needs. State assumptions to guide data structure choices.

2. Design the frontier

Propose a priority queue (heap) for prioritizing URLs, or a distributed queue for scalability. Discuss operations: enqueue (O(log n) for heap, O(1) for queue) and dequeue (O(log n) or O(1)).

3. Design the seen-set

Use a hash set for exact deduplication with O(1) average lookup/insert, or a Bloom filter for memory efficiency with O(k) operations and false positives. Mention distributed options like Redis or Cassandra.

4. Design per-host token buckets

Use a hash map from host to token bucket (e.g., a counter with timestamps). Operations: check/update bucket in O(1) average time. Discuss concurrency and distributed coordination.

5. Summarize complexities and trade-offs

Recap big-O for each structure and discuss trade-offs (memory vs. accuracy, latency vs. throughput). Highlight how they integrate for efficient crawling.

Key Points to Mention

  • Frontier as a priority queue (heap) for politeness and prioritization, with O(log n) enqueue/dequeue.
  • Seen-set as a hash set for O(1) average lookup/insert, or Bloom filter for O(k) with false positives.
  • Per-host token buckets stored in a hash map for O(1) average access, with token refill logic.
  • Big-O complexities: frontier O(log n) or O(1), seen-set O(1) or O(k), token buckets O(1).
  • Trade-offs: memory vs. accuracy (Bloom filter), latency vs. throughput (priority queue vs. FIFO).
  • Scalability considerations: distributed data structures (e.g., Redis, Kafka) and concurrency control.

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

Q3

How would you prevent deadlocks and priority inversion in this crawler, and how would you detect and handle thread-safety bugs?

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

I went with lock-free queues for the frontier and fine-grained locks per host bucket rather than one global lock.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the crawler's architecture and concurrency model, then systematically address deadlock prevention (e.g., lock ordering, timeouts), priority inversion (e.g., priority inheritance, avoiding shared locks), and thread-safety bug detection (e.g., static analysis, stress testing, logging). Emphasize trade-offs and practical Amazon-scale considerations like monitoring and gradual rollouts.

Pro tip: Tie your answer to Amazon's leadership principles: show ownership by proposing a monitoring and alerting system for deadlocks, and insist on the highest standards by suggesting code reviews and automated tests for concurrency.

1. Clarify the concurrency model

Ask about the crawler's architecture: is it multi-threaded, multi-process, or distributed? Identify shared resources (e.g., URL frontier, visited set, rate limiters) and their access patterns.

2. Prevent deadlocks

Propose strategies like lock ordering, lock timeouts, and using lock-free data structures or atomic operations where possible. Mention avoiding nested locks and using a single global lock only if contention is low.

3. Mitigate priority inversion

Explain priority inheritance (e.g., in mutexes) or priority ceiling protocols. Alternatively, avoid priority inversion by not using priority-based scheduling for threads sharing locks, or by using separate queues for different priorities.

4. Detect thread-safety bugs

Describe static analysis tools (e.g., ThreadSanitizer, Coverity), dynamic analysis (stress testing with high concurrency), and runtime detection (assertions, logging lock acquisition order).

5. Handle and monitor

Outline a plan for handling detected bugs: reproduce, fix, add regression tests, and deploy with canary releases. Set up monitoring for deadlock detection (e.g., thread dumps, watchdog timers) and alerting.

Key Points to Mention

  • Lock ordering and hierarchical locking to prevent deadlocks
  • Priority inheritance and priority ceiling protocols for priority inversion
  • Lock-free data structures and atomic operations for scalability
  • ThreadSanitizer, Helgrind, and stress testing for detection
  • Watchdog timers and thread dumps for runtime deadlock detection
  • Trade-offs between performance, complexity, and correctness

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

Q4

BFS ordering breaks down when crawling many hosts simultaneously. How does this happen and what would you do to approximate true BFS?

System DesignTechnical Trade-offsAdaptability & Ambiguity
Author's notes

Didn't fully see this coming.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, explain why BFS ordering breaks down in a distributed crawl: multiple hosts are crawled in parallel, so pages from different depths are fetched concurrently, and the global FIFO queue is not strictly maintained. Then, propose a practical approximation using per-host queues with a global depth-based scheduler, and discuss trade-offs like politeness and throughput.

Pro tip: Emphasize that perfect BFS is impossible in a distributed system without sacrificing parallelism, so the goal is to approximate it while respecting politeness constraints and maximizing throughput. Mention that Amazon values customer obsession, so tie it back to delivering fresh, comprehensive results efficiently.

1. Clarify the problem

Explain that BFS requires visiting all nodes at depth d before depth d+1, but with many hosts crawled in parallel, the global order is lost because each host progresses at its own pace.

2. Identify the causes

Discuss factors like per-host politeness delays, varying response times, and the need for concurrent connections, which cause some hosts to advance to deeper levels while others are still at shallower levels.

3. Propose an approximation

Suggest using a global priority queue keyed by depth, with per-host queues to enforce politeness. The scheduler picks the shallowest available URL across hosts, approximating BFS.

4. Discuss trade-offs

Acknowledge that strict BFS would serialize crawling and reduce throughput; the approximation balances depth ordering with parallelism and politeness.

5. Conclude with impact

Summarize how this approach improves crawl freshness and coverage, aligning with business goals like comprehensive product indexing.

Key Points to Mention

  • BFS ensures shallow pages are crawled first, which is important for freshness and coverage.
  • Parallel crawling across hosts breaks global FIFO order due to independent host progress.
  • Politeness constraints (e.g., robots.txt, delay between requests to same host) exacerbate the issue.
  • A global depth-based priority queue with per-host queues can approximate BFS.
  • Trade-off: strict BFS reduces parallelism; approximation balances depth and throughput.
  • Amazon context: efficient crawling impacts product discovery and customer experience.

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

Q5

What metrics would you track to verify a 50%+ throughput improvement, and how would you design a controlled benchmark to prove it?

Product Analytics & MetricsA/B Testing & ExperimentationSystem Design
Author's notes

Pages crawled per second, queue depth over time, per-host fetch latency, analysis task lag, and CPU plus memory utilization.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the throughput metric precisely and the baseline, then outline a controlled benchmark design that isolates the change and accounts for variability. Emphasize statistical rigor (power analysis, confidence intervals) and operational metrics (latency, error rates) to ensure the improvement is real and not at the expense of other system qualities.

Pro tip: Prove the improvement with a confidence interval on the relative change and show that the lower bound exceeds 50%, not just the point estimate. Also, pre-register the analysis plan to avoid p-hacking concerns.

1. Define the metric and baseline

Clearly specify the throughput metric (e.g., requests per second, records processed per minute) and establish a stable baseline under representative conditions. Include secondary metrics like latency, error rate, and resource utilization to ensure no trade-offs.

2. Design the controlled experiment

Use a randomized controlled trial (A/B test) with the current system as control and the modified system as treatment. Ensure both groups run on identical hardware, with the same workload, and randomize the order of runs to mitigate time-based effects.

3. Determine sample size and power

Conduct a power analysis to determine the number of runs needed to detect a 50% improvement with sufficient statistical power (e.g., 80%) and significance level (e.g., 0.05). Account for variance in throughput measurements.

4. Analyze results with statistical rigor

Compare throughput between groups using appropriate tests (e.g., t-test or bootstrap) and report the effect size with confidence intervals. Verify that the lower bound of the confidence interval for the relative improvement exceeds 50%.

5. Validate and monitor

Replicate the benchmark in a production-like environment and monitor key metrics over time to ensure the improvement is sustained. Document the methodology and results for reproducibility.

Key Points to Mention

  • Throughput metric definition (e.g., requests per second, records processed per minute) and baseline measurement
  • Controlled experiment design: randomization, control/treatment groups, identical conditions
  • Statistical power analysis and sample size determination
  • Confidence intervals and hypothesis testing to prove >50% improvement
  • Secondary metrics: latency, error rates, resource utilization to avoid trade-offs
  • Reproducibility and monitoring to ensure sustained improvement

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