LLD Hub
Learn

Strategy in LLDSwap algorithms at runtime

Encapsulate algorithms behind one interface. · Swap strategy at runtime (user tier, promo, payment rail).

Watch

Watch, then scroll down for code and practice.

In code

Fare strategiesTypeScript
interface FareStrategy {
  compute(km: number): number;
}

class EconomyFare implements FareStrategy {
  compute(km: number) {
    return 8 * km;
  }
}

class PremiumFare implements FareStrategy {
  compute(km: number) {
    return 15 * km;
  }
}

📘 Key ideas

Problem

Payment gateway needs to support UPI, Card, NetBanking. Ride fare calculation needs Economy vs Premium pricing. Hard-coding these creates brittle switch-cases.

Solution

Define a Strategy interface. Each algorithm is a class. The context accepts a strategy and delegates to it.

Composable

Strategies can be combined. A fare calculator might apply a BaseStrategy + SurgeStrategy + PromoStrategy in sequence.

Relation to OCP

Strategy is the mechanism that makes OCP achievable — new algorithms are new classes, no existing code changes.

🧠 Practice — Apply What You Learned

Parking Lot System

Design a parking lot system that can handle multiple floors, different vehicle types, and

FreeL2 · Easy

Library Management System

Design a library system where members can search, borrow, and return books. Librarians can

L1 · Easy

ATM Machine

Design an ATM system that handles card authentication, balance inquiry, cash withdrawal, a

L3 · Medium

Tic Tac Toe Game

Design a Tic Tac Toe game supporting 2 players (human or AI) on an N×N board.

L1 · Easy

Logger / Logging Framework

Design a flexible logging framework that supports multiple log levels, formatters, and out

L2 · Easy

Food Delivery System (Swiggy/Zomato)

Design a food delivery platform where customers can browse restaurants, place orders, and

L5 · Intermediate

Chat Application (WhatsApp-like)

Design a messaging system supporting 1-on-1 chats, group chats, message status, and media

L5 · Intermediate

Notification System

Design a notification service that can send alerts via multiple channels based on user pre

L4 · Medium

Ride Sharing System (Uber/Ola)

Design a ride sharing platform where riders request rides and drivers accept them.

L6 · Intermediate

LRU Cache System

Design an in-memory cache system with LRU eviction policy, TTL support, and thread safety.

L4 · Medium

Elevator System

Design an elevator control system for a building with multiple elevators and floors.

L7 · Hard

Payment Gateway

Design a payment processing system that handles transactions across multiple payment metho

L8 · Hard

Distributed Job Scheduler

Design a job scheduling system that can queue, execute, and monitor background jobs with r

L9 · Expert

Movie Ticket Booking (BookMyShow)

Design a movie ticket booking platform with seat selection, concurrent booking safety, and

L6 · Intermediate

Inventory Management System

Design an inventory system for an e-commerce warehouse with stock tracking, reordering, an

L5 · Intermediate

Hotel Booking System

Design a hotel room booking platform with availability search, pricing, and reservation ma

L6 · Intermediate

Expense Splitter (Splitwise-like)

Design an app that tracks shared expenses and calculates who owes whom in a group.

L5 · Intermediate

Social Media Feed (Twitter/Instagram)

Design a social media platform with posts, follows, and a personalized news feed.

L7 · Hard

URL Shortener (bit.ly)

Design a URL shortening service that generates short aliases, handles redirects, and track

L4 · Medium

Rate Limiter

Design a rate limiting service that restricts request rates per user/IP using multiple alg

L7 · Hard

Event Ticketing System

Design a large-scale event ticketing platform (like Ticketmaster) with high concurrency su

L8 · Hard

🚀 Now apply what you learned

Pick a problem above, write your solution, and get AI feedback on your design.

Start Practice →