LOAD-BEARINGfree
Low-level designTier 2 · unit 3 of 5 · 14 min read

The patterns that actually show up

The famous Gang of Four book catalogued 23 design patterns. Here's the field report from actual interviews and actual codebases: six of them do almost all the work. Learn these six deeply — the problem each solves, not just the name — and you're covered for the vast majority of low-level design questions you'll ever face.

Strategy — swap the algorithm at runtime

The situation: a requirement says "depending on X, do Y differently" — and the list of X's will grow. Pricing rules (weekday/weekend/event). Parking spot allocation. Feed ranking. Retry policies. Split calculations.

The move: define an interface for the varying behaviour (PricingStrategy.price(ticket)), write one class per variant, and inject the right one. The host object doesn't know or care which strategy it holds. New variant = new class, zero edits to existing code — you'll recognise Open/Closed from last lesson wearing a costume.

This is, without exaggeration, the single highest-value pattern in design interviews. When you hear "the rules vary," your hands should already be typing an interface.

Factory — centralise the construction decision

The situation: creating an object requires a decision (which subclass? which config?) and that decision would otherwise be copy-pasted everywhere anything gets created.

The move: one place — PaymentFactory.create(type) — owns the deciding and the assembling. Callers ask; they don't construct. The payoff: new stops leaking into business logic, and when construction changes (new subtype, new required dependency), one file changes instead of thirty call sites.

Observer — announce, don't orchestrate

The situation: when an order is placed, five things must happen: update inventory, send email, log analytics, notify the warehouse, award loyalty points. The naive version has OrderService calling all five directly — meaning it must know all five, and grows a new call with every new requirement.

The move: flip it. The order service publishes an event — "OrderPlaced" — and interested parties subscribe. The publisher doesn't know its audience; new subscribers attach without the publisher changing. File this pattern carefully: it is the in-process ancestor of the event-driven architectures in Tier 6. Same idea, bigger stage.

State — when behaviour depends on mode

The situation: an order moves through Placed → Paid → Shipped → Delivered, with Cancelled lurking. Each state permits different actions: you can cancel a Placed order, not a Shipped one. The naive version: every method starts with a thicket of if (status == ...) checks, duplicated and drifting out of sync.

The move: one class per state; each state class implements only its legal transitions. ShippedState simply has no cancel() that succeeds. Illegal transitions become structurally impossible rather than merely discouraged by conditionals someone will eventually get wrong.

Decorator — layer behaviour like wrapping paper

The situation: you need logging, caching, retries, or auth around an existing call, without editing the thing being called — and in mixable combinations.

The move: wrappers that implement the same interface as the thing they wrap: new RetryDecorator(new LoggingDecorator(realService)). Each layer adds one behaviour and delegates inward. You already use this daily — HTTP middleware is Decorator. (And that coffee-shop pricing exercise — coffee + milk + syrup, price each combination — that interviewers love? It's a Decorator question in an apron.)

Singleton — one instance, handled with care

The situation: some things genuinely should exist once — a database connection pool, a config registry.

The honest warning: Singleton is global mutable state in a trench coat. It hides dependencies (code silently reaches for getInstance() instead of declaring what it needs), makes tests order-dependent (state leaks between tests), and the classic getInstance() with lazy initialisation needs careful locking to be thread-safe. The modern move: let your dependency-injection container create one instance and hand it to whoever declares the need. Same single instance, none of the hidden-global disease.

The trap

Naming patterns instead of solving problems. "I'll use an Abstract Factory Builder Facade here" tells a reviewer you've read a book, not that you understand the problem. The winning order is: describe the requirement ("pricing varies and will grow"), derive the structure ("so I'll separate it behind an interface, one class per rule"), and name the pattern in passing ("— a Strategy"). Requirement first, name last.