SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
  • OSI Model
  • IP Address
  • TCP vs UDP
  • HTTP / HTTPS
  • DNS
  • Proxy vs Reverse Proxy
  • Checksums
  • HTTP/1.1 vs HTTP/2 vs HTTP/3
  • Cookies and CORS
  • Subnets, CIDR and NAT
  • Firewalls and VPN
  • Ports and Sockets
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Foundations/Networking

HTTP / HTTPS

The language browsers and servers use to talk, and how HTTPS keeps it secret.

⏱ 14 min readBeginnerMust KnowInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

HTTP is the language a browser and a web server use to talk. The browser sends a request, the server sends back a response.

  • HTTPS is HTTP inside a secure tunnel (TLS). It gives privacy, no tampering and proof of who the server is.
  • HTTP is stateless: each request stands alone. Cookies and tokens help the server remember you.
  • Use HTTPS everywhere. Plain HTTP on the open internet is unsafe.

02Concept: What is it?

HTTP (HyperText Transfer Protocol) is a set of rules for asking for things on the web and answering. It works on a request and response pattern. The client always starts.

Anatomy of an HTTP request and response
Request
Method + pathGET /cart
HeadersHost, Cookie, Accept
Body (optional)JSON for POST/PUT
→↓then
Response
Status code200 OK
HeadersContent-Type, Cache-Control
BodyHTML, JSON, image…
🧠HTTP vs HTTPS in one line
HTTPS = HTTP + TLS. The messages are the same. They are just locked inside an encrypted tunnel. The default ports are 80 for HTTP and 443 for HTTPS.

03Real-Life Example

🍵Ordering at a restaurant
You (the client) tell the waiter what you want: “One masala dosa, please” (the request). The kitchen (the server) prepares it and the waiter brings it back with a note, “Here is your dosa” (the response with status 200). If the dish is not on the menu, the answer is “Sorry, not available” (404). If the kitchen is on fire, it is 500.
HTTPS is like talking to the waiter in a sealed, soundproof room. Nobody outside can hear or change your order. And you know it is really the restaurant, because it shows a government-approved licence (a certificate).
Restaurant
Web
Customer
Browser (client)
Kitchen
Web server
Order: “one dosa”
HTTP request (GET /dosa)
Dish on the plate
Response body
“Not on the menu”
404 Not Found
Table number / loyalty card
Cookie or token
Soundproof room + licence
TLS (HTTPS) + certificate
Without and with HTTPS on public Wi-Fi
HTTP
💻You
↓password=1234 (readable)
🕵️Spy on the Wi-Fireads it all
HTTPS
💻You
↓🔒 a9f3c0e1… (scrambled)
🕵️Spy on the Wi-Fisees noise
On plain HTTP, anyone on the same network can read or change the data. With HTTPS they see only scrambled text.

04Why Do We Need It?

🤝A common language
Every browser and server in the world understands HTTP. That is why the web works.
🔒Privacy
Passwords, cards and chats must not be readable by others.
✍️No tampering
Nobody on the way should be able to change a page or inject ads.
🪪Trust
You must be sure you are talking to your bank, not a fake site.
🔎Search and browser rules
Browsers mark HTTP sites “Not secure”. Many features need HTTPS.
🧩Simple and flexible
The same request pattern works for pages, APIs, images and videos.
HTTP makes the web possible. HTTPS makes it safe.

05Where Do We Use It?

🌍Websites
Every page you open in a browser.
🔌REST and JSON APIs
Mobile apps and services talk over HTTP.
💳Payments and logins
Always HTTPS.
📦Downloads and updates
Apps, packages and OS updates.
🎬Streaming
Video is sent as small HTTP chunks (HLS, DASH).
🔗Webhooks
One service calls another service’s URL when something happens.

Where it sits

7HTTP (and HTTPS)request / response
6TLSencryption (for HTTPS)
4TCP (or QUIC/UDP for HTTP/3)reliable transport
3IPaddresses

06Types / Parts / How It Works

HTTP methods: what do you want to do?

MethodMeaningSafe?Idempotent?
GETRead somethingYesYes
POSTCreate something or run an actionNoNo
PUTReplace something fullyNoYes
PATCHChange part of somethingNoNot guaranteed
DELETERemove somethingNoYes
HEADLike GET, but headers onlyYesYes
OPTIONSAsk what is allowed (used by browser CORS checks)YesYes
📝Idempotent?
Doing it once or ten times gives the same result. Deleting the same item twice leaves it deleted. Paying twice with POST charges twice. That is why payment APIs use an idempotency key.

