← Amazon Interview Insights

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

SeniorPrefer not to say
Jun 2026

Summary

System design round at Amazon focused entirely on a locker management system. The question had a lot of moving parts and I felt like I was playing catch-up the whole time trying to cover concurrency and persistence before the hour ran out.

Questions Asked (5)

Q1

Design a locker management system for Amazon Locker OS that assigns the best-fitting available locker when a courier arrives with a package. Define what 'best fit' means, specify core operations, data structures, and analyze time and space complexity.

System DesignAlgorithms & Data StructuresTechnical Trade-offs
Author's notes

I started with the obvious stuff: exact size match first, then upsize if nothing's available, small to medium to large in that order.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and defining 'best fit' as minimizing wasted space (e.g., smallest locker that fits the package) while considering operational constraints like locker availability and courier speed. Then outline core operations (assign, release, query) and choose data structures (e.g., balanced BST or segment tree) to efficiently find the best-fit locker. Finally, analyze time and space complexity and discuss trade-offs.

Pro tip: Emphasize that 'best fit' should be configurable based on business priorities (e.g., minimizing wasted space vs. maximizing locker utilization) and mention real-world constraints like package dimensions, locker sizes, and concurrent access.

1. Clarify Requirements and Define 'Best Fit'

Ask clarifying questions about locker sizes, package dimensions, assignment criteria, and system constraints. Define 'best fit' as the smallest locker that can accommodate the package, possibly with tie-breakers like proximity to entrance.

2. Define Core Operations and Data Structures

Specify operations: assignLocker(package), releaseLocker(lockerId), and possibly queryAvailability. Choose data structures like a segment tree or balanced BST keyed by locker size to efficiently find the best-fit locker.

3. Design the Algorithm for Best-Fit Assignment

Describe how to find the smallest available locker that fits the package. For example, use a segment tree to query the minimum size >= package size, or maintain sorted sets of available lockers by size.

4. Analyze Time and Space Complexity

Analyze the complexity of each operation: assignment O(log n) with a balanced BST or segment tree, release O(log n), and space O(n) for storing lockers. Discuss trade-offs between different data structures.

5. Discuss Scalability and Trade-offs

Address concurrency, distributed lockers, and potential optimizations like caching or sharding. Discuss trade-offs between optimal best-fit and simpler approaches like first-fit.

Key Points to Mention

  • Definition of 'best fit': smallest locker that fits the package to minimize wasted space, with possible tie-breakers.
  • Core operations: assign locker, release locker, and query available lockers.
  • Data structures: balanced BST (e.g., TreeSet) or segment tree for efficient best-fit search.
  • Time complexity: O(log n) for assignment and release, O(1) for release if using direct reference.
  • Space complexity: O(n) for storing locker states.
  • Trade-offs: best-fit vs. first-fit, handling concurrency, and scalability across multiple locker locations.

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

Q2

How would you handle concurrency in this system, specifically simultaneous couriers trying to assign lockers at the same time? Address race conditions, idempotency, and fairness.

System DesignTechnical Trade-offsAPI & Integrations
Author's notes

This is where I spent most of my time and still felt shaky.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements and constraints, then propose a layered solution: use database transactions with row-level locking or optimistic concurrency control to prevent race conditions, design idempotent APIs to handle retries safely, and implement a fair queuing mechanism (e.g., FIFO with timestamps) to ensure couriers are served in order. Discuss trade-offs between consistency, latency, and scalability, and mention how you would test for concurrency issues.

Pro tip: Emphasize idempotency keys and conditional writes (e.g., 'assign locker only if status is available') to avoid double-assignment, and mention that fairness can be achieved with a distributed lock or a queue service like Amazon SQS with FIFO semantics.

1. Clarify requirements and constraints

Ask about expected concurrency level, consistency requirements, and whether fairness is strictly FIFO or just no starvation. This shows you don't jump to solutions prematurely.

2. Prevent race conditions with concurrency control

