Skip to content
Tutorials Center
My learning

Topics

Lesson 46 of 57 ยท Low-Level Design Projects

How to Approach a Low-Level Design Problem

A repeatable framework for low-level design: clarify requirements, find entities, model relationships, define APIs, apply patterns, handle concurrency and plan extensions.

Low-level design (LLD) is the work of turning a short problem statement, such as "design a parking lot", into classes, methods and relationships that a team could implement. It sits below high-level design, which decides which services, databases and queues exist. LLD asks smaller questions: Which classes? What does each one own? Which methods do they expose? Which patterns keep the code easy to change?

LLD problems are popular in interviews, but the skill is also what you use at work whenever you design a feature. People who struggle with them usually do not lack pattern knowledge. They lack a process. They start coding the first class that comes to mind and run out of time or clarity. This lesson gives you a framework you can apply to every project in this chapter and to any new problem.

The seven steps

Clarify Turn a vague prompt into requirements.
Entities Find the nouns that matter.
Relationships Who owns, uses or contains whom?
APIs Define the public methods first.
1 / 2

Why low-level design matters, and why it is hard

High-level design decides the big boxes: services, databases, queues. Low-level design decides what is inside one box: classes, interfaces, relationships, method signatures and the patterns that connect them. A good one makes the code easy to read, test and extend, and it is where requirements like "add a new payment type" are either cheap or painful.

It is hard for four reasons. Requirements are vague and keep changing. There is rarely one right answer, only trade-offs. Over-design (a pattern for every line) and under-design (one giant class) are both easy to fall into. And mistakes surface late, when changing a class that fifty others depend on is expensive.

Two small examples show the vocabulary you will use. In Order -> OrderItem an order has items and owns their life cycle (composition). In Payment <- UpiPayment, CardPayment the two concrete payments are kinds of payment and share one interface (inheritance or realization). The seven steps below are a way to reach those choices on purpose instead of by accident.

Step 1: clarify the requirements

The problem statement is deliberately incomplete. Before drawing anything, ask questions and write down the answers. Split them into two lists:

  • Functional requirements: what the system must do. "A car can enter, receive a ticket, and pay on exit."
  • Non-functional requirements and constraints: scale, concurrency, what is out of scope. "One building, up to 500 spots, several entrance gates."

Also say what you will not build, such as payment gateways, user interfaces or databases. This keeps the design small and avoids guessing. Good questions are about who uses the system (actors), what the main flows are and which rules can change (such as pricing).

Step 2: find the entities

Read your requirements and underline the nouns. Candidates for classes appear: vehicle, spot, ticket, gate. Underline the verbs too: park, pay, assign, release. Verbs become methods, and the noun that naturally "does" a verb becomes its owner.

Not every noun deserves a class. A noun with no behavior and no rules (a plate number) may just be a field. A noun with rules (a price that must not be negative) may deserve a small value object, as discussed in Anti-Patterns and Code Smells. Finally, separate entities (things with identity and a life cycle, like a ticket) from value objects (things defined by their value, like a duration).

JS From requirements to candidate entities

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice that "loan" never appeared as a noun in the requirements. The relationship between a member and a copy had behavior of its own (dates, a due date), so it became a class. Hidden entities like this are often the most valuable find.

Step 3: relationships

Now connect the entities. For each pair ask: does one contain the other, use it temporarily, or know about it? Review the UML vocabulary in Reading and Drawing UML for Low-Level Design if needed. Decide:

  • Ownership: who creates the object and controls its life? A parking lot owns its floors; a ticket does not own a vehicle.
  • Multiplicity: one-to-many, many-to-many? A member has many loans; a loan has exactly one copy.
  • Direction: who needs to reach whom? Avoid arrows in both directions unless you must have them.
  • Inheritance versus composition: prefer composition. Use inheritance only for a true "is a" with shared behavior, as covered in DRY, KISS, YAGNI and More.

A rough class diagram, even a quick sketch with boxes and lines, is worth drawing at this point. It shows gaps (an entity with no connections) and cycles.

Step 4: define the public API first

