LOW-LEVEL DESIGN · THE LLD INTERVIEW · METHOD · 47 OF 48

How to Answer a Low-Level Design Interview: A Step-by-Step Plan

A repeatable method for 60 to 90 minute low-level design and machine coding rounds: what interviewers score, a minute-by-minute time plan, then every step on a small worked example, a parcel locker: clarify requirements, find entities, draw the class diagram, choose interfaces and patterns, walk the core flows, write the code, handle concurrency and discuss extensions.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
1 / 16

Press play to hear the narration, or step through at your own pace. The Java example is below.

Java example

One file, Java 17, 204 lines, with a small main() demo. Save it as ParcelLockerWalkthrough.java, then run javac ParcelLockerWalkthrough.java && java ParcelLockerWalkthrough.

import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/** A worked LLD answer: a parcel locker, built step by step with the interview method. */
public class ParcelLockerWalkthrough {

    public static void main(String[] args) throws InterruptedException {
        AtomicReference<Instant> clock = new AtomicReference<>(Instant.parse("2026-01-05T10:00:00Z"));
        AtomicInteger seq = new AtomicInteger(1000);
        LockerService service = new LockerService(
                List.of(new Locker("S1", Size.SMALL), new Locker("M1", Size.MEDIUM),
                        new Locker("M2", Size.MEDIUM), new Locker("L1", Size.LARGE)),
                new SmallestFitPicker(), new ConsoleNotifier(),
                () -> "C" + seq.incrementAndGet(), clock::get);

        // Happy path: three deposits, one pickup
        String a = service.deposit(new Parcel("P-1", Size.SMALL, "98xxxx01")).orElseThrow();
        String b = service.deposit(new Parcel("P-2", Size.MEDIUM, "98xxxx02")).orElseThrow();
        service.deposit(new Parcel("P-3", Size.SMALL, "98xxxx03")).orElseThrow(); // S1 taken: goes to M2
        System.out.println("Pickup " + a + ": " + service.pickup(a).map(Parcel::id).orElse("refused"));

        // Edge cases: same code twice, wrong code, lockers full
        System.out.println("Pickup " + a + " again: " + service.pickup(a).map(Parcel::id).orElse("refused"));
        System.out.println("Pickup C9999: " + service.pickup("C9999").map(Parcel::id).orElse("refused"));
        service.deposit(new Parcel("P-4", Size.LARGE, "98xxxx04"));
        Optional<String> none = service.deposit(new Parcel("P-5", Size.LARGE, "98xxxx05"));
        System.out.println("Deposit when no large locker is free: " + none.orElse("no locker free"));

        // Expiry: move the injected clock forward four days
        clock.set(clock.get().plus(Duration.ofDays(4)));
        System.out.println("Expired and freed: " + service.expireOlderThan(Duration.ofDays(3)));
        String afterExpiry = service.pickup(b).map(Parcel::id).orElse("refused");
        System.out.println("Pickup " + b + " after expiry: " + afterExpiry);

        // Concurrency: eight couriers race for four empty lockers
        LockerService fresh = new LockerService(
                List.of(new Locker("S1", Size.SMALL), new Locker("S2", Size.SMALL),
                        new Locker("M1", Size.MEDIUM), new Locker("L1", Size.LARGE)),
                new SmallestFitPicker(), (phone, msg) -> { }, () -> "K" + seq.incrementAndGet(), clock::get);
        AtomicInteger stored = new AtomicInteger();
        CountDownLatch go = new CountDownLatch(1);
        List<Thread> couriers = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            Parcel p = new Parcel("R-" + i, Size.SMALL, "97xxxx" + i);
            Thread t = new Thread(() -> {
                try {
                    go.await();
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    return;
                }
                fresh.deposit(p).ifPresent(code -> stored.incrementAndGet());
            });
            couriers.add(t);
            t.start();
        }
        go.countDown();
        for (Thread t : couriers) {
            t.join();
        }
        System.out.println("8 couriers, 4 lockers: stored " + stored.get()
                + ", occupied " + fresh.occupied());
    }
}

// ---------- Step 2: entities ----------
enum Size {
    SMALL, MEDIUM, LARGE;

    boolean fits(Size parcel) {
        return ordinal() >= parcel.ordinal();
    }
}

record Parcel(String id, Size size, String phone) { }

record Assignment(String code, Locker locker, Parcel parcel, Instant storedAt) { }

/** The only mutable entity. Its content is claimed with compare-and-set (step 7). */
final class Locker {
    private final String id;
    private final Size size;
    private final AtomicReference<Parcel> content = new AtomicReference<>();

    Locker(String id, Size size) {
        this.id = id;
        this.size = size;
    }

    String id() {
        return id;
    }

    Size size() {
        return size;
    }

    boolean isFree() {
        return content.get() == null;
    }

    boolean tryStore(Parcel parcel) {
        return content.compareAndSet(null, parcel);
    }

    Parcel release() {
        return content.getAndSet(null);
    }
}

// ---------- Step 4: seams where change is likely ----------
interface SlotPicker {
    List<Locker> candidates(List<Locker> all, Size size);
}

/** Strategy: free lockers that fit, smallest first, so large lockers stay free for large parcels. */
final class SmallestFitPicker implements SlotPicker {
    @Override
    public List<Locker> candidates(List<Locker> all, Size size) {
        return all.stream()
                .filter(l -> l.isFree() && l.size().fits(size))
                .sorted(Comparator.comparing(Locker::size))
                .collect(Collectors.toList());
    }
}

interface Notifier {
    void send(String phone, String message);
}

final class ConsoleNotifier implements Notifier {
    @Override
    public void send(String phone, String message) {
        System.out.println("  SMS to " + phone + ": " + message);
    }
}

// ---------- Step 6: the service, the single entry point ----------
final class LockerService {
    private final List<Locker> lockers;
    private final SlotPicker picker;
    private final Notifier notifier;
    private final Supplier<String> codes;
    private final Supplier<Instant> now;
    private final Map<String, Assignment> byCode = new ConcurrentHashMap<>();

    LockerService(List<Locker> lockers, SlotPicker picker, Notifier notifier,
                  Supplier<String> codes, Supplier<Instant> now) {
        this.lockers = List.copyOf(lockers);
        this.picker = picker;
        this.notifier = notifier;
        this.codes = codes;
        this.now = now;
    }

    Optional<String> deposit(Parcel parcel) {
        for (Locker locker : picker.candidates(lockers, parcel.size())) {
            if (locker.tryStore(parcel)) {                // another courier may have won: try the next
                String code = codes.get();
                byCode.put(code, new Assignment(code, locker, parcel, now.get()));
                notifier.send(parcel.phone(),
                        "Parcel " + parcel.id() + " is in " + locker.id() + ", code " + code);
                return Optional.of(code);
            }
        }
        return Optional.empty();
    }

    Optional<Parcel> pickup(String code) {
        Assignment a = byCode.remove(code);               // atomic: only one caller gets it
        if (a == null) {
            return Optional.empty();
        }
        return Optional.of(a.locker().release());
    }

    List<String> expireOlderThan(Duration maxAge) {
        Instant cutoff = now.get().minus(maxAge);
        List<String> expired = new ArrayList<>();
        for (Assignment a : byCode.values()) {
            if (a.storedAt().isBefore(cutoff) && byCode.remove(a.code(), a)) {
                a.locker().release();
                expired.add(a.parcel().id() + "@" + a.locker().id());
            }
        }
        expired.sort(null);
        return expired;
    }

    long occupied() {
        return lockers.stream().filter(l -> !l.isFree()).count();
    }
}

Notes

What is scored

First, know the scorecard. Interviewers check that you pin down requirements and scope, that your classes are small and well named, that you put interfaces where change is likely and pick patterns for a reason. They want code that runs and reads well, a sensible answer on thread safety, and calm answers to extension questions. Throughout, they score how clearly you explain. Hidden genius that is never said out loud earns nothing.

The scorecard
  • • clear requirements + scope
  • • sensible classes, small
  • and named well
  • • interfaces where change is
  • likely, patterns with reason
  • • working, readable code
  • • thread safety handled
  • • extension questions answered
  • • you explain as you go

The time plan

