Design Patterns & LLD
Gang of Four creational, structural, and behavioral patterns; SOLID principles applied to real code; microservice-level patterns; and the machine-coding problems (Parking Lot, Elevator, Rate Limiter) that low-level design rounds actually ask.
Creational Patterns (Java)
Singleton — Eager vs Lazy vs Double-checked locking vs Enum Singleton — compare all four approaches.
intermediateTests whether you know the tradeoffs in initialization timing, thread safety, and serialization safety across all four variants.
What is the Singleton pattern? Implement it using double-checked locking.
beginnerTests whether you can write a correctly synchronized Singleton, not just describe the pattern conceptually.
Can Singleton be broken? Name 4 ways (Reflection, Serialization, Cloning, Multithreading).
beginnerTests whether you know Singleton isn't actually bulletproof, and how to defend against each specific attack.
What is the difference between constructor overloading and constructor chaining?
intermediateTests whether you know one is about multiple constructor signatures and the other is about constructors calling each other via this().
What is the Factory Method pattern? How does it differ from Simple Factory?
beginnerTests whether you know Factory Method delegates creation to subclasses, unlike a single static factory method.
What is the Abstract Factory pattern? Give a real-world Java example.
intermediateTests whether you know how to produce families of related objects without specifying their concrete classes.
What is the Builder pattern? When should you use it over a constructor?
beginnerTests whether you know when a fluent step-by-step builder is more readable than a constructor with many optional parameters.
Design Patterns
What is the Prototype pattern? When would you use it over calling a constructor directly?
intermediateThe Prototype pattern creates new objects by cloning an existing, fully-configured instance (via a clone() method) rather than building one from scratch through a constructor. It's useful when object creation is expensive (e.g. involves a database call or heavy computation) or when you need many variants of a complex, pre-configured object — cloning a template is far cheaper than reconstructing it field-by-field each time.
What is the Facade pattern? How does it differ from Adapter?
intermediateFacade provides a single, simplified interface in front of a complex subsystem with many interacting classes, hiding that complexity from the client — e.g. a single `OrderFacade.placeOrder()` method that internally coordinates inventory, payment, and shipping services. Adapter also wraps something, but its purpose is different: Adapter converts one incompatible interface into another the client already expects, while Facade simplifies an interface the client would otherwise have to navigate directly.
Behavioral Patterns (Java)
Strategy pattern vs State pattern — both swap behavior at runtime, so what actually distinguishes them?
intermediateTests whether you know Strategy is chosen externally by the client, while State transitions are driven internally by the object itself.
Where is the Observer pattern used in real-world Spring applications?
intermediateTests whether you can connect the abstract pattern to Spring's own ApplicationEvent/ApplicationListener mechanism.
What is the Strategy pattern? Show an example (sorting strategies).
beginnerTests whether you know how to swap an algorithm's implementation at runtime without changing the calling code.
What is the Observer pattern? How does Java's EventListener relate to it?
beginnerTests whether you know the publish-subscribe relationship behind one of Java's oldest built-in event models.
What is the Template Method pattern? Where is it used in Spring (JdbcTemplate)?
intermediateTests whether you know how a base class fixes the algorithm's skeleton while letting subclasses fill in specific steps.
What is the Chain of Responsibility pattern? How does it differ from Command?
intermediateTests whether you know Chain of Responsibility passes a request along handlers while Command encapsulates a request as an object.
SOLID Principles
What is the Open-Closed Principle, and what does 'open for extension, closed for modification' actually mean in practice?
intermediateA class should be extendable to support new behavior without changing its existing, already-tested source code. In practice, this usually means depending on an abstraction (an interface) and adding new behavior by writing a NEW class that implements it, rather than adding another if/else branch to an existing class — e.g. adding a new PaymentMethod by creating a new class implementing a PaymentStrategy interface, instead of editing a giant switch statement inside PaymentProcessor.
What is the Liskov Substitution Principle, and what's a classic example of violating it?
intermediateSubtypes must be substitutable for their base type without altering the correctness of the program — anywhere a Base object is expected, a Derived object should work without surprising behavior. The classic violation is Square extending Rectangle: if setWidth() and setHeight() on Rectangle are independent, but Square must keep both equal, then a Square silently breaks any code that relies on Rectangle's contract (e.g. setting width to 5 and height to 10 and expecting area == 50).
What is the Interface Segregation Principle, and why do 'fat interfaces' violate it?
intermediateClients shouldn't be forced to depend on methods they don't use — a class implementing an interface should need every method on it, not just some. A 'fat interface' like Worker with work() and eat() methods forces a Robot implementation to provide a meaningless eat() method; splitting it into separate Workable and Eatable interfaces lets each class implement only what actually applies to it.
What is the Dependency Inversion Principle, and how does it differ from Dependency Injection?
intermediateDependency Inversion is a design PRINCIPLE stating that high-level modules shouldn't depend on low-level modules directly — both should depend on abstractions (interfaces). Dependency Injection is a PATTERN/TECHNIQUE for actually supplying those dependencies (typically via constructor) from the outside rather than a class creating them itself; using DI doesn't automatically guarantee DIP — you can inject a concrete class directly instead of an interface, which still violates the principle even though the dependency is technically 'injected.'
What are the SOLID principles? Name all 5 with one-line definitions.
beginnerTests whether you can rattle off SRP, OCP, LSP, ISP, and DIP cleanly under interview pressure.
Single Responsibility Principle — give a bad example and refactored good example.
beginnerTests whether you can actually spot an SRP violation in code and refactor it, not just define the principle.
Structural Patterns (Java)
Proxy pattern vs Decorator pattern — both wrap an object, so what's the real difference in intent?
intermediateTests whether you know Proxy controls access to the same interface while Decorator adds new behavior on top of it.
What is the Adapter pattern? Explain with a Java example.
beginnerTests whether you know how to make two incompatible interfaces work together without modifying either one.
What is the Decorator pattern? How is it used in java.io?
beginnerTests whether you can connect the pattern to something you've already used, like wrapping InputStream with BufferedInputStream.
What is the Proxy pattern? Explain the 3 types: Virtual, Remote, and Protection proxy.
intermediateTests whether you know the different reasons to interpose a proxy — lazy loading, network calls, or access control.
What is the Flyweight pattern? How does it save memory?
intermediateTests whether you know how sharing common object state across many instances reduces memory footprint.
OOP Fundamentals for LLD
Composition vs Inheritance — when should you prefer one over the other?
intermediateTests whether you know 'favor composition over inheritance' isn't a blanket rule but depends on whether an IS-A relationship genuinely holds.
What is the difference between aggregation and composition?
intermediateTests whether you know composition implies ownership and lifecycle dependency, while aggregation is a looser has-a relationship.
What is the Law of Demeter (Principle of Least Knowledge)?
intermediateTests whether you know why chaining calls through multiple objects (a.getB().getC().doSomething()) is a design smell.
What is immutability, and how do you design a genuinely immutable class in Java?
intermediateTests whether you know all the rules — final fields, no setters, defensive copying of mutable fields — not just marking a class final.
What is the difference between IS-A and HAS-A relationships? Give design examples.
beginnerTests whether you know when inheritance is appropriate versus when composition is the better design choice.
What is cohesion and coupling? How do you achieve high cohesion and loose coupling?
intermediateTests whether you understand the two core forces that determine how maintainable an object-oriented design actually is.
UML & Schema Design
How do you model class inheritance in a relational database?
intermediateTests whether you know the three standard strategies (single table, joined, table-per-class) and their tradeoffs.
How do you translate a UML class diagram into a database schema?
intermediateTests whether you know the mapping rules for associations, multiplicities, and inheritance from object model to relational tables.
What is a sequence diagram? Draw one for a user logging into an application.
intermediateTests whether you can visually communicate the order of interactions between objects during a login flow.
Machine Coding Problems
Design a Chess Game — pieces, moves, turn management, check/checkmate detection.
advancedTests whether you can model a rich rule system with polymorphic piece behavior cleanly in objects.
Design a task management system like Trello — boards, lists, cards, drag-and-drop ordering.
intermediateTests whether you can model a nested hierarchy with ordering that needs to stay consistent as items move around.
Design a Logger Framework — log levels, multiple appenders (console, file, remote).
intermediateTests whether you know how to design a pluggable appender architecture that's easy to extend without modifying existing code.
Design a text editor with undo/redo support.
advancedTests whether you know the Command pattern is the natural fit for reversible, replayable operations.
Design a Circuit Breaker component from scratch — CLOSED, OPEN, HALF-OPEN state machine.
advancedTests whether you can implement the actual state transitions and thresholds, not just describe the pattern.
Design a Restaurant Reservation System — tables, time slots, party size, conflict prevention.
advancedTests whether you can handle overlapping-interval conflict checks and thread-safe booking cleanly.
Design the classic Snake Game — grid, movement, food, collision detection, growth.
intermediateTests whether you can model game state and collision logic cleanly with simple data structures.
Design a Concurrent HashMap from scratch — how would you implement thread-safe bucket-level locking?
expertTests whether you can reason about fine-grained locking design, not just use java.util.concurrent.ConcurrentHashMap as a black box.
Design a Parking Lot System — multi-floor, vehicle types, fee calculation.
beginnerOne of the most common machine-coding rounds — tests whether you can model entities, allocate spots, and calculate fees cleanly.
Design a Vending Machine — product selection, payment, change, inventory.
beginnerTests whether you can model a state machine (idle, selecting, paying, dispensing) cleanly in object-oriented code.
Design an Elevator System — single elevator, request queue, floor movement.
intermediateTests whether you can design a request-scheduling algorithm and represent elevator state correctly.
Design a Movie Ticket Booking System (Bookmyshow) — seats, shows, booking.
intermediateTests whether you can model seats, shows, and concurrent booking without double-allocating the same seat.
Design a Splitwise / Expense Sharing App.
advancedTests whether you can model balances between multiple users and simplify debts efficiently.
Design an In-Memory Rate Limiter — Token Bucket, Sliding Window algorithms.
intermediateTests whether you can implement at least one real rate-limiting algorithm correctly, not just name it.
Design a Payment Gateway — multiple providers, retry, refund, idempotency.
advancedTests whether you can design around provider abstraction, safe retries, and idempotent payment processing.
Microservice Patterns — Decomposition
What is the Decompose by Business Capability pattern?
beginnerTests whether you know how to draw microservice boundaries around what the business does, not around technical layers.
What is the Backend for Frontend (BFF) pattern? When do you need separate gateways?
intermediateTests whether you know why a mobile client and a web client often need different API shapes from the same backend.
Microservice Patterns — Data & Resilience
What is the Outbox Pattern (Transactional Outbox)? How does it guarantee message delivery?
advancedTests whether you know how to atomically update a database and publish an event without a fragile dual-write.
What is the Idempotency pattern for APIs? How do you implement an idempotency key?
advancedTests whether you know how to make a retried request safe to process more than once without double-charging or double-booking.
Microservice Patterns — Deployment
What is the Sidecar pattern? What responsibilities does a sidecar container handle? How does Ambassador differ from it?
intermediateTests whether you know how a helper container extends a service's capabilities without changing the service's own code.
What is the Canary Deployment pattern? How does it reduce release risk?
intermediateTests whether you know how routing a small percentage of real traffic to a new version limits the blast radius of a bad release.
SOLID Principles in LLD
OCP: How do you extend a PaymentProcessor to add UPI without modifying existing code?
intermediateTests whether you can apply the Open/Closed Principle to a realistic scenario, not just quote its definition.
LSP: Give a classic violation example (Rectangle-Square problem) and how to fix it.
intermediateTests whether you know the textbook example of a subtype that technically extends a class but breaks its behavioral contract.
Concurrency in LLD
What is a race condition in LLD? Give a real example from a booking system.
intermediateTests whether you can connect the abstract concept of a race condition to a concrete double-booking bug.
How would you design a thread-safe LRU Cache?
advancedTests whether you know how to add correct synchronization to an LRU cache without serializing every single access.