Propose using database transactions with SELECT FOR UPDATE or optimistic locking (version numbers) to ensure only one courier can assign a locker at a time. Discuss trade-offs like contention and retries.

3. Ensure idempotency for retries

Design the assignment API to be idempotent using idempotency keys, so duplicate requests (e.g., from network retries) don't result in multiple assignments. Mention storing the key with a unique constraint.

4. Implement fairness in locker assignment

Use a FIFO queue (e.g., SQS FIFO) or timestamp-based ordering to process requests in the order received, preventing starvation. Alternatively, use a distributed lock with fair queuing.

5. Discuss trade-offs and testing

Compare approaches (e.g., pessimistic vs optimistic locking, centralized vs distributed locks) and explain how you would test concurrency (load tests, chaos engineering).

Key Points to Mention

  • Race conditions: use database transactions with row-level locking (SELECT FOR UPDATE) or optimistic concurrency control (versioning).
  • Idempotency: implement idempotency keys and conditional writes to ensure repeated requests don't cause duplicate assignments.
  • Fairness: use FIFO queues or timestamp-based ordering to process requests in order and prevent starvation.
  • Trade-offs: discuss latency vs consistency, contention, and scalability of different locking strategies.
  • Distributed systems: mention distributed locks (e.g., Redis Redlock) or Amazon SQS FIFO for cross-service coordination.
  • Testing: include concurrency tests, load testing, and monitoring for lock contention and retries.

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

Q3

Describe the persistence layer and failure recovery strategy for this locker system. What happens if the service crashes mid-assignment?

System DesignData Modeling
Author's notes

Went with a relational schema pretty quickly: lockers table with status and size, assignments table with locker ID, package ID, timestamps.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the data model and storage choices for lockers and assignments, emphasizing durability and consistency. Then explain the assignment flow with transactional guarantees and idempotency, and finally describe failure recovery mechanisms like write-ahead logging, retries, and reconciliation. Use a concrete example of a crash mid-assignment to illustrate how the system recovers without double-assignment or data loss.

Pro tip: Tie your design to Amazon's leadership principles by highlighting customer trust (no lost packages) and operational excellence (automated recovery, minimal manual intervention). Also, mention how you'd measure and monitor recovery success with metrics like assignment latency and reconciliation errors.

1. Define the data model and storage

Describe the entities (locker, package, assignment) and choose a durable, transactional store like a relational database or DynamoDB with strong consistency. Explain how you model assignment state (e.g., pending, confirmed, failed) and use unique constraints to prevent double-booking.

2. Explain the assignment transaction

Walk through the steps: reserve locker, write assignment record, update locker status, and notify user. Emphasize atomicity via a single transaction or saga with compensating actions, and idempotency keys to handle retries safely.

3. Address crash scenarios mid-assignment

Detail what happens if the service crashes after reserving but before confirming: the transaction either commits fully or rolls back. If using a saga, describe how the orchestrator or choreography detects the incomplete state and triggers compensation or retry.

4. Describe recovery and reconciliation

Explain mechanisms like write-ahead logging, periodic reconciliation jobs that scan for stuck assignments, and timeouts that release reserved lockers. Mention how you ensure exactly-once semantics and avoid duplicate assignments.

5. Discuss monitoring and operational readiness

Cover metrics (e.g., assignment success rate, recovery time), alarms, and automated remediation. Highlight how you'd test failure scenarios with chaos engineering and ensure the system meets SLAs.

Key Points to Mention

  • Use of ACID transactions or DynamoDB transactions for atomic assignment
  • Idempotency keys to make assignment operations safe to retry
  • Write-ahead logging or event sourcing for durability and recovery
  • Saga pattern with compensating actions for distributed transactions
  • Reconciliation jobs to detect and fix inconsistent states
  • Timeouts and leases to automatically release reserved lockers
  • Monitoring and alerting on assignment failures and recovery metrics

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

Q4

