Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Low-Level Design in Java

21 LLD interview systems and 9 language drills, in plain Java. Every folder compiles, every folder runs, and every folder prints something that argues for its design.

Java Verified on JDK 25 No dependencies License: MIT

302 Java files · 21 systems · 9 drills · no build tool, no dependencies · verified on JDK 25

Companion courses: Low-Level Design in Java: OOP, SOLID & 11 Design Patterns (low-level design — this repo) and System Design Fundamentals for Interviews (high-level / distributed system design).

Most LLD repositories are class diagrams with the code left as an exercise, or code that has never been run. This one is the opposite: javac and java on any folder, and the demo walks you through the design decision it exists to make — including the version that gets it wrong, so you can see the difference.

git clone https://github.com/AnandRochlani/low-level-design-java.git
cd low-level-design-java/case-studies/parking-lot
javac -d out $(find . -name '*.java') && java -cp out Main

Start here

New to this, or short on time before an interview? Read these three, in this order — they cover the two abstractions that most LLD questions actually turn on.

  1. Vending Machine — the smallest system where a state machine clearly beats a pile of booleans.
  2. Parking Lot — the one you are most likely to be asked, and two strategies swapped while it runs.
  3. docs/interview-framework.md — the 45-minute clock and the six questions to open with.

The 21 systems

System What it is really about Patterns Types
Amazon-style Shopping ★★★ Prices freeze and stock is reserved at checkout — the part most implementations skip. State 16
Chess ★★★ The if-else pyramid and the polymorphic version, running side by side and disagreeing. Strategy 20
Logging Framework ★★★ Chain of responsibility for levels, appenders for destinations, and no allocation when a level is off. Chain of Responsibility, Decorator, Singleton 14
Movie Ticket Booking ★★★ The concurrency one. 50 threads race for seat A5; exactly one wins. State 8
Rate Limiter ★★★ Four algorithms, one interface, and a broken token bucket kept in for contrast. Strategy 11
Ride Sharing (Uber / Ola) ★★★ Matching and pricing as two independent strategies over one trip lifecycle. Strategy, State 16
ATM ★★☆ A state machine with a PIN attempt counter and a dispenser that can run out of notes. State 16
Blackjack ★★☆ The ace problem: one hand, three totals, and why Card.value() -> int is wrong. Strategy 17
Car Rental ★★☆ Cross-branch pickups, add-on charges, and rates that vary by duration. Strategy, Decorator 21
Elevator System ★★☆ Two schedulers over the same car, printed side by side so you can see FCFS lose. Strategy 11
Food Delivery (Swiggy / Zomato) ★★☆ Restaurant search, cart, and partner assignment with a real distance bound. Strategy, State 14
Hotel Management ★★☆ You reserve a room type, not a room number — which is the whole insight. Value Object 9
Key-Value Store with Eviction ★★☆ LRU and FIFO behind one policy interface, plus a decorator that adds thread safety. Strategy, Decorator 11
Meeting Scheduler ★★☆ Half-open intervals, so back-to-back meetings do not falsely collide. Value Object 15
Parking Lot ★★☆ The classic opener. Two strategies swapped at runtime, and a lot that can actually fill up. Strategy 17
Restaurant Management ★★☆ Table states, order lifecycle, listeners for the kitchen, and split billing. State, Observer, Strategy 22
Splitwise ★★☆ Three split strategies and a settlement pass that minimises transfers. Strategy 11
Stack Overflow ★★☆ An event bus where reputation and badges are listeners, not if statements in the vote handler. Observer 20
Snake and Ladder ★☆☆ A tiny board game whose only real design decision is making the dice injectable. Strategy 9
Tic Tac Toe ★☆☆ Two win-check implementations behind one interface — O(n²) scan vs O(1) counters. Strategy 11
Vending Machine ★☆☆ The cleanest State machine in the repo — a good first read. State 8

Looking for one pattern in particular? Where each pattern actually appears.

The 9 drills

Short, runnable programs for the language mechanics and principles that LLD interviews probe directly.

Drill What it shows Types
Choosing a Collection Same six entries, three maps, three different orders. 2
Creational Pattern Selector Singleton, simple factory, factory method, abstract factory and builder — in one run, so you can compare. 20
Exception Design A swallowed exception charges a customer and parks their car nowhere. 11
Immutability & Defensive Copies Two live leaks through a getter, then the fix. 4
OOP Mechanics Overloading vs overriding, access, init order, and the compile errors Java gives you. 32
Pattern Catalogue The remaining GoF patterns as compact, runnable demos. 41
SOLID Drill Five rounds, one principle each, violation and fix side by side. 29
Sealed Types & Exhaustive Switch A closed type hierarchy the compiler can check for you. 12
equals / hashCode Contracts equals says yes, the HashSet says no — and why. 5

How to use this for an interview

Reading a finished design teaches you much less than rebuilding it. For each system:

  1. Read only The problem and Deliberately out of scope in its README.
  2. Close it. Draw your own class diagram, on paper, in ten minutes.
  3. Open the diagram in the README and diff it against yours.
  4. Read Design decisions worth defending — that section is the part an interviewer is actually grading.
  5. Run the demo and read the output.

There is a 45-minute walkthrough of the method in docs/interview-framework.md.

Requirements

A JDK, and nothing else. No Maven, no Gradle, no dependencies — every folder is plain javac-able source so you can read it without a build system in the way.

Verified on JDK 25. Everything compiles on JDK 21 except concepts/sealed-types, which uses unnamed variables (case Card _) and needs JDK 22+.

Two folders — concepts/oop-mechanics/broken/ and concepts/sealed-types/broken/do not compile on purpose. Each file there is a specific compiler error worth being able to predict. They are excluded from every build command in this repo.

Regenerating the docs

Every README, class diagram and captured output in this repository is generated from the sources:

python3 tools/generate_docs.py

The diagrams are parsed out of the .java files and the terminal output is captured by actually running each demo, so neither can drift from the code.

The courses

I teach this material in Low-Level Design in Java: OOP, SOLID & 11 Design Patterns — the four pillars, the five SOLID principles, eleven design patterns, and four of these systems (Parking Lot, Library, Elevator, Chess) built from a blank page on camera: requirements first, then the diagram, then the code, with the wrong version written first so the fix has something to fix.

This repository is deliberately larger than the course and stands entirely on its own — clone it, run it, and never buy anything. The course is for people who want the reasoning narrated rather than reconstructed from source. There are also free written walkthroughs at anandrochlani.com.

LLD is one half of the design interview. The other half — scaling, storage, caching, queues, consistency and the back-of-the-envelope numbers behind them — is System Design Fundamentals for Interviews. Take them together if you are preparing end to end; either one stands on its own.

Licence

MIT — see LICENSE. Use it in your own prep, teaching or projects.

About

21 low-level design interview systems + 9 Java drills. Plain javac, no dependencies — every folder compiles, runs, and shows the design decision it exists to make.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages