Amazon Software Engineer Interview Prep Guide
Everything Amazon actually asks Software Engineer candidates — concept walkthroughs, worked examples, and the real interview questions, drawn from candidate reports. Free to read.
Last updated

Your main focus is Amazon Leadership Principles/STAR depth plus Amazon-specific system design: AWS service tradeoffs and operational excellence, because behavioral has the thinnest engagement signal while system design is central for Amazon. You're self-rating 4/5 across coding, system design, and software engineering fundamentals, so arrays, intervals, LRU, OOD, cloud networking, and ML-adjacent material stay in brief review mode. The Amazon-specific highlights are LP deep dives, AWS primitives such as DynamoDB/SQS/S3/Kinesis-style choices, and production readiness through metrics, alarms, retries, and runbooks. With one month until interview, this plan keeps the first-pass cheatsheet budget around 85 minutes, leaving most prep time for timed coding drills, mock LP answers, and design practice.
Technical Screen — 38 min
Behavioral & Leadership
- Leadership Principles And STAR Stories (Focus) — covered in depth under Onsite below.
Coding & Algorithms
-
DFS/BFS Tree, Graph, And Grid Traversal — covered in depth under Onsite below.
-
Dynamic Programming And Memoization — covered in depth under Take-home Project below.
-
Greedy, Heaps, And Scheduling Optimization — covered in depth under Take-home Project below.
-
Arrays, Strings, Hash Maps, And Frequency Counting (Light review) — covered in depth under Take-home Project below.
System Design
-
AWS Service Primitives And Amazon Design Tradeoffs (Focus) — covered in depth under Onsite below.
-
Operational Excellence, Observability, And Production Readiness (Focus) — covered in depth under Onsite below.
-
Real-Time Top-K And Streaming Analytics — covered in depth under Onsite below.
Onsite — 39 min
Behavioral & Leadership
Leadership Principles And STAR Stories
Focus areaFocus area — Amazon weighs LP heavily, and your behavioral engagement is only one viewed question, so prioritize polished, metrics-backed STAR stories.

