← Questions

Design Amazon Locker (object-oriented)

0
AmazonOO designLast asked Jan 2026

An object-oriented design interview question asked in Amazon's coding round, last asked Jan 2026. It tests object-oriented design.

Design the object model for a self-service package locker. A courier drops a package into a free compartment that fits it, and the system issues a one-time pickup code valid for a few days. The customer enters the code, the right compartment opens, and the code stops working. Packages that are never picked up go back to the courier. Hardware (latches, scanners, SMS gateways) and payments are outside the model.

Requirements

  • Functional: a location has compartments of several sizes (small, medium, large); assign an arriving package the smallest free compartment that fits, or report that none fits; generate a one-time code and notify the customer; open the compartment when a valid code is entered and free it after pickup; expire packages after the pickup window and mark them for return; let the courier collect expired packages.
  • A code works exactly once and only at its location.
  • Non-functional: no compartment is ever assigned to two packages, even when two couriers deposit at once; codes are hard to guess.

Clarifying questions

  • How many compartment sizes, and can a small package use a large compartment when small ones are full?
  • How long is the pickup window, and can it be extended?
  • What happens if the customer enters a wrong code several times?
  • Can one customer have several packages, and does one code open all of them?
  • Can a customer return an item through the locker?

What a strong answer covers

  • Core classes: LockerLocation (compartments, address), Compartment (ID, size, status: free, reserved, occupied, out of service), Package (ID, size, customer, status), PickupCode (code, package, expiry, used), LockerService (assign, deposit, pickup, expire), AssignmentStrategy, and NotificationService.
  • Assignment: a free list per size and a smallest-fit-first policy, with fallback to larger sizes.
  • Avoiding check-then-act bugs: assigning a compartment as one atomic step (a lock or a conditional status change), and redeeming a code atomically so two attempts cannot both open it.
  • Code generation with enough randomness, rate-limiting wrong attempts, and storing codes hashed.
  • Expiry as a scheduled job that moves packages to "return" and reserves them for the courier.
  • Tests: no free compartment, two simultaneous deposits, a reused code, an expired code.

Follow-ups

  • Add customer returns: drop an item into a locker for the courier to collect.
  • Support one code that opens several compartments for a multi-package order.
  • Route packages to a nearby location when the chosen one is full.

Where it's asked

  • Amazon · Coding · Last asked Jan 202655 min · Usually two rounds; one is often an object-oriented design built in steps · No AI

What it tests

object-oriented design

Your canvas
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing