Solly
Lesson

04 Complete LLD systems: bounded executable slices

Complete LLD systems: bounded executable slices

Building an interview-sized system without guessing the architecture

These are not production deployments. Each exercise gives a small executable slice of a familiar application. The title names the domain, not a claim that you will implement the whole system. For example, the ATM/Vending/Traffic Signal problems isolate transition rules; Elevator and Chess isolate a replaceable policy, not a full scheduler or complete chess engine. Once the small slice passes, ask which additional rules a real system would need.

Two useful worked traces for later tasks:

  • LRU (least recently used) versus TTL (time to live): after inserting A then B, reading A makes B the least recently used entry. If capacity is 2, inserting C should evict B. TTL is independent: if an entry expires at time 10, a read at time 9 can refresh recency without pushing expiry past 10 unless the contract explicitly says so. Before inserting when full, remove expired entries first; an expired most-recently-used entry must never cause a still-valid older entry to be evicted.
  • All-or-nothing effects: in a wallet transfer of 30 cents, source balance goes down 30 and destination up 30 while exactly two ledger entries sum to zero. If funds are insufficient, neither balance nor the ledger changes. A repeated idempotency key must reuse the earlier result, not debit again.

Before naming classes, list what the caller can do, what data must be remembered, and which operations must happen together.

For example, in a parking-lot exercise: a vehicle requests a spot; a compatibility rule decides whether it fits; the lot remembers the claim; a ticket identifies the vehicle and spot; an exit frees the spot and asks a pricing rule for the cost. The caller-facing examples specify the required methods and returned dictionaries. Do not invent extra arguments merely because a real parking business might need them.

An invariant is a rule that must remain true, such as “one spot can belong to at most one vehicle.” Atomic means that competing callers cannot observe a half-finished claim. Idempotent means repeating an operation does not create a second effect. Compensation means undoing a previous step if a later step fails, such as releasing a reservation after a failed payment. Snapshot means taking a stable copy of what matters at a particular moment. These words matter only when the supplied tests require their behavior.

Try each task in this order: (1) draw the caller calls, (2) list the state owned by each piece, (3) walk through the successful path, (4) walk through a failure or retry, (5) make the regular example pass, and (6) handle the listed design pressure. If you cannot explain an unfamiliar domain rule from the problem and test, write it down as a missing assumption rather than guessing.


Each system is a runnable interview-sized slice chosen around a real pressure from the larger LLD system. Use the supplied Expected Behavior, then reason through Stable roles, Change, Ownership, Abstraction need, and Topology.

Ownership includes lifetime/scope only where it actually changes the design: transactions, idempotency, subscriptions, session state, caches, locks, resource claims, persistence, and similar system concerns. The goal is not to force every system through ceremonial abstractions; it is to make the important runtime property executable.

Parking Lot and Library Management deliberately carry multiple independent stress cases.

Sign in with an enabled provider to save your lesson progress.
Sign in to track progress

Loading sign-in options…