Status codes: the five families

ℹ️1xx Info
“Keep going.” Rarely seen.
✅2xx Success
200 OK, 201 Created, 204 No Content.
↪️3xx Redirect
301 Moved, 302 Found, 304 Not Modified.
🙋4xx Client error
400, 401, 403, 404, 429. You did something wrong.
🔧5xx Server error
500, 502, 503, 504. The server has a problem.

How HTTPS builds a secure tunnel

HTTPS uses TLS (the newer name for SSL). TLS gives three things:

🔒Encryption
Nobody on the way can read the data.
🧾Integrity
Any change on the way is detected.
🪪Authentication
A certificate proves the server is who it says.
Who do we trust? The certificate chain
🏛️Root CAbuilt into your browser or OS
↓signs
🏢Intermediate CA
↓signs
📜shop.com certificateproves the site’s identity
Your device already trusts a few root authorities. They vouch for others down the chain.

HTTP versions

  1. 1
    HTTP/1.1
    Text based. One request at a time per connection, so browsers open many connections. Still very common.
  2. 2
    HTTP/2
    Many requests share one TCP connection (multiplexing). Headers are compressed. Fixes much of the waiting.
  3. 3
    HTTP/3
    Runs on QUIC over UDP. Faster start, and one lost packet no longer blocks everything.
VisualizerOne request, one responseFollow a page load from typing the address to the page appearing.
💻Browsershop.com/cart
↔not connected yet
🖥️shop.comweb server
Step 1 of 6
You type https://shop.com/cart
The browser reads the address. “shop.com” is the server name and “/cart” is the page you want.
VisualizerThe TLS handshake (how HTTPS starts)Step through how the browser and server agree on a secret key.
💻Browser
→↓ClientHello
🖥️Server
Step 1 of 5
1. ClientHello: “Hi, let’s talk securely”
The browser lists the TLS versions and ciphers (lock types) it knows, and sends a public key share for building a secret.

Simplified. In real TLS 1.3 the handshake takes one round trip and most of it is already encrypted.

VisualizerStatus code explorerClick a code to see what it means and whose problem it is.
Pick a status code
💻Client
←404 Not Found
🖥️Server
Code
404
Not Found
Family
4xx
Client error
Whose problem?
The client
Nothing exists at this address.
Like this: The dish is not on the menu.

07How to Use It / Steps / Implementation

What happens when you open https://shop.com

  1. 1
    DNS lookup
    Turn “shop.com” into an IP address.
  2. 2
    TCP handshake
    SYN, SYN-ACK, ACK on port 443.
  3. 3
    TLS handshake
    Check the certificate and agree on a secret key.
  4. 4
    HTTP request
    GET / with headers such as Host and Cookie.
  5. 5
    Server work
    Check login, read the database, build the page.
  6. 6
    HTTP response
    200 OK plus HTML.
  7. 7
    Render
    The browser asks for images, CSS and JavaScript, then draws the page.

A real request and response

Request
GET /api/products/42 HTTP/1.1
Host: shop.com
Accept: application/json
Authorization: Bearer <token>
Response
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: max-age=60

{ "id": 42, "name": "Tea cup", "price": 120 }

Useful headers

HeaderWhat it does
HostWhich website you want (many sites share one IP)
Content-TypeWhat kind of data is in the body (for example application/json)
AuthorizationProves who you are (token or key)
Cookie / Set-CookieLets the server remember you across requests
Cache-ControlHow long a copy may be reused
LocationWhere to go next on a redirect
Strict-Transport-Security (HSTS)Tells the browser to always use HTTPS for this site
💡To turn on HTTPS for your site
Get a certificate (free ones come from Let’s Encrypt), install it on the server or load balancer, redirect HTTP to HTTPS, and turn on HSTS. Most big load balancers and CDNs can do this for you.

08Key Terms to Know

TermMeaning in easy words
Client / ServerThe one that asks, and the one that answers
URLThe full address of a thing, for example https://shop.com/cart?id=5
Request / ResponseOne message to ask, one message to answer
HeaderExtra information sent with a message
BodyThe main content (page, JSON, image)
Status codeA 3-digit number telling the result
StatelessThe server keeps no memory between requests. Cookies or tokens carry the identity
CookieA small piece of data the browser stores and sends back with each request
TLSThe protocol that encrypts HTTPS traffic (the new name for SSL)
CertificateA signed ID card for a website
CA (Certificate Authority)A trusted company that signs certificates
TLS terminationEnding the HTTPS tunnel at a load balancer or proxy
Keep-aliveReusing one connection for many requests
HSTSA header that forces browsers to use HTTPS

