The inside of one part: classes, responsibilities, interfaces and the patterns that keep code easy to change.
Low-level design (LLD) is the design inside one part of a system: which classes exist, what each one is responsible for, how they connect, and which interfaces keep the code easy to change.
Once the big picture is drawn (see High-Level Design (HLD)), someone still has to write the code inside each service. LLD is the plan for that code. It is about objects and their relationships: what data each one holds, what it can do, and who it depends on.
A good LLD is not about drawing nice diagrams. It is about making change cheap. Requirements will change next month: a new payment type, a new vehicle, a new notification channel. A design that handles this by adding a class is healthy. A design that handles it by editing five existing classes is a warning sign.
interface PricingStrategy {
price(minutes: number): number;
}
class HourlyPricing implements PricingStrategy {
price(minutes: number) { return Math.ceil(minutes / 60) * 2; }
}
class Ticket {
constructor(private pricing: PricingStrategy) {}
fee(minutes: number) { return this.pricing.price(minutes); }
}Ticket does not know how pricing works. To add a monthly-pass rule you write a new class that implements PricingStrategy. Ticket never changes.
| High-Level Design (HLD) | Low-Level Design (LLD) | |
|---|---|---|
| Scope | The whole system | One service, module or feature |
| Pieces | Services, databases, caches, queues | Classes, interfaces, methods |
| Typical artifacts | Architecture diagram, data flow, API list | Class diagram, sequence diagram, schema, code skeleton |
| Audience | Architects, product, other teams | The developers who write and review the code |
| Questions answered | Where is data stored? How does it scale? | Who owns this rule? How do I add a new type? |
| Done when | Boxes and flows meet the requirements | Responsibilities and interfaces are clear enough to code |
| If skipped | The system cannot scale or survive failures | The code becomes tangled and hard to change |
| Idea | In plain words | A sign you broke it |
|---|---|---|
| Single responsibility | A class has one reason to change | A class that prints, saves and calculates |
| Open / closed | Open for extension, closed for editing | Adding a type means editing an if/else chain |
| Liskov substitution | A subclass can stand in for its parent without surprises | A subclass that throws “not supported” |
| Interface segregation | Small, focused interfaces | Classes forced to implement methods they never use |
| Dependency inversion | Depend on interfaces, not on concrete classes | new MySqlDatabase() deep inside business logic |
| Pattern | One line | Use it when |
|---|---|---|
| Strategy | Swap one rule for another behind an interface | Pricing, sorting, routing, validation |
| Factory | One place that decides which class to create | The type depends on input or config |
| Observer | Many listeners are told when something changes | Events, notifications, UI updates |
| State | An object changes behaviour as its state changes | Vending machine, order status, elevator |
| Builder | Build a complex object step by step | Many optional fields |
| Decorator | Wrap an object to add behaviour | Logging, caching, compression layers |
| Adapter | Make one interface look like another | Wrapping a third-party library |
| Command | Turn an action into an object | Undo, queues, job scheduling |
| Singleton | Exactly one instance, shared | Rarely. It hides dependencies and makes tests hard |
A teaching model with fixed rules, not a measurement of real code. Score = 100 minus 30 for each existing class you must edit, minus 8 if only the wiring file changes. Real projects vary, but the direction is the same: new behaviour should arrive as new code, not as edits to old code.
// 1. A new entry in the vehicle type list
enum VehicleType { Car, Bike, Truck, Electric }
// 2. Spots say which types they accept (data, not if/else)
class Spot {
constructor(readonly accepts: Set<VehicleType>) {}
canFit(v: Vehicle) { return this.accepts.has(v.type); }
}
// 3. If pricing differs, add one new class and register it
class EvChargingPricing implements PricingStrategy {
price(minutes: number) { return Math.ceil(minutes / 60) * 3; }
}ParkingLot, Level and Ticket are untouched. That is the open / closed idea in action.
| Term | Meaning in easy words |
|---|---|
| LLD | Low-level design: the design of classes and interfaces inside one part of a system |
| Entity | A thing in the problem that gets its own class, such as Ticket |
| Responsibility | The one job a class is trusted to do |
| Interface | A contract listing what a class can do, without saying how |
| Inheritance (is-a) | A class that extends another and takes on its behaviour |
| Composition (has-a) | A class that holds other objects and uses them |
| Coupling | How much one class depends on another. Lower is better |
| Cohesion | How well the parts inside one class belong together. Higher is better |
| SOLID | Five guidelines: single responsibility, open/closed, Liskov, interface segregation, dependency inversion |
| Dependency injection | Passing a class its helpers from outside instead of creating them inside |
| Design pattern | A named, reusable solution to a common design problem |
| God class | One huge class that knows and does too much |
| Class diagram | A UML picture of classes, their fields, methods and relationships |
| Sequence diagram | A UML picture of who calls whom, in order, for one use case |
| Choice | We gain | We lose |
|---|---|---|
| Interface + several classes | Easy to extend and test | More files, a bit more setup |
| One simple class | Fast to write and read | Hard to extend once rules multiply |
| Composition | Swap parts at run time | More wiring code |
| Inheritance | Shares code quickly | Deep trees are rigid and fragile |
| Dependency injection | Easy tests with fakes | Needs a place to wire things together |
| Design up front | Fewer rewrites for stable problems | Wasted effort if requirements shift |
| Interviewers look for | What it looks like |
|---|---|
| A clean model | Sensible classes with clear names and one job each |
| Extensibility | A new type or rule is a new class, not edits everywhere |
| Readable code | Small methods, clear names, no clever tricks |
| Edge cases | Full, empty, invalid, duplicate and failure paths handled |
| Not over-engineered | Patterns used where they help, and explained |
| Concurrency awareness | You mention shared state and say how you would guard it |