Before writing method bodies, write the signatures of the operations a user of your design would call. These form the system's public surface. For a parking lot this might be enter(vehicle), exit(ticketId) and availableSpots(type).

Writing the API first helps because:

  • it forces you to check that every requirement has an operation that serves it;
  • it separates what the system offers from how it works inside;
  • it reveals missing data (the exit operation needs a ticket id, so tickets need ids).

Keep the surface small. A facade-like class (a "service" or "controller" in your design) is a good place for it. See Facade.

Step 5: apply patterns where change is expected

Only now think about patterns, and use a simple test: which rules are likely to change? Pricing rules change, so use Strategy. Objects with life cycles change behavior by status, so use State. Objects that need creating by type suggest Factory Method. Parties that must be notified suggest Observer. Data access suggests a repository.

Do not add a pattern because it is in your head. Add it because you can point to the requirement or the likely change that it serves. Interviewers and teammates alike value "I used Strategy here because pricing changes" over a diagram full of pattern names.

Step 6: think about concurrency and failure

Real systems have many users acting at the same time. Ask, for every shared resource: what if two requests want this at once? Two cars should never get the same spot, and two members should not borrow the last copy of a book. Common answers are:

  • Mutual exclusion: make "check and take" one atomic operation (a lock, a synchronized method, or a single-threaded event loop).
  • Immutable data: values that never change cannot be corrupted by parallel access.
  • Idempotent operations: doing "release spot" twice must be harmless.
  • Failure paths: what happens on invalid input, on a full lot, on a double exit? Name the errors your API returns.

In JavaScript and Node, a single thread runs your code, so a synchronous "check and take" is already atomic. The danger returns when you await between checking and taking. Languages like Java and C++ need explicit locks. The parking-lot project shows this in detail.

Step 7: extensions and trade-offs

End by showing how the design would grow. "To add electric-vehicle charging spots, add a spot type and a pricing strategy. No existing class changes." If a new requirement would force edits across many classes, that tells you where the design is rigid. Mention trade-offs honestly. For example, an in-memory design is simple but loses data on restart, and a repository interface (see Repository and Unit of Work) is the seam where a real database would plug in.

A reusable skeleton

This example puts the steps together on a tiny parcel-locker problem. It starts with the API, stubs the strategy and shows a walk-through of the main use case. Running a walk-through (a "happy path") is the fastest way to find holes in a design.

JS A design skeleton with a walk-through

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The skeleton is short, yet it has a clear API, a strategy where rules may change, a value object and visible failure paths. In a real interview or review, you would also say what you left out (payment, expiry of codes, hardware).

Communicating while you design

  • Think aloud. State assumptions as you make them and invite correction.
  • Start simple, then deepen. A working core first, patterns and concurrency second.
  • Name trade-offs. Every design choice costs something. Saying so shows judgment.
  • Test the design with scenarios. Walk two or three flows through the classes, including a failing one.
  • Keep the time. If you only have 45 minutes, spend about 10 on requirements and entities, 15 on the API and classes, 15 on code or key methods, and 5 on extensions.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What should you do first when given a vague LLD prompt such as 'design a parking lot'?

    The prompt is intentionally incomplete. Requirements and scope decide every later choice.
  2. 2. Why define the public API before writing method bodies?

    Writing signatures first exposes missing data and unserved requirements while changes are still cheap.
  3. 3. When is it appropriate to use Strategy in an LLD answer?

    Point to the requirement or likely change that a pattern serves. That is what makes it justified.
  4. 4. In a single-threaded JavaScript program, where can a race condition on a shared resource still appear?

    An await lets other tasks run in between, so a check made before it may no longer be true afterward.

Summary

  • LLD turns a short problem statement into classes, relationships and APIs; a repeatable process matters more than recalling patterns.
  • Seven steps: clarify, find entities, define relationships, write the API, apply patterns where change is expected, handle concurrency and failures, show extensions.
  • Nouns suggest classes, verbs suggest methods, and hidden relationships such as a loan are often entities too.
  • Prefer composition and a small public surface; justify every pattern with a requirement.
  • Walk the main flow and a failing flow through your design to find gaps.
  • Say your assumptions and trade-offs out loud.

Next lesson: Project: Parking Lot.