Skip to main content
← CONCEPTS / SOFTWARE DESIGN & ARCHITECTURE
An end-to-end domain learning journey

Low-Level System Design: LRU Cache,
Elevator & Ticket Booking.

Low-Level Design (LLD) translates high-level requirements into clean class hierarchies, explicit state machines, concurrency-safe interfaces, and extensible design patterns inside a single service or library.
Start the journey7 sections· Last modified Oct 5, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When a single bottleneck threatens end-to-end availability, Elevator & Ticket Booking, great LLD isolates volatile business rules behind narrow interfaces and explicit state transitions so adding a new pricing rule, eviction policy, or booking workflow never breaks existing code.

TL;DR30-second simplified summary
▾

Core Mechanics: While High-Level Design (HLD) governs distributed services over networks, Low-Level Design (LLD) governs the internal architecture of a service or library: entities (identity + lifecycle), value objects (immutable.

Visual & Structural Flow: Depicts Ticket Seat Hold Lifecycle (Replacing Boolean Flag Soup) (AVAILABLE -> HELD (TTL) -> BOOKED); Guarding Check-Then-Act in Concurrent Seat Booking (User A Thread -> Striped Seat Lock -> Seat State -> User B Thread).

Trade-Offs & Production: Balance polymorphism against indirection, and striped locks against coarse synchronization. In production services, the LLD domain core (Entities, FSMs, Strategies) has zero framework or database imports—it depends only on narrow port interfaces (Clock, SeatStore.

Failure Modes & Application: Practice full end-to-end LLD implementations across caching, scheduling, and concurrency.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Distributed & Application Caching
Caching keeps a reusable copy of data so an application can avoid repeating a database query, calculation, or network call. It can make responses faster and reduce database load. The trade-off: the copy may be out of date.
Full walkthrough · 7 stages
01
STAGE 01 · WHAT IT ISL4 · FUNDAMENTALS

What is Low-Level System Design (LLD).

Why this matters: The mechanism: understand how Low-Level System Design (LLD) works from first principles.

While High-Level Design (HLD) governs distributed services over networks, Low-Level Design (LLD) governs the internal architecture of a service or library: entities (identity + lifecycle), value objects (immutable, equality by value), and stateless domain services.

Clean LLD models lifecycles as explicit Finite State Machines (FSMs) and isolates volatile rules behind Strategy, State, Observer, and Command interfaces.

Explicit FSM Design

Ticket Seat Hold Lifecycle (Replacing Boolean Flag Soup)

holdSeat(user, ttl)confirmPayment(txId)TTL expired / cancelAVAILABLEOpen for selectionHELD (TTL)Locked + expiresAtBOOKEDPayment confirmed

A single enum-backed State Machine eliminates impossible combinations like isHeld=true && isBooked=true.

02
STAGE 02 · WHY WE NEED ITL4 · FUNDAMENTALS

Why boolean flags and check-then-act races break services.

Why this matters: The problem: see what breaks without Why boolean flags and check-then-act races break services under real concurrency or scale.

Poor LLD produces god classes, brittle if-else trees, and concurrency bugs at 100k+ lines of code.

Two failure modes recur constantly: boolean flag explosion (isActive, isPaused, isDeleted allowing illegal states) and check-then-act race conditions where two threads both see spot.isFree() == true and issue duplicate tickets.

Atomic Reservation

Guarding Check-Then-Act in Concurrent Seat Booking

User A ThreadStriped Seat LockSeat StateUser B Thread1. Acquire lock(seatId)2. Blocks on lock(seatId)3. AVAILABLE -> HELD (TTL 5m)4. Reads HELD -> 409 Conflict

Making check-and-reserve atomic under a per-entity lock or optimistic CAS prevents double-booking.

Engineering Decision Framework
Problem
How to implement Low-Level System Design: LRU Cache, Elevator & Ticket Booking without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
When a single bottleneck threatens end-to-end availability, elevator & Ticket Booking, great LLD isolates volatile business rules behind narrow interfaces and explicit state transitions so adding a new pricing rule, eviction policy, or booking workflow never breaks existing code.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Low-Level System Design: LRU Cache, Elevator & Ticket Booking experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
STAGE 03 · WHERE IT IS USEDL5 · APPLIED DESIGN

Where LLD rigor pays off (and where to keep it simple).

Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

Think of Where LLD rigor pays off (and where to keep it simple) as the intuition layer for Low-Level System Design: LRU Cache, Elevator & Ticket Booking: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

Apply full domain modeling to core engines with evolving rules and concurrent state.

ChoiceWhat it buysWhat it costs
Good Candidate: Core Engines & SDKsRate limiters, LRU caches, order matchers, elevator/parking schedulers, and payment pipelines.More upfront interfaces and unit test scaffolding.
Avoid: One-Off Scripts & Glue CodeKeep 100-line migration scripts procedural; don't add 6 AbstractFactory layers before a second variant exists.Premature abstraction scatters trivial logic across dozens of files.
04
STAGE 04 · HOW IT IS MANAGEDL5 · APPLIED DESIGN

Explicit Transition Table + Striped Locking.

Why this matters: Operational control: configure bounds, failure handling, and safe production defaults.

Think of Explicit Transition Table + Striped Locking as the intuition layer for Low-Level System Design: LRU Cache, Elevator & Ticket Booking: Operational control: configure bounds, failure handling, and safe production defaults.

Define an explicit (currentState, event) -> nextState transition map and inject Clock and Repository interfaces so time-dependent TTL logic is 100% unit-testable.

Lifecycle & Failure Recovery

Explicit Transition Table + Striped Locking

TTL expiredconcurrent missessingleflight lockvalue cachedCache HitCache MissHot-Key StampedeCoalesced Fill
public enum SeatStatus { AVAILABLE, HELD, BOOKED }

public final class Seat {
    private SeatStatus status = SeatStatus.AVAILABLE;
    private Instant holdExpiresAt = Instant.EPOCH;
    private final ReentrantLock lock = new ReentrantLock();

    public boolean tryHold(Instant now, Duration ttl) {
        lock.lock();
        try {
            if (status == SeatStatus.BOOKED) return false;
            if (status == SeatStatus.HELD && now.isBefore(holdExpiresAt)) return false;
            status = SeatStatus.HELD;
            holdExpiresAt = now.plus(ttl);
            return true;
        } finally {
            lock.unlock();
        }
    }
}
05
STAGE 05 · ALTERNATIVESL6 · SCALE & TRADE-OFFS

Alternatives: Pattern Extensibility vs. Procedural Simplicity.

Why this matters: The trade-off: compare competing approaches across latency, consistency, and operational cost.

Think of Alternatives: Pattern Extensibility vs. Procedural Simplicity as the intuition layer for Low-Level System Design: LRU Cache, Elevator & Ticket Booking: The trade-off: compare competing approaches across latency, consistency, and operational cost.

Balance polymorphism against indirection, and striped locks against coarse synchronization.

Component Topology

Alternatives: Pattern Extensibility vs. Procedural Simplicity

App ServersingressSingleflightcomputeRedis L2storagePrimary DBcontrolGET hot_keyL2 lookup1x origin fetch
ChoiceWhat it buysWhat it costs
Interfaces + Strategy/StateTrivial to swap algorithms, mock clocks/stores, and add variants without touching callers.Over-abstracting stable code slows onboarding.
Striped Per-Entity LocksHigh multi-core throughput across independent seats/accounts.Multi-entity transfers require canonical lock ordering to avoid deadlocks.
06
STAGE 06 · PRODUCTION ARCHITECTUREL7 · STAFF / PRINCIPAL

Clean Domain Core + Pluggable Adapters (Hexagonal LLD).

Why this matters: Production architecture: see how the components compose end to end under real load.

Think of Clean Domain Core + Pluggable Adapters (Hexagonal LLD) as the intuition layer for Low-Level System Design: LRU Cache, Elevator & Ticket Booking: Production architecture: see how the components compose end to end under real load.

In production services, the LLD domain core (Entities, FSMs, Strategies) has zero framework or database imports—it depends only on narrow port interfaces (Clock, SeatStore, PaymentGateway), allowing deterministic in-memory unit tests at 10,000 tests/sec.

Request & State Flow

Clean Domain Core + Pluggable Adapters (Hexagonal LLD)

App WorkerSingleflight / L1Redis L2Origin DB1. GET key (coalesce duplicates)2. Check L2 distributed cache3. Single origin query on miss4. Populate cache with jitteredTTL

Inject Clock, Never Call Instant.now() Directly

Testing 5-minute seat-hold expiry takes 0 ms when time is injected via java.time.Clock.

Lock Ordering for Multi-Seat Checkout

Sort selected seatIds before acquiring Seat.lock to guarantee deadlock-free group bookings.

07
STAGE 07 · PROBLEMS SOLVED & FURTHER DEEP DIVEL7 · STAFF / PRINCIPAL

Classic LLD Problems & Design Concepts.

Why this matters: Applied problems: connect these internals to concrete system design and debugging scenarios.

Think of Classic LLD Problems & Design Concepts as the intuition layer for Low-Level System Design: LRU Cache, Elevator & Ticket Booking: Applied problems: connect these internals to concrete system design and debugging scenarios.

Practice full end-to-end LLD implementations across caching, scheduling, and concurrency.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why should an LLD Seat or Order entity replace independent booleans (isHeld, isBooked, isCancelled) with a single enum-backed State Machine?

Recommended Learning Flow