When an interviewer introduces a new pricing, eviction, or allocation rule mid-round, isolate the varying behavior behind a Strategy or State interface so existing orchestration logic stays untouched.
TL;DR30-second simplified summary▾
Mid-interview requirement pivots test whether your code obeys the Open-Closed Principle.
Inject swappable policies (PricingStrategy, EvictionPolicy) via constructors and decouple storage behind Repository interfaces.
Write deterministic unit tests covering both happy paths and invalid state transitions.
Why This Blueprint Exists & Core Evaluation Contract.
Why this matters: Establish the LLD evaluation rubric, time pacing, and clean OOP/concurrency contract.
LLD interviews evaluate whether your code stays maintainable as requirements evolve mid-interview (e.g., adding a new pricing rule, eviction policy, or vehicle type). Applying SOLID principles, Strategy/Factory/Observer patterns, and explicit concurrency control separates senior engineers from candidates who write monolithic if/else blocks.
When to Apply This Blueprint:
- 45–60 minute Machine Coding or LLD rounds (LRU Cache, Parking Lot, Elevator, Splitwise, Ticket Booking, Rate Limiter).
- Designing modular, unit-testable service components.
Core Evaluation Checkpoints:
- Step 1 (Clarify Entities & Use Cases): List core actors, state transitions, and edge cases (e.g., double-booking, concurrent eviction).
- Step 2 (Interfaces & Composition over Inheritance): Use Strategy for swappable policies (eviction, pricing, allocation) and Repository interfaces for storage.
- Step 3 (Concurrency & Thread Safety): Explicitly identify shared mutable state and guard it with fine-grained locks,
ConcurrentHashMap, or atomic CAS. - Step 4 (Clean Runnable Code & Tests): Write clean, compile-ready Java or Python with happy-path and concurrency/edge-case tests.
Applying LLD Discipline Under Interview Time Pressure
- Monolithic if/else blocks
- Shared state race conditions
- Deep rigid inheritance
- Entities & invariants first
- Strategy & Repository interfaces
- Thread-safe state & unit tests
Concrete Problem Specializations & Design Trade-Offs.
Why this matters: Connect the LLD blueprint to concrete worked problems and class-level trade-off dimensions.
Concrete LLD problem articles specialize this blueprint with domain-specific entities, invariants, concurrency primitives, and runnable Java/Python implementations.
Core LLD Trade-Offs:
- Coarse vs. Fine-Grained Locking: A single
ReentrantLockis simple and deadlock-free for moderate contention, whereas striped or per-entity locks scale under multi-threaded load if lock ordering is enforced. - Composition vs. Inheritance: Composing
PricingStrategyorEvictionPolicyinterfaces avoids subclass explosion when rules combine.
Specializing the LLD Blueprint Across Classic Problems
- Problem
- How to structure extensible domain logic and shared mutable state in an LLD interview without creating rigid inheritance hierarchies or race conditions.
- Naive Solution
- Put all conditional rules in a single monolithic service class with deep subclassing and unsynchronized in-memory collections.
- Why It Fails
- Adding a new rule forces edits across existing conditionals (violating Open-Closed), while concurrent callers corrupt shared state or trigger ConcurrentModificationException.
- Alternatives
- Compare coarse-grained global locking (synchronized / single Lock) against fine-grained striped locks, lock-free CAS, or immutable value objects with Strategy/State interfaces.
- Engineering Decision
- Model behavior behind small cohesive interfaces (Strategy, State, Repository) using composition, and guard only the minimal critical section of shared state with explicit locks or atomic primitives.
- Trade-Offs
- Gains Open-Closed extensibility, unit testability, and thread safety in exchange for a few extra interface files and explicit lock-ordering discipline.
Midway through a Parking Lot or Rate Limiter LLD interview, the interviewer asks you to support a new surge-pricing rule and concurrent requests from multiple entry gates. Which design change best satisfies both?
Pacing & Evaluation Matrix.
Why this matters: Map the 45–60 minute LLD interview rubric across modularity, extensibility, concurrency, and edge-case handling.
Preparation & Execution Matrix
| LLD Focus Area | What Interviewers Look For | Example Pattern | | :--- | :--- | :--- | | Modularity | Small cohesive classes, single responsibility | Service + Repository + Domain Model | | Extensibility | Add new rule without editing caller/service | Strategy / State / Factory | | Concurrency | Zero race conditions, minimal critical sections | Striped locks, ReadWriteLock, ReentrantLock, CAS | | Memory & Lifecycle | Bounded state (no OOM), long IDs, clean shutdown | Ring buffer / LRU cap, AutoCloseable / close() | | Edge Cases | Nulls, capacity=0, negative values, duplicates | Guard clauses + IllegalArgumentException / IllegalStateException |
Preparation & Execution Matrix
| LLD Focus Area | What Interviewers Look For | Example Pattern | | :--- | :--- | :--- | | Modularity | Small cohesive classes, single responsibility | Service + Repository + Domain Model | | Extensibility | Add new rule without editing caller/service | Strategy / State / Factory | | Concurrency | Zero race conditions, minimal critical sections | Striped locks, ReadWriteLock, ReentrantLock, CAS | | Memory & Lifecycle | Bounded state (no OOM), long IDs, clean shutdown | Ring buffer / LRU cap, AutoCloseable / close() | | Edge Cases | Nulls, capacity=0, negative values, duplicates | Guard clauses + IllegalArgumentException / IllegalStateException |
Executing a 45-Minute LLD Interview Session
Time-boxed structure leaves dedicated room for requirement pivots, thread safety, and edge-case tests.
Runnable Reference Templates (Python & Java).
Why this matters: Provide compile-ready Python and Java Strategy pattern templates with defensive input validation.
Reference Templates (Python & Java)
# Strategy pattern for extensible LLD pricing/allocation (Python)
from abc import ABC, abstractmethod
class PricingStrategy(ABC):
@abstractmethod
def calculate_fee(self, minutes: int) -> float:
pass
class FlatHourlyPricing(PricingStrategy):
def __init__(self, hourly_rate: float = 5.0) -> None:
if hourly_rate < 0:
raise ValueError("hourly_rate must be non-negative")
self._hourly_rate = hourly_rate
def calculate_fee(self, minutes: int) -> float:
if minutes < 0:
raise ValueError("minutes must be non-negative")
if minutes == 0:
return 0.0
hours = (minutes + 59) // 60
return hours * self._hourly_rate// Strategy pattern for extensible LLD pricing (Java)
public interface PricingStrategy {
double calculateFee(long minutes);
}
public final class FlatHourlyPricing implements PricingStrategy {
private final double hourlyRate;
public FlatHourlyPricing(double hourlyRate) {
if (hourlyRate < 0) {
throw new IllegalArgumentException("hourlyRate must be non-negative");
}
this.hourlyRate = hourlyRate;
}
@Override
public double calculateFee(long minutes) {
if (minutes < 0) {
throw new IllegalArgumentException("minutes must be non-negative");
}
if (minutes == 0) {
return 0.0;
}
long hours = (minutes + 59) / 60;
return hours * hourlyRate;
}
}Reference Templates (Python & Java)
# Strategy pattern for extensible LLD pricing/allocation (Python)
from abc import ABC, abstractmethod
class PricingStrategy(ABC):
@abstractmethod
def calculate_fee(self, minutes: int) -> float:
pass
class FlatHourlyPricing(PricingStrategy):
def __init__(self, hourly_rate: float = 5.0) -> None:
if hourly_rate < 0:
raise ValueError("hourly_rate must be non-negative")
self._hourly_rate = hourly_rate
def calculate_fee(self, minutes: int) -> float:
if minutes < 0:
raise ValueError("minutes must be non-negative")
if minutes == 0:
return 0.0
hours = (minutes + 59) // 60
return hours * self._hourly_rate// Strategy pattern for extensible LLD pricing (Java)
public interface PricingStrategy {
double calculateFee(long minutes);
}
public final class FlatHourlyPricing implements PricingStrategy {
private final double hourlyRate;
public FlatHourlyPricing(double hourlyRate) {
if (hourlyRate < 0) {
throw new IllegalArgumentException("hourlyRate must be non-negative");
}
this.hourlyRate = hourlyRate;
}
@Override
public double calculateFee(long minutes) {
if (minutes < 0) {
throw new IllegalArgumentException("minutes must be non-negative");
}
if (minutes == 0) {
return 0.0;
}
long hours = (minutes + 59) / 60;
return hours * hourlyRate;
}
}Decoupled Fee Calculation & Thread-Safe Checkout Flow
Constructor-injected Strategy keeps CheckoutService unchanged when new pricing rules are introduced.
Practice: Make the trade-off yourself.
In the first 5–10 minutes of an LLD interview, what should you establish before writing implementation classes?