HLD vs LLD: High Level vs Low Level Design Explained
HLD vs LLD with one example designed at both levels: what each covers, deliverables, interview rounds, a comparison table and how to prepare for both.
On this page · 5 sections
High level design (HLD) decides which systems exist and how they talk: services, databases, caches, queues, and how data flows between them. Low level design (LLD) decides how one of those pieces is built inside: its classes, interfaces, methods, data structures and the rules they enforce. HLD answers “what boxes, and why?”; LLD answers “what code goes in this box?”
The quickest way to see the difference is to design the same thing twice. Below, a URL shortener gets a high level design and then a low level design, followed by a side-by-side comparison, what interviewers expect in each round, and how to prepare.
HLD vs LLD at a glance
| High level design (HLD) | Low level design (LLD) | |
|---|---|---|
| Question it answers | Which components exist and how do they interact? | How is each component built? |
| Unit of design | Services, databases, caches, queues, CDNs | Classes, interfaces, methods, data structures |
| Main concerns | Scale, availability, latency, consistency, cost | Correctness, extensibility, readability, testability |
| Typical diagrams | Architecture / component diagram, data flow, sequence across services | Class diagram, sequence within a service, state diagram |
| Numbers you discuss | QPS, storage per year, cache hit rate, replication factor | Time and space complexity of operations |
| Key trade-offs | SQL vs NoSQL, sync vs async, cache strategy, sharding key | Inheritance vs composition, which design pattern, thread safety |
| Who usually owns it | Architects, senior and staff engineers | The engineers implementing the component |
| Interview round | System design round | Machine coding / object-oriented design round |
The same system at both levels: a URL shortener
Requirements for both: create a short link for a long URL, redirect a short code to its URL, optional custom alias, optional expiry, count clicks.
The high level design
At this level you estimate load, pick the building blocks and explain how a request flows through them. Assume 100 million new links a month and 100 reads for every write:
- Writes: 100M / (30 × 86,400 s) ≈ 40 per second; reads ≈ 4,000 per second, with peaks several times higher.
- Storage: roughly 500 bytes per row × 100M × 12 months ≈ 600 GB a year.
+--------------------+
client ---> | Load balancer |
+---------+----------+
|
+----------v-----------+ +---------------------+
| Stateless API/app | -----> | ID ranges (ticket |
| servers (N copies) | | server / ZooKeeper)|
+---+--------------+---+ +---------------------+
| |
read path | | write path
+---------v---+ +-----v------------------------+
| Redis cache | -> | Key-value / SQL store, |
| (hot codes) | | sharded by short code |
+-------------+ +------------------------------+
|
+--> click events --> Kafka --> analytics store
HLD decisions and why:
- Short codes from a counter in base62, with each app server leasing a block of IDs, so codes are unique without a database round trip per write. Seven base62 characters give 62⁷ ≈ 3.5 trillion codes.
- Cache-aside Redis in front of the store, because reads outnumber writes 100:1 and popular links are very hot.
- A key-value or SQL store sharded by code: lookups are always by code, so there are no cross-shard queries.
- Click counting through a queue (Kafka) so redirects don’t wait on analytics writes.
- 301 vs 302 redirect: 302 if you need to count every click, since browsers cache 301s.
The URL shortener lesson in the System Design course goes through this design in full.
The low level design
Now zoom into the app server. LLD is about the classes and their contracts: what’s an interface, what’s swappable, where the rules (valid URL, expiry, unique alias) live, and what happens with concurrent requests.
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from datetime import datetime, timedelta, timezone
import itertools
import threading
ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
def to_base62(n: int) -> str:
if n == 0:
return ALPHABET[0]
out = []
while n:
n, r = divmod(n, 62)
out.append(ALPHABET[r])
return "".join(reversed(out))
@dataclass
class ShortUrl:
code: str
long_url: str
created_at: datetime
expires_at: datetime | None = None
clicks: int = 0
def is_expired(self, now: datetime) -> bool:
return self.expires_at is not None and now >= self.expires_at
class UrlRepository(ABC):
"""Storage is an interface, so the service doesn't care if it's memory, MySQL or DynamoDB."""
@abstractmethod
def save(self, url: ShortUrl) -> None: ...
@abstractmethod
def find(self, code: str) -> ShortUrl | None: ...
class InMemoryUrlRepository(UrlRepository):
def __init__(self):
self._rows: dict[str, ShortUrl] = {}
self._lock = threading.Lock()
def save(self, url: ShortUrl) -> None:
with self._lock:
if url.code in self._rows:
raise KeyError(f"code {url.code!r} already taken")
self._rows[url.code] = url
def find(self, code: str) -> ShortUrl | None:
return self._rows.get(code)
class CodeGenerator(ABC):
@abstractmethod
def next_code(self) -> str: ...
class CounterCodeGenerator(CodeGenerator):
"""Base62 of a counter. In the HLD this counter comes from a ticket server or ID ranges per node."""
def __init__(self, start: int = 100_000):
self._counter = itertools.count(start)
self._lock = threading.Lock()
def next_code(self) -> str:
with self._lock:
return to_base62(next(self._counter))
class UrlShortenerService:
def __init__(self, repo: UrlRepository, codes: CodeGenerator, clock=lambda: datetime.now(timezone.utc)):
self.repo, self.codes, self.clock = repo, codes, clock
def shorten(self, long_url: str, ttl: timedelta | None = None, alias: str | None = None) -> str:
if not long_url.startswith(("http://", "https://")):
raise ValueError("only http(s) URLs")
now = self.clock()
code = alias or self.codes.next_code()
self.repo.save(ShortUrl(code, long_url, now, now + ttl if ttl else None))
return code
def resolve(self, code: str) -> str | None:
url = self.repo.find(code)
if url is None or url.is_expired(self.clock()):
return None
url.clicks += 1
return url.long_url
if __name__ == "__main__":
t = [datetime(2026, 11, 22, tzinfo=timezone.utc)]
svc = UrlShortenerService(InMemoryUrlRepository(), CounterCodeGenerator(), clock=lambda: t[0])
a = svc.shorten("https://algosimplified.dev/courses/system-design/")
b = svc.shorten("https://example.com/sale", ttl=timedelta(days=1))
c = svc.shorten("https://example.com/docs", alias="docs")
print(a, b, c)
print(svc.resolve(a), svc.resolve("nope"))
t[0] += timedelta(days=2)
print(svc.resolve(b), svc.resolve(c))
try:
svc.shorten("https://example.com/other", alias="docs")
except KeyError as e:
print("error:", e)
Output:
q0U q0V docs
https://algosimplified.dev/courses/system-design/ None
None https://example.com/docs
error: "code 'docs' already taken"
LLD decisions and why:
UrlRepositoryandCodeGeneratorare interfaces (dependency inversion), so the service can be tested with in-memory fakes and moved to a real database or a distributed ID source without changes.- The service owns the business rules (only http(s) URLs, expiry check, aliases), not the storage layer.
- The clock is injected, which makes expiry testable: the example moves time forward two days.
- Locks around the counter and the save make the in-process pieces thread-safe; across servers, uniqueness comes from the HLD’s ID ranges and the database’s unique key.
Notice how the two levels connect: the HLD said “codes come from leased ID ranges”; the LLD turns that into a CodeGenerator interface with one implementation per environment.
What interviewers look for in each round
System design (HLD) round, 45–60 minutes. You clarify requirements, estimate scale, draw the architecture, then go deep on one or two parts (data model, caching, sharding, failure handling). Interviewers look for structured thinking, sensible numbers and trade-offs you can defend. There’s usually no code.
Low level design / machine coding round, 45–90 minutes. You get a problem such as a parking lot, an elevator, an LRU cache or a movie ticket booking system. You define entities, draw a class diagram, and often write working code. Interviewers look for clean abstractions, SOLID principles, sensible design patterns, extensibility (“now add electric vehicle charging spots”) and thread safety where it matters.
Many Indian product companies run both rounds for backend roles, with LLD weighted more for 1–4 years of experience and HLD more for senior roles.
How to prepare for HLD and LLD
For HLD:
- Learn the building blocks: load balancing, caching, database replication and sharding, consistent hashing, queues, CAP.
- Practise a fixed framework: requirements → estimates → API → data model → architecture → deep dives → bottlenecks.
- Work through classic designs: URL shortener, rate limiter, chat, news feed, notification system.
For LLD:
- Be fluent in OOP and UML class diagrams.
- Learn SOLID and the dozen design patterns that actually come up (strategy, observer, state, factory, builder, singleton, decorator, adapter).
- Practise case studies end to end, in code, against a timer.
Free resources on this site, in order:
- System Design course (HLD) and the HLD sheet of practice questions.
- Low-Level Design course, starting with what low-level design is, and the LLD sheet.
- The concurrency sheet for the thread-safety questions LLD rounds love.
Frequently asked questions
What is the difference between HLD and LLD in simple words?
HLD is the architecture: which services, databases, caches and queues exist and how they connect. LLD is the inside of one component: its classes, interfaces, methods and data structures.
Which comes first, HLD or LLD?
HLD comes first. It fixes the components and their responsibilities, and LLD then designs each component. In practice you iterate: an LLD detail (say, an expensive query) can send you back to change the HLD.
Is LLD the same as machine coding?
Not quite. LLD is the design: entities, relationships, patterns. A machine coding round asks you to design and also implement it as working code in a fixed time. Most LLD interviews in India are run as machine coding rounds.
Do freshers need HLD?
Freshers are mostly tested on DSA and sometimes basic LLD. HLD rounds usually start at around 2–3 years of experience, though knowing the basics (caching, databases, load balancing) helps in any interview.
What documents are produced in HLD and LLD?
An HLD document covers the architecture diagram, components and their responsibilities, technology choices, data flow, capacity estimates and non-functional requirements. An LLD document covers class diagrams, interfaces and method signatures, database schemas, sequence diagrams for key flows, and error handling.