09Pros, Cons and Trade-offs

HTTP (plain)
  • Simple, no certificate needed
  • Slightly less CPU work
  • ❌ Anyone on the path can read or change it
  • ❌ Browsers show “Not secure”
  • ❌ Many new web features are blocked
HTTPS
  • Private, untampered and verified
  • Trusted by browsers and search engines
  • Allows HTTP/2, HTTP/3 and modern features
  • Costs a little CPU and an extra handshake
  • Needs certificates to be renewed
ChoiceWe gainWe lose
HTTPS everywhereSecurity and trustSmall extra time and CPU (usually tiny today)
Keep-alive connectionsNo repeated handshakesServer holds idle connections
Stateless HTTPEasy to scale: any server can answerNeed cookies or tokens to know the user
Caching responsesFast pages, less loadUsers may see old data
HTTP/3Faster on bad networksSome networks block UDP

10Common Problems and Mistakes

Common mistakes

  1. Using GET to change data. Crawlers and prefetchers may call it by accident. Use POST, PUT or DELETE.
  2. Wrong status codes. Returning 200 with an error message inside makes clients and monitoring blind. Use 4xx and 5xx honestly.
  3. Putting secrets in the URL. URLs end up in logs and browser history. Use headers or the body.
  4. Letting a certificate expire. The site then shows a scary warning. Automate renewals and watch expiry dates.
  5. Mixed content. An HTTPS page that loads an HTTP script or image gets blocked or marked unsafe.
  6. Mixing up 401 and 403. 401: “who are you?”. 403: “I know you, but no.”
  7. Believing HTTPS makes a site “safe”. It protects data in transit. It does not stop bugs, bad passwords or phishing sites that also use HTTPS.

Known problems

🕵️Man-in-the-middle
An attacker sits between you and the server. Valid certificates and HSTS stop this.
🍪Stolen cookies
Use Secure, HttpOnly and SameSite flags on cookies.
🐢Too many requests
A page with 100 small files is slow on HTTP/1.1. Use HTTP/2 or bundle files.
🔁Redirect loops
A bad HTTP to HTTPS rule can bounce forever.

11Real-World Examples

🏦Online banking
Always HTTPS, with strict rules and short-lived sessions.
🛒Shopping sites
Product pages are cached by CDNs. Checkout is always HTTPS.
📱Mobile apps
Apps call JSON APIs over HTTPS.
🎬Video apps
Videos are cut into small pieces and downloaded over HTTP.
🌍CDNs and load balancers
End the HTTPS connection near the user, then talk to your servers.
🔐Let’s Encrypt
A free certificate service that made HTTPS common on small sites.
Where HTTPS usually ends
🧑User
→↓HTTPS
⚖️Load balancer / CDNTLS ends here
→↓HTTP or HTTPS
🖥️
🖥️
Public internet (encrypted) Edge Private servers
Many systems end TLS at the edge (CDN or load balancer) and use a private network behind it. Very strict systems encrypt that inner part too.

12Related Topics to Read Next

TCP vs UDP→

HTTP/1.1 and HTTP/2 use TCP. HTTP/3 uses UDP.

DNS→

The first step before any request: find the IP.

OSI Model→

HTTP is Layer 7. TLS and TCP sit below it.

Proxy vs Reverse Proxy→

Reverse proxies often end HTTPS for your servers.

What are Load Balancers?→

They spread HTTP requests over many servers.

Checksums→

TLS uses integrity checks to detect changes.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔HTTP: request and response. Stateless. Ports 80 / 443.
  • ✔HTTPS = HTTP + TLS: encryption, integrity, authentication.
  • ✔Methods: GET read, POST create, PUT replace, PATCH change part, DELETE remove.
  • ✔Codes: 2xx ok, 3xx redirect, 4xx client error, 5xx server error.
  • ✔Page load: DNS, TCP, TLS, HTTP request, response, render.
  • ✔Versions: 1.1 text, 2 multiplexing, 3 over QUIC (UDP).
  • ✔Cookies and tokens give a stateless protocol a memory.
  • ✔One line: “HTTP is how the web talks; HTTPS makes that talk private and trusted.”
← Previous
TCP vs UDP
Next →
DNS