What's being tested
Amazon behavioral interviews test whether you can demonstrate Leadership Principles through concrete engineering judgment, not whether you can recite values. For a Software Engineer, the interviewer is probing how you debug ambiguous systems, make tradeoffs under pressure, own production outcomes, raise quality bars, and work across teams without authority. Strong answers show specific technical context, measurable impact, and personal accountability: what you did, why it mattered, what alternatives you considered, and what you learned. Expect deep follow-ups on details like failure modes, metrics, incident timelines, code-review decisions, and whether your actions would scale beyond one heroic fix.
Core knowledge
-
STAR means Situation, Task, Action, Result. For Amazon, the Action section should be the longest: roughly 10% context, 10% goal, 60% your decisions/actions, 20% measurable results and lessons.
-
Ownership stories should show you acted beyond your narrow ticket. Good SWE examples include fixing a flaky
`CI`pipeline, improving an unowned service’s`p99`latency, writing a runbook after an incident, or taking responsibility for a bad deployment even when another team contributed. -
Dive Deep requires technical specificity. Be ready to explain logs, dashboards, traces, database queries, thread dumps, memory profiles, cache behavior, retries, timeouts, race conditions, and why the first plausible root cause was wrong.
-
Customer Obsession for engineers usually maps to reliability, latency, correctness, accessibility, security, or developer experience. Tie work to concrete outcomes: reduced checkout errors from
`1.2%`to`0.3%`, cut`p95`API latency from`900ms`to`220ms`, or reduced support tickets by`35%`. -
Bias for Action is not “move fast and break things.” Strong answers show bounded risk: feature flags, canary deployments, rollback plans, read-only migrations, dark launches, rate limits, or temporary mitigations while a permanent fix is built.
-
Insist on the Highest Standards should include quality mechanisms, not perfectionism. Mention code reviews, test coverage, load testing, static analysis,
`SLO`alerts, backward-compatible APIs, migration validation, or eliminating an entire class of bugs through tooling. -
Invent and Simplify is especially relevant when you reduce operational complexity. Examples: replacing manual deployments with one-click pipelines, consolidating duplicate services, simplifying an API contract, removing a brittle dependency, or turning tribal knowledge into automation.
-
Have Backbone; Disagree and Commit should show respectful escalation using evidence. For SWE, evidence might include load-test results, error-budget burn, security risk, operational burden, or a prototype comparing two designs. Once a decision is made, show you supported execution.
-
Deliver Results stories need constraints. State the deadline, dependency, ambiguity, or resource limit. Then explain prioritization: what you cut, deferred, automated, delegated, or simplified to ship safely without hiding quality risks.
-
Earn Trust is demonstrated through transparency and follow-through. In engineering stories, this can mean posting an incident update, admitting a regression you caused, documenting tradeoffs, giving credit, asking for review early, or making a decision visible in an
`ADR`. -
Measured impact matters even when the story is behavioral. Use engineering metrics such as
`MTTR`,`MTTD`, deployment frequency, rollback rate,`p95`/`p99`latency, error rate, availability, test flakiness, build time, memory usage, CPU utilization, or defect escape rate. -
Follow-up readiness is critical. Interviewers often ask: “What exactly did you do?”, “What data did you inspect?”, “Who disagreed?”, “What would you do differently?”, “How did you know it worked?”, and “Was this really your contribution?”
Worked example
For “Answer Dive Deep and Ownership in LP interview”, a strong candidate should frame the story in the first 30 seconds as a production or near-production problem with measurable customer or operational impact. For example: “I’ll use a story where our order-status API had intermittent `5xx` spikes after a deployment; I was not the original owner, but I was on call and drove root cause, mitigation, and prevention.” Clarify the scale briefly: request volume, severity, affected customers, and whether there was an `SLA` or `SLO` at risk.
Organize the answer around four pillars: first, detection and triage; second, technical investigation; third, mitigation and communication; fourth, long-term prevention. In the investigation pillar, go beyond “I checked logs” and name the actual reasoning path: comparing deploy timestamps with error spikes, isolating one dependency, finding retry amplification, verifying with traces, and reproducing under load. A good tradeoff to flag is mitigation versus root cause: “I rolled back first to stop customer impact, then used the failed build in staging to preserve evidence and continue debugging.”
The result should include numbers: `5xx` rate dropped from `8%` to baseline, `MTTR` was `37 minutes`, and a follow-up change reduced similar incidents by adding timeout budgets, circuit breakers, and an alert on dependency saturation. Close with learning: “If I had more time, I would have added pre-production load tests for retry storms earlier and documented a dependency-failure checklist for the on-call rotation.” This shows you owned both the immediate fix and the systemic improvement.
A second angle
For “Answer Amazon-style leadership deep dives”, the same storytelling discipline applies, but the interviewer may focus less on one incident and more on decision-making, conflict, or influence. Suppose the story is about disagreeing with a proposed synchronous service call in a checkout path. The framing should emphasize the engineering tradeoff: synchronous simplicity versus availability risk, latency budget, and blast radius. Instead of centering the narrative on logs and root cause, center it on evidence, stakeholder alignment, and commitment after the decision. A strong answer would mention a prototype, `p99` latency estimates, failure-mode analysis, and how you either persuaded the team or committed to the chosen design while adding safeguards.
Common pitfalls
Pitfall: Giving a generic values answer instead of an engineering story.
A weak answer says, “I always take ownership and communicate well.” A stronger answer names the service, the bug, the metric, the decision you made, and the result. Amazon interviewers will keep drilling until they can separate your actual contribution from the team’s general effort.
Pitfall: Over-indexing on heroics and under-indexing on mechanisms.
“I stayed up all night and fixed production” may sound committed, but it can also signal fragile operations. Pair urgency with scalable mechanisms: alerts, runbooks, tests, deployment guards, code ownership, post-incident reviews, and prevention of repeat failures.
Pitfall: Hiding conflict, mistakes, or tradeoffs.
Perfect stories often sound rehearsed and shallow. It is usually better to say, “My first hypothesis was wrong,” “I shipped a mitigation with known limitations,” or “I disagreed with the design because of `p99` latency risk.” Then show how you used data, communicated clearly, and improved the system.
Connections
Interviewers often pivot from behavioral stories into system design, especially around reliability, scalability, and operational excellence. They may also ask for debugging deep dives, code quality tradeoffs, incident management, or cross-team design negotiation. Prepare each story so it can support both a leadership principle discussion and a technical follow-up.
Further reading
-
Amazon Leadership Principles — official source for the principles and the language interviewers use.
-
The Site Reliability Workbook — practical mechanisms for incident response, reliability, alerting, and operational ownership.
-
How Complex Systems Fail — Richard I. Cook — useful mental model for explaining incidents without oversimplifying root cause.
Practice questions
Coding & Algorithms
Coding is strong overall, but graph/grid traversal is frequent at Amazon and benefits from a few timed refreshers.

What's being tested
Graph traversal skill across trees, grids, and network-like graphs: choosing DFS, BFS, or Dijkstra based on reachability, shortest unweighted distance, or weighted cost. Interviewers probe whether you maintain correct state, avoid revisits, handle branching/obstacles/errors, and explain time/space complexity clearly.
Patterns & templates
-
BFS shortest path on unweighted graphs — use
queue,visited, and level counting;O(V + E)time,O(V)space. -
Multi-source BFS for spreading processes — enqueue all initial rotten/spoiled cells first; each BFS layer represents one time unit.
-
DFS path matching in an N-ary tree — recurse with
(node, index)state; backtracking is implicit, and duplicate values require sequence-position tracking. -
Grid traversal template — iterate four directions via
dirs = [(1,0),(-1,0),(0,1),(0,-1)]; validate bounds, obstacles, and visited cells. -
Dijkstra-style traversal for weighted cells — use
heapqwith(cost, r, c); mark finalized distances, not merely first-seen nodes. -
Web crawler BFS — normalize URLs, enforce same-domain scope, dedupe with
visited, and separate fetch failures/retries from traversal correctness. -
Complexity framing — trees are
O(n), grids areO(rows * cols), crawlers areO(pages + links)bounded by crawl limit and dedupe set.
Common pitfalls
Pitfall: Using DFS for shortest path in an unweighted grid without tracking all alternatives; BFS is the canonical shortest-step solution.
Pitfall: Marking weighted grid nodes visited when pushed into the heap; with Dijkstra, finalize when popped with the minimum known distance.
Pitfall: Matching N-ary tree paths by value only; repeated values mean your state must include the current sequence index.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Practice questions
-
Dynamic Programming And Memoization — covered in depth under Take-home Project below.
-
Greedy, Heaps, And Scheduling Optimization — covered in depth under Take-home Project below.
-
Arrays, Strings, Hash Maps, And Frequency Counting (Light review) — covered in depth under Take-home Project below.
System Design
Focus area — Amazon interviews reward practical AWS-flavored tradeoffs: DynamoDB, SQS, SNS, S3, Kinesis, caches, queues, and failure modes.
What's being tested
Interviewers probe your ability to map application requirements (throughput, latency, durability, ordering, cost, operational burden) to AWS building blocks and explain concrete tradeoffs. They expect clear choices among primitives like messaging, streaming, object storage, key-value stores, and serverless compute, plus patterns (idempotency, backpressure, batching) that make systems correct and resilient. Amazon cares because engineers must deliver scalable, cost-effective services that operate at high availability inside AWS constraints.
Core knowledge
- AWS primitives taxonomy — know the roles of
`S3`(durable object store),`DynamoDB`(managed key-value with single-digit-ms reads),`RDS/Aurora`(relational OLTP with ACID),`SQS`/`SNS`(queue/topic),`Kinesis`(streaming with ordered shards),`Lambda`(serverless compute),`EC2/ECS/EKS`(container/VM compute). - Delivery & ordering guarantees —
`SQS`standard: at-least-once, best-effort ordering;`SQS`FIFO: message-group ordering and deduplication window (not strict global ordering);`Kinesis`gives per-shard ordering and at-least-once delivery. - Consistency vs availability tradeoff — strong consistency (e.g.,
`RDS`transactions,`DynamoDB`strongly-consistent reads in-region) vs eventual (cross-region replication,`S3`object replace/delete semantics); pick based on correctness needs and latency budget. - Throughput primitives and scaling math — streaming throughput = shards * per-shard capacity (
`Kinesis`: writes ≈ 1 MB/s or 1000 records/s per shard; reads ≈ 2 MB/s). For batch-oriented queues, throughput often limited by consumer concurrency. - Storage semantics and durability —
`S3`: highly durable (~11 nines) object storage suitable for large immutable blobs and long-term logs;`EBS`for block-level,`EFS`for shared file access. Use`S3`for cheap durable log/backup. - Idempotency and uniqueness — design producers/consumers for idempotency using stable idempotency keys, dedup tables in
`DynamoDB`, or use`SQS`FIFO deduplication when appropriate; critical when primitives deliver at-least-once. - Transactional patterns — for cross-service consistency prefer outbox pattern (write-to-db + publish event) or use database transactions where possible; avoid distributed transactions across AWS services unless you accept complexity.
- Retry/backoff and error handling — use exponential backoff with jitter for retries; configure dead-letter queues (
`DLQ`) for`SQS`and`Lambda`to surface poison messages; implement circuit-breakers for downstream overload. - Cost & operational tradeoffs — serverless (
`Lambda`,`SQS`) reduces ops but can increase per-request cost and cold-start latency; provisioned services (`EC2`,`ECS`,`RDS`) give cost predictability and control for sustained high throughput. - Networking, latency, and data transfer cost — cross-AZ traffic generally free for most services but cross-region egress has measurable cost and higher latency; collocate producers and consumers in same region/AZ where latency and egress matter.
- Observability primitives — instrument
p50,p95,p99latency, error rates, throughput; use`CloudWatch`metrics,`X-Ray`traces for request graphs, and`CloudTrail`for control-plane audit. - Security and operational constraints — use
`IAM`least-privilege,`KMS`for encryption at rest, and VPC endpoints for private service access; design for key rotation and least-exposed network surfaces.
Worked example — "Design a scalable pub/sub notification service using AWS primitives"
First 30s framing questions: clarify throughput (messages/sec and size), ordering needs, exactly-once vs at-least-once requirements, multi-region delivery, and latency SLOs. Skeleton of a strong answer: (1) pick a publish mechanism (`SNS` for fanout) and durable delivery targets (`SQS` queues per subscriber or `Lambda` for direct processing); (2) design for scale and failure (each subscriber uses an `SQS` queue with `DLQ` and visibility timeout tuned to processing time); (3) ensure correctness (idempotency keys and optional `FIFO` queues when ordering matters); (4) monitoring and cost controls (`CloudWatch` alarms, delivery metrics, `DLQ` alerts). Explicit tradeoff: using `SNS`→`SQS` scales fanout with decoupling and durability but yields at-least-once delivery — if subscribers require strict exactly-once or global ordering, you'd need `SQS` FIFO or end-to-end deduplication at consumers, increasing latency and reducing throughput. Close: "If I had more time I'd prototype high-load scenarios, tune VisibilityTimeout and batch sizes, add per-queue concurrency autoscaling, and model cost at expected QPS."
A second angle — "Design an order ingestion pipeline with exactly-once semantics across microservices"
Same AWS primitives behave differently: here ordering and exactly-once matter per order ID. Candidate options: use `SQS` FIFO to preserve order and eliminate duplicates within the deduplication window, or use the outbox pattern in the order service (write order and journal event in one DB transaction, then publish to `Kinesis` for downstream consumers). Key decisions: prefer transactional outbox plus at-least-once consumer with idempotent handlers if you want strong durability without distributed transactions; prefer `Kinesis` when you need ordered replay and stream retention for reprocessing. Also consider `DynamoDB` streams + `Lambda` for scalable change-data-capture, but remember cross-region replication is eventual — account for potential reordering at global scale.
Common pitfalls
Pitfall: Choosing
`SQS`standard because it's "faster" without addressing deduplication — leads to duplicate processing bugs in stateful consumers. Always design for idempotency or use FIFO when ordering/dedup is required.
Pitfall: Treating
`Lambda`concurrency as unlimited — failing to provision reserved concurrency or control downstream resources (`DynamoDB`/`RDS`) causes throttling spikes and cascading failures; model concurrency vs downstream provisioned capacity.
Pitfall: Ignoring monitoring and
`DLQs`— assuming success if no visible errors; configure`DLQs`, per-queue metrics, trace sampling, and automated alerts to detect poison messages and backlog growth early.
Connections
Interviewers may pivot to capacity planning and cost optimization (provisioned vs on-demand capacity decisions), or to data modeling for `DynamoDB` (partition keys, GSIs, hot partitions). They may also explore observability (tracing cross-service flows with `X-Ray`) or security (`IAM` roles and `KMS` encryption) depending on weakness in your tradeoff rationale.
Further reading
- AWS Well-Architected Framework — concise pillars and service selection guidance.
- Designing Data-Intensive Applications — covers fundamentals of ordering, replication, and stream processing that map to AWS primitives.
Practice questions
Focus area — Amazon values ownership after launch; emphasize SLIs, alarms, dashboards, runbooks, on-call safety, retries, and rollback plans.
What's being tested
Interviewers are probing whether you can make a service production-ready: instrument code for observability, reason about real-user signals, and design safe deployment and failure-handling at the application level. They want to see practical choices—what metrics/logs/traces you emit, where to put timeouts/retries/idempotency, and how your code helps reduce MTTR without depending on platform teams.
Core knowledge
-
Observability basics: logs, metrics, and traces are complementary signals; logs for details, metrics for aggregation/alerts, traces for end-to-end latency and dependency topology. Instrument all three at the application layer.
-
Structured logging: emit JSON logs with stable fields like
request_id,user_id,route,status, andduration_msso downstream systems can parse and correlate easily. -
Correlation IDs / context propagation: generate a
request_idat edge and propagate via headers (e.g.,X-Request-ID) into logs and tracing spans to join signals across services. -
Metric types: use counters for event counts, gauges for current state, and histograms for latency distributions; prefer histograms for
p95/p99computation. For first-time use, instrument business and system metrics. -
p99stability: tail-percentiles need large sample sizes; rule-of-thumb: keep ≥1000 samples per evaluation window or use histogram-extrapolation to avoid noisy alerts. -
Tracing: instrument important spans using
OpenTelemetry-compatible libraries; capture errors and span attributes (e.g., DB host, query id) but avoid PII. -
Timeouts & retries: apply per-call timeouts, exponential backoff with capped retries, and circuit breakers at client libraries to prevent cascading failures; ensure retries are idempotent or guarded.
-
Health endpoints: expose
/healthz(liveness) and/readyz(readiness) that check local critical dependencies quickly without triggering heavy work. -
Safe schema changes & migrations: perform backwards-compatible schema changes (add nullable columns, dual-writes reads, phased rollouts), and include migration toggles to rollback quickly.
-
Deployment strategies: prefer canary or blue/green with small cohorts and automatic rollback on predefined error-rate/latency thresholds; use feature flags for risky behavior changes.
-
Runbooks & alerts: alert on actionable signals with a clear owner and runbook link; avoid high-noise alerts by combining metrics (error rate × traffic) and using short burn-rate windows for fast detection.
-
Testing for production: unit tests + integration tests + contract tests for downstream services, plus pre-production load/smoke tests and targeted chaos tests for degradation paths.
Worked example — "Design an observable HTTP microservice that meets production readiness"
First 30s framing: ask what SLAs (latency/error targets) the service must meet, main downstream dependencies, expected traffic shape, and whether any data is PII. State assumptions (e.g., typical QPS, stateful vs stateless). Skeleton of answer: (1) instrumentation plan (structured logs, business counters, latency histograms, trace spans), (2) failure handling (timeouts, retries, idempotency, circuit breakers), (3) deployment & rollout (canary + feature flags + automated rollback), (4) health/check endpoints and runbooks. A concrete tradeoff: sampling traces reduces cost but can hide rare tail issues—pick head-based sampling plus full-trace capture on errors (error-based sampling). Implementation details you'd call out: use OpenTelemetry for traces, expose duration_ms histogram with explicit buckets, propagate request_id to logs and traces, and implement per-route timeouts. Close by saying: if more time, I'd sketch concrete alert thresholds, write example prometheus rules, and add a short runbook template for 5 common failures.
A second angle — "You own a background job processor that occasionally stalls; how do you make it observable and production-ready?"
Re-frame signals: background processors need different metrics—queue depth, job processing rate, job latency, and failure/error classes. Instrument job lifecycle events (enqueue, start, success, failure, retry) and emit histogram of processing duration. Add a liveness probe that detects if the worker thread pool is starved or stuck. For stalling, correlate queue growth with per-worker CPU/memory and external dependency latency (DB locks, blocking RPCs). Design retries to be idempotent and add a dead-letter queue with diagnostic metadata. For rollout, use versioned workers processing a small fraction of queue first. The same observability principles (structured logs, request_id propagation, histograms, runbooks) apply but with queue-specific metrics and alerting conditions (e.g., sustained queue growth × drop in consumption).
Common pitfalls
Pitfall: Emitting only error counts without context. Counting “5xx”s without per-endpoint or per-client breakdown produces noisy, un-actionable alerts. Always tag metrics by meaningful dimensions.
Pitfall: Instrumenting everything verbatim. Over-instrumentation creates high cardinality metrics that blow storage and alerting; limit high-cardinality tags (avoid per-user or per-order id in metrics).
Pitfall: Treating traces as optional. Relying solely on logs/metrics makes diagnosing latency and distributed causality far slower; capture at least sampled traces and always capture full traces for errors.
Connections
This topic commonly leads to pivots into distributed tracing & context propagation, deployment strategies (canary/blue-green), and SRE/SLI-SLO discussions; be ready to explain why you chose application-level mitigations versus platform-level controls.
Further reading
-
OpenTelemetry Spec — vendor-neutral guidance and API/SDK patterns for traces, metrics, and logs.
-
Site Reliability Engineering (Google) — practical perspective on SLIs/SLOs and incident response that informs production-readiness decisions.
Practice questions
You have strong system-design engagement, but Amazon-scale ranking and stream aggregation are worth structured practice.

