SyntaxPilot
Courses/System Design/Lesson 1

System Design · Lesson 1 of 40 · 8 min

What happens when you open a website

scheduled

These are the notes for System Design episode 1. You will learn what system design is, the difference between HLD and LLD, how a website works (explained as a restaurant), the four steps of a request (DNS, TCP + TLS, HTTP request, response), why one server breaks at scale, the four goals of every good system, and three beginner myths. The Python simulations from the video are included with their real output; run them yourself in the SyntaxPilot compiler.

The problem: it works on my laptop

You build your first website. You open localhost on your laptop and the page appears. Brilliant!

You send the link to a friend. His browser says:

This site can't be reached
localhost refused to connect.
ERR_CONNECTION_REFUSED

Why? localhost means this very computer. On your friend's laptop, localhost is his laptop, where nothing is running. You can check what the name points to with Python:

import socket
print(socket.gethostbyname("localhost"))

Output:

127.0.0.1

127.0.0.1 is the "loopback" address: every computer uses it to talk to itself.

Step What happens Result
It works on my laptop you open localhost:5173 your page
Send the link to a friend his localhost is his own laptop ERR_CONNECTION_REFUSED
Put it on an always-on computer with a name a server + a public IP address + DNS (syntaxpilot.in) anyone can reach it
Then 10 lakh people come one server can't keep up slow, then down

The last row is the real question: how do you connect the parts so the system doesn't break when lots of people use it? That question is called system design.

What is system design?

  • System design is planning how the different parts of a piece of software work together.
  • The parts: servers, databases, caches, queues and the network.
  • The goal: even with millions of users, the system stays fast, reliable and affordable.

HLD vs LLD

HLD (high-level design) LLD (low-level design)
Analogy the city map: which road goes where the plan of one house: which room goes where, even each switch
Shows boxes and arrows: services, databases, how they connect fields, classes, functions, error handling
SyntaxPilot compiler example browser → API server → code runner that executes the code a run request has fields like language, code and input; how errors come back

In interviews, "design YouTube" is usually an HLD question, while "design the classes for a parking lot" is an LLD question.

A website works like a restaurant

At a restaurant On the web Job
You, the customer (you want food) Browser / app you want a page
Finding the address (Google Maps) DNS turns a name into an IP address
The waiter (takes your order) Web server / API takes the request
The storeroom (all the ingredients) Database stores all the data

The journey of one request

When you type syntaxpilot.in and press Enter:

Step Name What happens Restaurant version
1 DNS lookup the browser asks: what's the IP address for syntaxpilot.in? look up the address
2 Connect: TCP + TLS the browser opens a TCP connection to the server and, for HTTPS, does a TLS handshake knock on the door and agree a secret code so nobody in between can listen
3 HTTP request the browser sends a request such as GET /course ("give me the course page") place the order
4 Response the server reads data from the database, builds the page and sends it back with 200 OK; the browser shows it the food arrives

In one line:

Browser → DNS (name → IP) → Server (logic) → Database (data) → Page on screen

This four-step structure is the answer to the interview favourite "What happens when you type a URL and press Enter?"

A URL itself has parts that each step uses. Python can split one:

from urllib.parse import urlsplit
u = urlsplit("https://syntaxpilot.in/course?lang=java")
print("scheme:", u.scheme)
print("host:  ", u.hostname)
print("path:  ", u.path)
print("query: ", u.query)

Output:

scheme: https
host:   syntaxpilot.in
path:   /course
query:  lang=java

The host goes to DNS (step 1), the scheme https means TLS is needed (step 2), and the path and query go into the HTTP request (step 3).

Going a little further (good to mention in interviews): before asking a DNS server, the browser checks its own DNS cache and the operating system's cache. After the response arrives, the browser parses the HTML and makes more requests for CSS, JavaScript and images.

Simulate the request in Python

One dictionary acts as DNS, another as the database. Reading from a database takes time, so the server waits 50 milliseconds.

import time

dns = {"syntaxpilot.in": "203.0.113.10"}   # example IP
database = {"/course": "Java Full Course"}

def server(path):
    time.sleep(0.05)                # reading from the database
    return "200 OK: " + database[path]

start = time.time()
ip = dns["syntaxpilot.in"]
print("1. DNS lookup  ->", ip)
print("2. Request     -> GET /course")
print("3. Response    ->", server("/course"))
print("Total time:", round((time.time() - start) * 1000), "ms")

Output:

1. DNS lookup  -> 203.0.113.10
2. Request     -> GET /course
3. Response    -> 200 OK: Java Full Course
Total time: 50 ms

DNS gave the IP, the request went out, and the response came back with 200 OK in about 50 ms. (203.0.113.10 is from a range reserved for documentation examples, not a real server.) On the real internet every step costs a little time, and a big part of system design is cutting that time down.

Why scale changes everything

Now send 20 users to the same server, 50 ms per request, the obvious way: everyone stands in one line.

import time

def server(path):
    time.sleep(0.05)                # 50 ms per request
    return "200 OK"

start = time.time()
for user in range(1, 21):           # 20 users, one server
    server("/course")
    if user in (1, 10, 20):
        waited = round((time.time() - start) * 1000)
        print("User", user, "got the page after", waited, "ms")

print("10 lakh users would need:", round(1_000_000 * 0.05 / 3600, 1), "hours")

Output (the ms values vary by a few ms per run):

User 1 got the page after 50 ms
User 10 got the page after 502 ms
User 20 got the page after 1004 ms
10 lakh users would need: 13.9 hours

The further back in the line, the longer the wait: user 10 waits about half a second, user 20 about a full second. Ten lakh users would need about 14 hours, so the last user sees the page tomorrow. The cause: one server doing one thing at a time. Finding the fix (more servers, load balancers, caches, doing work in parallel) is what this course is about.

The arithmetic behind that last line:

Quantity Value
Time per request 0.05 s (50 ms)
Users 10,00,000 (1 million)
Total, one at a time 1,000,000 × 0.05 = 50,000 s
In hours 50,000 / 3,600 ≈ 13.9 hours

1 customer is easy, 5.9 crore is not

Restaurant Website What you need
One customer: one cook is enough a small site one server works fine
A wedding for 2,000 guests: many cooks, counters, a plan a big site many servers, load balancers, caches
World Cup final 2023 (India vs Australia) Disney+ Hotstar 5.9 crore (59 million) people watching at the same time

Handling scale like that is what system design is about.

The 4 goals of a good system

Goal Meaning
Scalability more users? add capacity, don't rewrite the whole system
Availability it keeps working, even when parts fail
Low latency every request gets a fast answer
Cost all of this without wasting money

Every concept in this course connects back to these four goals.

Key trade-offs

The goals pull against each other, and a good design picks a balance for the product:

  • Availability vs cost: running two copies of everything survives failures, but doubles the bill.
  • Latency vs cost: a cache or servers close to users make pages faster, but cost money and add complexity.
  • Simplicity vs scale: one server is simple and cheap until it isn't; a distributed system scales but is harder to build and debug.

3 beginner myths

Myth Reality
"Only big companies need system design" every app starts small; if the design is thought through, growth doesn't break it
"More servers fix everything" if the database itself is slow, a hundred servers just stand in line outside that same database
"There is one right answer" every choice is a trade-off between speed, cost and simplicity; in interviews your reasoning matters more than the answer

Common mistakes

Mistake What you see Why / fix
Sharing a localhost link ERR_CONNECTION_REFUSED (Chrome: "localhost refused to connect") localhost is always the viewer's own computer (127.0.0.1). Deploy to a server with a public address and a domain name
Calling a port where nothing is listening curl: (7) Failed to connect to localhost port 5999 after 0 ms: Couldn't connect to server no server is running on that port; start it, or check the port number
Answering "type a URL" with only "the server sends the page" an incomplete interview answer use the four steps: DNS, TCP + TLS, HTTP request, response
Thinking more servers always help the system is still slow find the real bottleneck first (often the database)
Jumping to class diagrams in an HLD question the interviewer wanted boxes and arrows HLD first (city map), LLD only when asked (house plan)

Practice

  1. Explain "what happens when you type a URL" to a friend in four steps.
  2. Run the request simulation and change the delay from 0.05 to 0.2. What is the total time now?
  3. In the scale demo, how many hours would 10 lakh users need if each request took 10 ms instead of 50 ms?
  4. Open your browser's DevTools Network tab, reload any website and find one request. Note its method, status code and time.
  5. Which of the four goals matters most for UPI payments, and why?
Solutions and hints

1. (1) DNS turns the name into an IP address. (2) The browser opens a TCP connection and does a TLS handshake for HTTPS. (3) It sends an HTTP request like GET /course. (4) The server reads the database, builds the page and replies with 200 OK, and the browser shows it.

2. Change time.sleep(0.05) to time.sleep(0.2). Output:

1. DNS lookup  -> 203.0.113.10
2. Request     -> GET /course
3. Response    -> 200 OK: Java Full Course
Total time: 200 ms

3. 1_000_000 * 0.01 / 3600 = about 2.8 hours. Faster requests help, but a single line still doesn't scale: you need more servers working in parallel.

4. In Chrome or Firefox press F12, open Network, reload. The first row is usually the page itself: method GET, status 200. The Time column shows how long it took.

5. A good answer: availability (a payment system that is down stops shops and people everywhere), closely followed by correctness. Low latency matters too, because nobody wants to wait at the counter. There is no single right answer; the reasoning is what counts.

Quick quiz

You type syntaxpilot.in. Which part turns that name into an IP address?

  • A. The database
  • B. DNS
  • C. The browser cache
  • D. TLS
Answer

B: DNS. DNS (the Domain Name System) is the internet's address book: it turns a name into an IP address. (The browser cache can remember a previous DNS answer, but DNS is what produces it.)

Interview questions

  • What happens when you type a URL into the browser and press Enter?
  • What is the difference between HLD and LLD? Give an example of each.
  • What does DNS do? What is localhost / 127.0.0.1?
  • What is the role of TLS in HTTPS?
  • Why does a single server fail at scale? What are the first things you would add?
  • Name the four goals of a good system. Which one matters most for a payment system, a video streaming site and a chat app?
  • "Just add more servers": when does that not help?

Summary

  • System design is planning how servers, databases, caches, queues and the network work together so the system stays fast, reliable and affordable at scale.
  • HLD is the city map (boxes and arrows); LLD is the house plan (fields, classes, errors).
  • A website is a restaurant: browser (customer), DNS (address), server (waiter), database (storeroom).
  • One request: DNS → TCP + TLS → HTTP request → response (200 OK).
  • One server handling one request at a time makes users wait in line: 10 lakh users × 50 ms ≈ 13.9 hours. Scale like 5.9 crore concurrent Hotstar viewers is why we design.
  • The four goals: scalability, availability, low latency, cost, and every choice is a trade-off.

Next episode: the client–server model and HTTP in detail: methods, status codes, headers, and how HTTPS keeps you safe.