Here is a time plan for sixty minutes. Five minutes to clarify requirements. Five for entities. Five for the class diagram and patterns. Five to walk the main flows. About twenty eight minutes to write code with a small demo. Five on concurrency, and the last seven on extensions and your questions. In a ninety minute machine coding round, the extra time mostly goes to code and testing. Check the clock at each step.

A 60-minute plan
  • 0-5 clarify requirements
  • 5-10 entities
  • 10-15 class diagram, patterns
  • 15-20 core flows
  • 20-48 code + a demo main
  • 48-53 concurrency
  • 53-60 extensions, questions
  • 90 min: stretch code to
  • about 50 min, test more

1 · Clarify

Step one, clarify. Our problem: a parcel locker. There are small, medium and large lockers. A courier deposits a parcel, the system chooses a locker and texts the customer a pickup code. The customer opens the locker with the code. Parcels not collected in three days expire. Several couriers can work at the same time. Say what is out of scope, like payments and multiple sites, and get a nod before moving on.

Ask questions whose answers change the code. Can a small parcel go into a large locker? Yes, but only if no small one is free. One parcel per locker? Yes. What happens on expiry? Free the locker and record it for return. Are codes single use? Yes. Each answer becomes a rule that lives in one specific class. Skip questions that change nothing, like the colour of the lockers.

Parcel locker: scope
  • lockers: small, medium, large
  • courier deposits a parcel
  • system picks a locker and
  • texts the customer a code
  • customer picks up with code
  • parcels expire after 3 days
  • many couriers at once
  • out of scope: payments,
  • multiple sites, the app UI
Questions that matter
  • can a small parcel use a
  • large locker? yes, if no
  • small one is free
  • one parcel per locker? yes
  • wrong code: retry limit?
  • out of scope for now
  • expired: just free the
  • locker and log it
  • codes: unique, single use

2 · Entities

Step two, entities. Underline the nouns: locker, parcel, size, code, courier, customer. Keep only the ones that hold data or rules. Size becomes an enum with a fits method. Parcel and Assignment become records, because they never change. Locker has changing state, so it is a small class. The courier and customer only call the system, so they stay outside the model. LockerService is the single entry point.

Nouns to types
  • Size: enum, with fits()
  • Parcel: record (id, size,
  • phone)
  • Locker: id, size, content
  • Assignment: record (code,
  • locker, parcel, time)
  • LockerService: the facade
  • courier, customer: callers,
  • not classes

3 · Class diagram

Step three, a quick class diagram. LockerService has many lockers and tracks assignments by pickup code. An assignment points to one locker and one parcel, with the time it was stored. A locker contains zero or one parcel. Draw boxes, arrows and multiplicity, and say each relation as you draw it. This takes two minutes, and it becomes the map you follow while coding.

4 · Interfaces, patterns

Step four, interfaces and patterns. Put an interface wherever a what if question is likely. How lockers are chosen may change, so SlotPicker is a Strategy, starting with smallest fit. How customers are told may change from SMS to app push, so Notifier is an interface. Time is injected, so expiry can be tested without waiting three days. Name each pattern only with the pain it removes.

Seams, with a reason
interface SlotPicker {   // Strategy
  List<Locker> candidates(
      List<Locker> all, Size size);
}
interface Notifier {     // SMS, app push
  void send(String phone, String msg);
}
Supplier<Instant> now;   // testable time

5 · Core flows

Step five, walk the core flows before coding. Deposit: the courier calls deposit with a parcel. The service asks the slot picker for candidate lockers in order of preference. It tries to claim the first one; if another courier just took it, it tries the next. It creates an assignment with a fresh code, stores it, and the notifier texts the code to the customer.

Pickup: the customer enters a code. The service removes the assignment for that code in one atomic step. If it was there, the locker is released and the door opens. A second attempt with the same code finds nothing and is refused, which gives single use codes for free. Walking flows like this catches missing methods before you write them, and shows the interviewer your plan.

6 · Code

Step six, code. Write in the order of your diagram: enum and records first, then Locker, then the interfaces, then the service, and last a main method that runs the flows. Here is deposit: loop over the candidates, claim a locker, create the assignment, notify, return the code. If nothing is free, return an empty optional instead of null. Keep methods short and talk while you type.