What's being tested
These interviews test whether you can design low-latency streaming analytics that maintain accurate or approximate rankings while events arrive continuously, out of order, and at high volume. The interviewer is probing for practical distributed-systems judgment: how you partition work, maintain state, bound memory, recover from failures, and serve fresh answers under `p99` latency targets. Amazon cares because many systems need near-real-time counters and rankings: best-selling products, ad clicks, abuse signals, log histograms, popular searches, and operational dashboards. A strong Software Engineer answer balances correctness, scalability, simplicity, and operational failure modes instead of just naming `Kafka` plus a database.
Core knowledge
-
Top-K frequency tracking usually means maintaining the K most frequent keys over a stream: product IDs, search prefixes, ad IDs, log fields, or URLs. Exact global top-K requires counting every key, which is feasible for bounded cardinality but expensive when unique keys reach millions or billions.
-
Exact counting uses a hash map from key to count plus a min-heap of size K for candidates. Updates are for the counter and when heap membership changes; memory is for N distinct keys, which may be acceptable up to ~10M keys depending on key size and retention.
-
Approximate heavy-hitter algorithms trade precision for bounded memory. Count-Min Sketch estimates frequency with error bounded by using width and depth ; Space-Saving keeps M counters and works well when you only need likely top items.
-
Window semantics are central. A tumbling window such as “top-K per minute” is simpler because events belong to one bucket; a sliding window such as “last 15 minutes updated every second” requires bucketed subwindows, incremental expiration, or time-decayed counts.
-
Event time differs from processing time. If ranking by when a click actually happened, use event timestamps and accept late arrivals up to a watermark delay, for example “finalize window after 2 minutes of lateness.” If ranking by ingestion time, results are simpler but less faithful during client buffering or retries.
-
Partitioning strategy decides scalability. Hash partition by item key when aggregating counts for each key, then periodically emit local top-K candidates to a global reducer. Partitioning by user or session helps deduplication, but final top-K by item then requires a second aggregation stage.
-
Hot keys are a real failure mode. If one product, log category, or query prefix receives 30% of traffic, a single partition can overload. Mitigations include key salting, local pre-aggregation, adaptive partitioning, or separating ultra-hot keys into dedicated paths.
-
State management needs a clear recovery story. Stream processors like
`Apache Flink`,`Kafka Streams`, or`Spark Structured Streaming`keep local state backed by checkpoints or changelogs. Without checkpointing, a worker crash can reset counts or double-apply replayed events. -
Idempotency and deduplication matter for click and log systems. If producers retry, events may arrive twice; use an event ID, request ID, or composite key like
(user_id, item_id, timestamp, nonce)with bounded dedup state. Exact dedup across an infinite stream is impossible without unbounded memory. -
Serving path should be separated from computation. The streaming job writes materialized results like
(window, dimension, rank, item, count)to a low-latency store such as`Redis`,`DynamoDB`,`Cassandra`, or`OpenSearch`; read APIs should not scan raw events to answer top-K. -
Freshness versus correctness is a first-class tradeoff. For example, serving provisional top-K every second with watermark-corrected final values later may be better than waiting two minutes for perfect completeness. Make the SLA explicit: “results within 5 seconds, tolerate 0.5% error, late events included for 10 minutes.”
-
Autocomplete top-K combines streaming counts with prefix indexing. A common approach stores a trie or prefix table where each prefix maps to top suggestions; updates increment query/item counts and refresh affected prefixes. This is fast for reads but expensive for writes because one term touches prefixes.
Worked example
For Design rolling-window top-K click tracker, start by clarifying the API and SLA: “Are we returning top-K items globally or per advertiser/category? What is the window length, expected QPS, acceptable staleness, and do clicks have unique IDs?” Then declare assumptions, such as 1M clicks/sec, 15-minute sliding window, K=100, results refreshed every second, and late events accepted for 2 minutes.
A strong answer can be organized around four pillars: ingestion, aggregation, state/windowing, and serving. For ingestion, describe clients or edge services publishing click events into `Kinesis` or `Kafka`, with event ID, item ID, timestamp, and optional dimensions. For aggregation, use a stream processor such as `Flink` that partitions by item ID and maintains per-item counts in small time buckets, for example 900 one-second buckets for a 15-minute window. For top-K, each partition computes local candidates, then a second-stage reducer merges candidates and publishes the global ranked list.
The key design decision is exact versus approximate. Exact rolling counts require maintaining all active item counts and expiring old buckets, which is straightforward if active item cardinality is manageable; for very high cardinality, use Space-Saving or Count-Min Sketch to bound memory, while clearly explaining possible ranking errors near the cutoff. Serving should use a materialized store like `Redis` sorted sets or a `DynamoDB` table keyed by window and dimension, not recompute from raw clicks per request. Close by saying that with more time you would cover multi-region failover, backfill/reconciliation from durable logs, and observability metrics like ingestion lag, watermark lag, dropped duplicates, and `p99` query latency.
A second angle
For Implement autocomplete with top-K suggestions, the same core idea appears, but the read path becomes more latency-sensitive and prefix-specific. Instead of computing one global top-K, you maintain top suggestions for many prefixes, often with a trie, finite-state transducer, or prefix-to-candidates index. Updates are more expensive because a query like “headphones” affects h, he, hea, and every longer prefix, so many systems batch updates or separate real-time trending boosts from a slower offline rebuild. The tradeoff shifts from stream-window correctness to memory layout, Unicode normalization, case folding, deletion handling, and sub-10ms lookup latency.
Common pitfalls
Pitfall: Treating top-K as “just sort all events.”
Sorting raw events or scanning all counts on every query is the tempting simple answer, but it fails immediately at streaming scale. A better answer maintains incremental state: counters, heaps, sketches, or precomputed materialized rankings that make reads cheap.
Pitfall: Ignoring window and time semantics.
Saying “keep a counter per item” is incomplete if the question asks for a rolling 5-minute or 24-hour view. You need to explain how counts expire, whether timestamps use event time or processing time, and what happens to late events after a watermark.
Pitfall: Naming technologies without showing data flow.
An answer like “use `Kafka`, `Flink`, and `Redis`” sounds plausible but shallow. Interviewers want to hear what each component does, what state it owns, how data is partitioned, how failures are recovered, and where the top-K is actually computed.
Connections
Interviewers often pivot from streaming top-K into rate limiting, distributed counters, leaderboards, log analytics, or search/autocomplete indexing. They may also ask about consistency models, checkpointing, backpressure, or approximate data structures such as Bloom filters, HyperLogLog, Count-Min Sketch, and reservoir sampling.
Further reading
-
Streaming Systems by Tyler Akidau, Slava Chernyak, and Reuven Lax — the best practical treatment of event time, watermarks, windows, and triggers.
-
Count-Min Sketch paper: “An Improved Data Stream Summary” — foundational algorithm for approximate frequency estimation in large streams.
-
Space-Saving algorithm: “Efficient Computation of Frequent and Top-k Elements in Data Streams” — directly relevant to memory-bounded heavy-hitter tracking.
Practice questions
Your system design rating is high, but onsite schedulers require crisp coverage of leases, retries, idempotency, and recovery.
What's being tested
Interviewers are probing whether you can design a reliable distributed scheduler that turns future-time requests into actual execution while handling scale, failures, duplicate delivery, and clock/time-zone edge cases. For Amazon-style systems, this matters because many services depend on deferred work: retries, reminders, payments, fulfillment workflows, cleanup, batch fanout, and SLA-driven automation. A strong Software Engineer answer shows you can separate job definition, schedule computation, durable persistence, dispatch, and worker execution, then reason about the failure modes between each boundary. The interviewer is not looking for a single “perfect” architecture; they want crisp tradeoffs around correctness, latency, throughput, and operability.
Core knowledge
-
One-off jobs and recurring jobs should be modeled differently. A one-off job stores
run_at; a recurring job stores a schedule expression such ascron,interval, orrate, plustimezone,next_run_at, and recurrence metadata. Store future occurrences lazily rather than materializing infinite schedules. -
Durable storage is the source of truth. Use
DynamoDB,Postgres,MySQL, or similar to persistjob_id,tenant_id,run_at,payload_ref,status,attempt_count,dedupe_key, and timestamps. A scheduler that only keeps jobs in memory loses work on restart and usually fails the reliability bar. -
Scheduling algorithms depend on scale and latency targets. A single-node min-heap works for small systems, with
O(log n)insert and pop. At larger scale, use time-bucketed partitions, database range scans onrun_at, or a hierarchical timing wheel for high-throughput near-future timers. -
Polling plus claiming is a common durable pattern. Scheduler nodes query due rows where
run_at <= now()andstatus = SCHEDULED, then atomically transition toCLAIMEDusing compare-and-swap,SELECT ... FOR UPDATE SKIP LOCKED, or conditional writes. Claiming prevents many schedulers from dispatching the same job simultaneously. -
Sharding keeps due-job scans bounded. Partition by time bucket and hash, for example
bucket = floor(run_at / 60s)andshard = hash(job_id) % N. This gives roughly and avoids one hot partition for a popular timestamp like midnight. -
Delivery semantics are usually at-least-once, not exactly-once. Network failures make “did the worker execute?” ambiguous. Design for duplicate dispatch using idempotency keys, dedupe tables, conditional state transitions, and business-level safeguards rather than promising exactly-once execution.
-
Idempotency belongs at the job effect boundary. If the job sends an email, charges a card, or updates an order, pass a stable
idempotency_keyto the downstream service. Stripe-style idempotency keys are a useful mental model: repeated requests with the same key should produce one logical effect. -
Retries need bounded policy, not infinite loops. Store
attempt_count,max_attempts,last_error, andnext_retry_at. Use exponential backoff with jitter, e.g.delay = min(base * 2^attempt, max_delay) + random_jitter, to avoid thundering herds after regional or dependency outages. -
Leases handle scheduler and worker crashes. A claimed job should have
lease_until; if a node dies, another node can reclaim it after the lease expires. Use fencing tokens or monotonically increasingclaim_versionto prevent stale workers from committing after their lease is no longer valid. -
Recurring schedules require careful time handling. Store timestamps in UTC, but preserve the user’s
timezonefor computing the next local occurrence. Daylight Saving Time creates nonexistent times, duplicated times, and “last day of month” ambiguity; state your policy explicitly. -
Queues decouple dispatch from execution. The scheduler can enqueue due work into
SQS,Kafka,RabbitMQ, or an internal work queue, while workers consume and execute. Note limits:SQSdelay queues are useful for short delays but max delay is 15 minutes, so long-term scheduling still needs durable storage. -
Observability should include correctness and latency signals. Track
schedule_lag = dispatch_time - run_at, queue depth, due jobs per shard, claim conflicts, retry rate, dead-letter count, worker success rate, andp99dispatch latency. These metrics reveal hot shards, stuck schedulers, and downstream dependency failures.
Worked example
For “Design a scalable job scheduler”, a strong candidate would start by clarifying the scale and semantics: “Are jobs one-off, recurring, or both? What is acceptable scheduling latency, seconds or minutes? Is execution at-least-once acceptable if workers are idempotent? What job volume and payload size should I assume?” Then they might declare assumptions: 100M stored jobs, 100K due per minute at peak, second-to-minute precision, and at-least-once delivery.
The answer should be organized around four pillars: API and data model, durable scheduling store, scheduler/dispatcher architecture, and worker execution with retries and idempotency. For the API, propose CreateJob, CancelJob, GetJob, and maybe CreateRecurringSchedule, with stable job_id and optional client-provided dedupe_key. For storage, describe a table indexed by run_at or time buckets, plus sharding by hash to avoid a single partition scanning all due work.
For dispatch, explain that multiple scheduler nodes poll assigned shards, atomically claim due jobs, enqueue them to a work queue, and mark them dispatched only after successful enqueue. For workers, describe idempotent execution, retry with backoff, and a dead-letter state after max_attempts. One tradeoff to flag explicitly: scanning durable storage every second is simple but expensive at very high scale; time buckets or a timing wheel reduce scans but add complexity in rebalancing and recovery. Close by saying that with more time you would drill into multi-region behavior, recurring-job DST rules, operational dashboards, and backpressure during dependency outages.
A second angle
For “Design delayed job scheduler (LLD)”, the same concepts apply, but the interviewer is likely pushing for lower-level class design and concurrency behavior. Instead of starting with multiple regions and millions of tenants, focus on interfaces like JobStore, DelayQueue, SchedulerLoop, WorkerPool, and RetryPolicy. You should be ready to discuss whether the in-memory structure is a priority queue, delay queue, or timing wheel, and how it reloads from durable storage after restart. The key distinction is that an LLD answer needs concrete state transitions, locking or atomic update behavior, and testable components rather than only boxes on an architecture diagram. You can still mention distributed concerns, but anchor them in methods such as claimDueJobs(now, limit), extendLease(jobId, token), and completeJob(jobId, token).
Common pitfalls
Pitfall: Promising exactly-once execution.
A tempting answer is “the scheduler will ensure each job runs exactly once.” In distributed systems, a scheduler can crash after dispatching but before recording success, or a worker can complete while the acknowledgment is lost. A better answer is: “The scheduler provides at-least-once delivery, and downstream effects are protected with idempotency keys and conditional writes.”
Pitfall: Treating time as simple.
Many candidates say “store a cron expression and run it at the right time” without addressing time zones, DST, leap days, or clock skew. Stronger candidates store execution timestamps in UTC, preserve the user’s intended timezone for recurrence computation, use NTP-synchronized clocks, and state a policy for nonexistent or duplicated local times.
Pitfall: Drawing components without explaining state transitions.
A box diagram with API -> DB -> Queue -> Workers is not enough. The interviewer needs to hear how a job moves from SCHEDULED to CLAIMED to ENQUEUED to RUNNING to SUCCEEDED or FAILED, and what happens if a process dies between any two steps.
Connections
This topic often pivots into distributed queues, leader election, workflow orchestration, rate limiting, and idempotent API design. Be prepared to compare a custom scheduler with managed systems such as SQS, EventBridge Scheduler, Quartz, Airflow, or Temporal, especially around durability, retries, dependencies, and operational complexity.
Further reading
-
Designing Data-Intensive Applications — excellent background on replication, partitions, logs, consistency, and failure handling in distributed systems.
-
The Google File System paper — useful for understanding leases, master coordination, and failure-tolerant distributed design patterns.
-
Amazon Builders’ Library: Timeouts, retries, and backoff with jitter — directly relevant to retry policy, overload control, and avoiding retry storms.
Practice questions
Take-home Project — 8 min
Coding & Algorithms
Even with a 4/5 coding rating, DP needs deliberate recurrence practice for Amazon-style variants and take-home optimization.

What's being tested
Dynamic programming here means recognizing overlapping subproblems, defining a compact state, and proving the recurrence before coding. Interviewers are probing whether you can move between top-down memoization, bottom-up tabulation, graph ordering, and string segmentation without double-counting or exponential blowups.
Patterns & templates
-
Top-down memoization with
`dfs(i, remaining)`or`dfs(index)`— cache states in`dict`; usually reduces exponential recursion toO(states * transition_cost). -
Subset-sum/count DP — transform target-sign problems into
sum(P) = (total + target) / 2; handle parity, negative targets, and zeros carefully. -
Word break DP —
dp[i] = any(dp[j] and s[j:i] in words);O(n^2)substrings, often improved with max word length. -
Trie-guided segmentation — walk forward from each valid
`i`through a`Trie`; avoids checking impossible prefixes and reduces wasted substring hashing. -
DAG dynamic programming — process nodes in topological order; for bounded path length use
dp[steps][node]or rolling arrays forO(V)space. -
Concatenated words template — sort by length, build a
`set`incrementally, and run word-break while preventing the whole word from counting as itself. -
Counting vs existence —
sum(...)for number of ways,any(...)for feasibility,parent/backtracking arrays for producing actual segmentations.
Common pitfalls
Pitfall: Treating zeros like normal numbers in target-sum counting; each zero doubles the number of valid expressions.
Pitfall: Using plain recursion for word segmentation or DAG paths; without memoization, repeated suffixes or subpaths explode exponentially.
Pitfall: Returning
Truefor a concatenated word because it exists in the dictionary; require at least two smaller component words.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Practice questions
Amazon commonly asks scheduling and resource-allocation problems; practice proof of greedy choice, heap use, and complexity.

