Skip to content

Repository files navigation

Contributors Forks Stargazers Issues MIT License Website

Low Level Design in Python

Low Level Design in Python

Working implementations of the design problems that actually get asked in machine coding rounds
Practise these on GOAT Engineer »

Report a bug · Request a problem

About

Low-level design is badly served by the internet. DSA has structured practice — graded problems, a judge that tells you whether you were right. LLD has blog posts with a class diagram, no code, and no way to tell whether the design actually holds up.

This repository is the other thing: every problem here has a working implementation you can run, a test suite that pins down the behaviour that matters, and a write-up explaining why the design is shaped the way it is — including the bugs the shape prevents.

These problems back the LLD track on GOAT Engineer.

What a problem looks like

problems/vending-machine/
├── README.md      # statement, mermaid class diagram, design rationale, follow-ups
├── meta.json      # machine-readable metadata (validated against schema/)
├── src/
│   ├── main.py    # runnable demo
│   └── ...        # the implementation
└── tests/         # pytest, asserting the behaviour the design exists to guarantee

Problems

# Problem Difficulty Design Patterns Time
1 Design Tic Tac Toe 🟢 Easy Strategy, Observer 40 min
2 Snake and Ladder 🟢 Easy Strategy 45 min
3 Design Splitwise 🟡 Medium Strategy, Observer 60 min
4 Design a Chat Room 🟡 Medium Mediator, Observer, Facade 50 min
5 Design a Logging Framework 🟡 Medium Chain of Responsibility, Strategy, Singleton 45 min
6 Design a Notification Service 🟡 Medium Decorator, Observer, Factory Method, Strategy 55 min
7 Design a Parking Lot 🟡 Medium Strategy, Factory Method, Command, Facade 60 min
8 Design a Rate Limiter 🟡 Medium Strategy 50 min
9 Design a Text Editor with Undo 🟡 Medium Command, Memento, Composite, Facade 55 min
10 Design a Vending Machine 🟡 Medium State 50 min
11 Design an ATM 🟡 Medium State, Chain of Responsibility 60 min
12 Design an In-Memory File System 🟡 Medium Composite, Visitor, Iterator, Facade 55 min
13 Design an LRU Cache 🟡 Medium Strategy, Template Method 45 min
14 Design Chess 🔴 Hard Strategy, Command, Template Method, Observer 90 min
15 Design a Movie Ticket Booking System 🔴 Hard Builder, Repository, Proxy, Strategy, Facade 80 min
16 Design a Payment Gateway 🔴 Hard Adapter, Abstract Factory, Strategy, Facade 70 min
17 Design an Elevator System 🔴 Hard Strategy, State, Observer 75 min

Every problem's README carries a mermaid class diagram that renders inline on GitHub, the reasoning behind each pattern used, and the follow-up questions an interviewer is likely to ask next.

Looking for a particular pattern rather than a particular problem? docs/patterns.md indexes all 20 the other way round — what each one is for, the question that makes you reach for it, the mistake it attracts, and which problems here work it through.

Getting started

git clone https://github.com/abhaypaswan/lld-python.git
cd lld-python
pip install -r requirements-dev.txt

Run any problem's demo:

cd problems/parking-lot && python3 src/main.py

Run the whole test suite:

python3 -m pytest

Or one problem's:

python3 -m pytest problems/chess -v

Each problem is genuinely self-contained — copy one out of the repository and its tests and demo still run, with nothing else present:

cd problems/chess && python3 -m pytest

How this repository is put together

Each problem lives in problems/<slug>/ and is self-contained — you can read one top to bottom without touching anything else.

The code in src/<package>/ uses only the standard library. If a problem looks like it needs a dependency, that is usually a sign the design is doing something the problem did not ask for. pytest is for the tests, not the implementations.

Every problem carries a meta.json describing its difficulty, the patterns it genuinely uses, and how long it should take. Those files validate against schema/problem.schema.json and build into catalog.json, which is what GOAT Engineer reads:

python3 scripts/validate.py        # check every problem is complete and consistent
python3 scripts/build_catalog.py   # regenerate catalog.json, the table above, and docs/patterns.md
python3 scripts/check_examples.py  # run every command in these docs and verify its output

catalog.json, the problem table above, and docs/patterns.md are all generated. Edit a meta.json and re-run the build rather than editing any of them by hand — CI fails if they drift.

A note on the tests

The test suites are not there for coverage. Each one pins down the specific behaviour its design exists to guarantee, and several were written to fail first:

  • vending-machine — a machine that cannot make change leaves the item on the shelf and the buyer's money untouched
  • splitwise — every equal split from 1 to 200 sums exactly to the total, with nobody more than one cent out of step
  • chess — perft to depth 3 (8,902 positions), which proves undo fully reverses apply
  • tic-tac-toe — two perfect players always draw; a perfect player never loses to a random one, across eight seeds
  • rate-limiter — the fixed window does allow the boundary burst, so the sliding variants can be shown to fix it

Contributing

Contributions are welcome — especially new problems.

A new problem needs all five of: a README.md with a mermaid class diagram, a meta.json that passes scripts/validate.py, a runnable src/main.py, an implementation using only the standard library, and tests that cover the cases the design is meant to handle.

  1. Fork the repository
  2. Create a branch (git checkout -b problem/design-a-thing)
  3. Run python3 -m pytest and python3 scripts/validate.py
  4. Run python3 scripts/build_catalog.py to refresh the catalog
  5. Open a pull request

CI runs four jobs: the test suite on Python 3.10–3.13 plus the validator and the generated-file check; every problem in isolation, copied out of the repository; every command in the documentation, with its shown output verified; and lint.

(back to top)

License

MIT. See LICENSE.

Contact

Abhay Paswan — work.abhaypaswan@gmail.com

Repository: github.com/abhaypaswan/lld-python Platform: goatengineer.com

(back to top)

About

This repository contains solutions to machine coding problems related to low-level design (LLD) in Python. In technical interviews, these problems are commonly asked to assess a candidate's knowledge of Object Oriented Design Patterns & Concepts.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

40 stars

Watchers

1 watching

Forks

Packages

Contributors

Languages