deposit()
Optional<String> deposit(Parcel p) {
  for (Locker l : picker.candidates(
         lockers, p.size())) {
    if (l.tryStore(p)) {
      String code = codes.get();
      byCode.put(code, new Assignment(
          code, l, p, now.get()));
      notifier.send(p.phone(), code);
      return Optional.of(code); }
  }
  return Optional.empty(); }

7 · Concurrency

Step seven, concurrency. Name the shared state and the races. Two couriers may grab the same free locker: each locker holds its parcel in an atomic reference and claims it with compare and set, so exactly one wins and the other tries the next locker. Two pickups with one code: removing from a concurrent map returns the assignment to only one caller. Codes come from an atomic counter or a random id.

Races and fixes
  • two couriers, one free locker
  • -> CAS on locker content;
  • loser tries next one
  • two pickups, one code
  • -> ConcurrentHashMap.remove
  • returns it to one caller
  • code generator
  • -> AtomicInteger or UUID

8 · Extensions

Step eight, extensions. The interviewer will push. Extra large lockers? Add an enum value. A fee for overdue days? A new pricing policy interface used at pickup. Many locker sites? A site class with its own service. App push instead of SMS? A new notifier. A different way to choose lockers? A new slot picker. If your seams were chosen well, each answer is a small, local change, and you can say exactly where it goes.

What if...
  • extra-large lockers?
  • add an enum value
  • fee for overdue days?
  • a PricingPolicy interface
  • many locker sites?
  • LockerSite, service per site
  • app push instead of SMS?
  • a new Notifier
  • nearest site first?
  • a new SlotPicker

Show it runs

Finish coding with a demo that proves it works. Deposit a few parcels. Pick one up. Try the same code again and a wrong code. Fill every locker and show the clear answer. Move the injected clock forward and show expiry. Finally, run several couriers on threads at once and show no locker was used twice. Five minutes of demo builds more trust than five more classes.

Demo checklist
  • • deposit three parcels
  • • pick one up with its code
  • • same code again: refused
  • • wrong code: refused
  • • lockers full: clear answer
  • • move the clock: expiry
  • • many couriers at once:
  • no locker used twice

How to behave

A few habits matter as much as the design. Think out loud, so the interviewer can follow and help. State trade-offs, why this and not that. When the interviewer drops a hint, take it; it is usually a gift. Get a simple working version first, then improve it. And if you are stuck, say what you are trying and simplify the problem. Silence is the hardest thing to score.

Habits that score
  • • think out loud
  • • state trade-offs: why X
  • and not Y
  • • take hints, do not argue
  • • working simple version
  • first, then improve
  • • short methods, clear names
  • • if stuck: say what you
  • are trying, simplify

Interview questions

How should I start a low-level design interview?

Spend the first five minutes on requirements. Restate the problem, list the features you will build, ask questions that change the design, and say what is out of scope. Get the interviewer to agree before drawing classes.

How do I find the classes?

Underline the nouns in the requirements and keep those that hold data or enforce rules. Fixed kinds become enums, unchanging data becomes records, and the few things with changing state become small classes guarded in one place.

How many design patterns should I use?

Only those that remove a specific pain you can name, usually two or three. Strategy for a rule likely to change, Observer for notifications, Factory for creation logic. Using patterns for show is a common negative signal.

How much time should go to coding?

Roughly half the round. In 60 minutes, about 25 to 30 minutes of coding after 15 to 20 minutes of design, leaving time for concurrency and extensions. In a 90 minute machine coding round, coding and testing take most of the time.

Should I write tests or a main method?

Yes, at least a main that runs the happy path and key edge cases, or a few small tests if the setup allows it. Showing the code works is part of the score and often catches bugs before the interviewer does.

How do I handle concurrency in an LLD answer?

Identify the shared mutable state, describe the exact race, such as two couriers claiming one locker, and give the fix, such as compare-and-set or a lock around the check and update. Keep mutable state in as few classes as possible.

What do interviewers look for in extension questions?

That a new requirement maps to a small, local change: a new class implementing an existing interface, or a new enum value, rather than edits across the whole codebase. Point at the seam you already built.

What should I do if I get stuck?

Say what you are trying, simplify the problem, and ask a clarifying question. Get a simple version working first. Interviewers prefer a candidate who reasons aloud and takes hints over one who goes silent.