What's being tested
These problems test greedy choice, priority-queue invariants, and efficient array reasoning under ordering constraints. Interviewers are probing whether you can replace brute-force scans or pairings with O(n log n) or O(n) structures, justify correctness, and handle duplicates, empty inputs, and boundary cases cleanly.
Patterns & templates
-
Monotonic stack for nearest-smaller relationships —
O(n)time,O(n)space; decide strict<versus<=before coding duplicates. -
Fenwick tree or segment tree for rightmost-smaller queries — coordinate-compress values, store max index, query values
< a[i]inO(log n). -
Two heaps for streaming median — max-heap lower half, min-heap upper half; rebalance after every
addNum()to keep sizes within one. -
Greedy resource allocation — sort counts/capacities, consume smallest feasible requirement first; prove exchange argument, not just “seems optimal.”
-
Heap scheduling template — sort events by start time, push active candidates into
heapq, pop expired or highest-priority item; usuallyO(n log n). -
Pairing optimization — sort both sides or sort by constraint then use a heap; watch whether objective is max sum, min operations, or feasibility.
-
Range-update minimization — reason on adjacent differences, not full arrays; difference arrays often turn repeated interval operations into linear accounting.
Common pitfalls
Pitfall: Treating “nearest smaller” and “rightmost smaller” as the same problem; the former is usually stack-based, the latter often needs indexed value queries.
Pitfall: Using Python
heapqas a max-heap without negating priorities, or forgetting tie-breaking when equal priorities affect deterministic output.
Pitfall: Giving a greedy algorithm without a correctness argument; state the invariant or exchange proof before moving to implementation details.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Practice questions
Light review — You rated coding 4/5 and gave no weakness signal here, so keep this to quick fluency and edge-case review.