Write pseudocode for an assign(packageSize) function and a release(lockerId) function.

System DesignAlgorithms & Data Structures
Author's notes

Straightforward enough.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem requirements first, including the data structures for lockers and packages, concurrency needs, and edge cases. Then design the pseudocode for assign and release, focusing on efficient lookup, thread safety, and error handling. Walk through the logic step-by-step, explaining your choices and trade-offs.

Pro tip: Demonstrate awareness of real-world constraints like race conditions and scalability by mentioning locking mechanisms or lock-free approaches, and discuss how your design would handle high concurrency.

1. Clarify Requirements and Assumptions

Ask questions to understand the system: What data structures are available? Are lockers of fixed size? Is concurrency a concern? What should happen if no locker is available or if an invalid lockerId is released?

2. Define Data Structures

Specify the data structures for lockers and packages, such as a hash map for lockerId to locker status, a queue for available lockers, and a map for packageSize to available lockers of that size.

3. Design assign(packageSize) Logic

Outline steps: find an available locker that fits the package size, mark it as occupied, associate the package with the locker, and return the lockerId. Handle cases where no locker is available.

4. Design release(lockerId) Logic

Outline steps: validate lockerId, mark the locker as available, remove the package association, and update available locker structures. Handle invalid lockerId or already released locker.

5. Address Concurrency and Edge Cases

Discuss how to make the functions thread-safe using locks or atomic operations, and mention edge cases like concurrent assign/release, locker size mismatches, and error handling.

Key Points to Mention

  • Choice of data structures for efficient locker lookup by size and ID
  • Concurrency control mechanisms (e.g., mutex, semaphore, or lock-free) to prevent race conditions
  • Error handling for invalid inputs and no available lockers
  • Time and space complexity of the operations
  • Scalability considerations for large numbers of lockers and packages
  • Potential optimizations like using a priority queue for locker sizes or partitioning lockers by size

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

Q5

How would you extend this system to support reservations, per-location sharding, priority or SLA tiers, and scaling to many locations?

System DesignTechnical Trade-offsProduct Strategy
Author's notes

This came at the end and I was running low on time.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the current system architecture and requirements, then propose a high-level design that addresses each extension (reservations, sharding, SLA tiers, scaling) while discussing trade-offs. Emphasize incremental changes, data modeling, and operational considerations, aligning with Amazon's leadership principles like Customer Obsession and Think Big.

Pro tip: Frame your answer around customer impact and business value, and proactively discuss failure modes and mitigation strategies—Amazon values operational excellence and ownership.

1. Clarify Requirements and Assumptions

Ask questions to understand the current system, expected scale, consistency needs, and SLA definitions. State your assumptions explicitly to guide the design.

2. Design for Reservations

Introduce a reservation service with a data model (e.g., resource, time slot, user) and handle concurrency via optimistic locking or distributed transactions. Discuss idempotency and conflict resolution.

3. Implement Per-Location Sharding

Shard data by location to distribute load and enable horizontal scaling. Choose a sharding key (e.g., location ID) and discuss routing, rebalancing, and cross-shard queries.

4. Introduce Priority/SLA Tiers

Add a tier attribute to requests and implement prioritization via separate queues, rate limiting, or weighted scheduling. Ensure isolation to prevent lower tiers from impacting higher ones.

5. Scale to Many Locations

Address scaling challenges: automate shard management, use a control plane for metadata, and consider geo-distribution for latency. Discuss monitoring, autoscaling, and cost optimization.

Key Points to Mention

  • Data consistency models (strong vs. eventual) for reservations and cross-shard operations
  • Sharding strategies (range, hash, directory-based) and their trade-offs
  • SLA enforcement mechanisms (priority queues, rate limiting, dedicated resources)
  • Scalability patterns (horizontal scaling, caching, read replicas, async processing)
  • Operational concerns (monitoring, alerting, deployment, failure recovery)
  • Cost implications and trade-offs between performance and resource utilization

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