What's being tested
Array/string counting questions test whether you can turn brute-force comparisons into linear or near-linear passes using prefix/suffix state, two pointers, hash maps, and frequency vectors. Interviewers are probing correctness under duplicates, zeros, negative values, collisions, and boundary cases—not just happy-path O(n) code.
Patterns & templates
-
Prefix/suffix accumulation — compute left-to-right and right-to-left products/counts in
O(n)time; avoid division and handle zeros explicitly. -
Two-pointer scan on sorted arrays — move
l/rbased on sum comparison; skip duplicate values when returning unique pairs. -
Frequency map counting — use
dict,HashMap, orCounterfor character/item counts; compare vectors inO(k)wherekis alphabet size. -
Fixed alphabet arrays — prefer
int[26]orint[128]for lowercase/ASCII strings; faster and simpler than hash maps when domain is bounded. -
Partition state tracking — maintain left/right distinct-character counts as a split moves; update counts carefully when a frequency reaches zero.
-
Modulo reasoning — maximize distinct remainders by tracking used residues in a set; remember residues range from
0tok - 1. -
Hash map internals — know hashing, buckets, collisions, load factor, resizing, and worst-case
O(n)lookup; mention concurrency concerns when relevant.
Common pitfalls
Pitfall: Using division in product-except-self fails when zeros appear and may violate the stated constraint.
Pitfall: Returning duplicate pairs from a sorted array because you advance pointers but do not skip repeated values.
Pitfall: Treating hash map operations as always
O(1)without acknowledging collisions, resizing cost, and adversarial keys.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Practice questions