SYSTEM DESIGN · CONCEPTS · HOW THE WEB WORKS · EPISODE 3

HTTP vs HTTPS: What the S Really Does

What HTTP looks like on the wire, why plain HTTP is readable by anyone on the path, and how HTTPS uses TLS, certificates and keys to keep data private and untampered.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
1 / 21

Press play to hear the narration, or step through at your own pace. Every picture here is the same one used in the YouTube video.

Notes

What is HTTP?

First, HTTP. The Hypertext Transfer Protocol is the language browsers and servers use. It's simple: the client sends a request, and the server sends back a response.

A request has a method, like GET to read or POST to send data, a path, and headers: extra details like the host, the browser, and cookies.

The response has a status code, headers, and a body. 200 means OK, 3xx means it moved, 4xx means you made a mistake, like 404 not found, and 5xx means the server failed.

One key property: HTTP is stateless. Each request stands alone, and the server doesn't remember the last one. That's why cookies and tokens exist: they carry who you are, on every request.

Request
GET /balance HTTP/1.1
Host: bank.com
Cookie: session=8f3a…
Accept: text/html
Response
HTTP/1.1 200 OK
Content-Type: text/html
Set-Cookie: …

<html>Balance: 42,000</html>
HTTP is stateless
  • each request stands alone
  • the server doesn’t remember you
  • so: cookies and tokens
  • carry who you are

The problem

Here's the problem. Plain HTTP is plain text. Your data passes through routers, the café Wi-Fi, your internet provider. Anyone along that path can read it: passwords, cookies, everything.

There are three risks. Eavesdropping: someone reads it. Tampering: someone changes it, for example injecting ads or malware into a page. And impersonation: a fake server pretends to be your bank.

Three risks
  • 1 eavesdropping: they read it
  • 2 tampering: they change it
  • (inject ads, malware)
  • 3 impersonation: a fake site
  • pretends to be bank.com

The fix

HTTPS fixes all three. It's the same HTTP, but wrapped inside TLS, Transport Layer Security. TLS gives encryption, so nobody can read it. Integrity, so nobody can change it unnoticed. And authentication, so you know it's really your bank.

HTTPS = HTTP + TLS
  • encryption → nobody can read it
  • integrity → nobody can change it
  • authentication → it really is bank.com
  • port 443 (HTTP uses 80)

Keys, briefly

To understand TLS, you need two ideas. Symmetric encryption uses one shared key: it's fast, but how do two strangers agree on a key without anyone overhearing? Asymmetric encryption uses a key pair: a public key that anyone can use, and a private key only the owner has.

Two kinds of encryption
  • symmetric: one shared key
  • fast, but how do we share it?
  • asymmetric: public + private key
  • anyone can lock with the public key,
  • only the owner can unlock

TLS handshake

TLS uses both. Here's the handshake, in TLS 1.3. Step one: the browser says hello. It lists the versions and ciphers it supports, and sends its half of a key exchange.

Step two: the server replies with its choices, its half of the key exchange, and its certificate: a document that says, this public key belongs to bank.com.

Step three: the browser checks the certificate. Is it signed by a certificate authority the browser already trusts? Does the name match bank.com? Has it expired? If anything is wrong, you see a big warning page.

Trust flows down a chain. Your browser and operating system ship with a list of trusted root authorities. A root signs an intermediate, and the intermediate signs the site's certificate. Services like Let's Encrypt issue these for free.

Step four: from the key exchange, both sides compute the same secret session key, without ever sending it across the network. Someone watching sees the exchange, but can't work out the key.

Chain of trust
  • browser trusts → Root CA
  • Root CA signs → Intermediate CA
  • Intermediate signs → bank.com
  • Let’s Encrypt issues free certificates

After the handshake

From now on, every request and response is encrypted with that fast symmetric key. Someone on the café Wi-Fi sees only noise. TLS 1.3 does all of this in a single round trip.

One subtle point. HTTPS hides the path, headers, cookies and body. But the network can still see which IP you're talking to, usually the domain name, and roughly how much data moves.

What HTTPS hides, and doesn’t
  • hidden: path, headers, cookies, body
  • visible: the IP address,
  • the domain name (in the hello),
  • and roughly how much data

Performance

Is HTTPS slow? Not any more. The handshake costs about one round trip, or none when a session is resumed, and the encryption cost on modern chips is tiny. Newer HTTP versions require it, and browsers mark plain HTTP as not secure.

Cost of HTTPS today
  • handshake: about 1 round trip
  • (0 with session resumption)
  • encryption: tiny CPU cost
  • HTTP/2 and HTTP/3 need HTTPS
  • browsers mark HTTP “Not secure”

In system design

In system design, you'll hear TLS termination. Usually the load balancer or reverse proxy holds the certificate and decrypts traffic, then talks to the servers behind it, either over plain HTTP inside a private network, or re-encrypted for extra security.

In system design
  • TLS termination at the
  • load balancer or reverse proxy
  • inside the data centre:
  • plain HTTP or re-encrypted (mTLS)

Interview questions

What is the difference between HTTP and HTTPS?

HTTPS is HTTP sent inside a TLS connection (default port 443 instead of 80). TLS adds encryption (confidentiality), integrity checks, and server authentication through certificates.

Walk through the TLS 1.3 handshake.

Client hello (supported versions, cipher suites, key share) → server hello (choices, its key share) plus its certificate and a signature proving it owns the private key → client verifies the certificate chain and hostname → both derive the same session keys from the key exchange → encrypted application data. It takes one round trip (zero with resumption).

Why does TLS use both asymmetric and symmetric cryptography?

Asymmetric cryptography (key exchange and signatures) solves agreeing on a secret and proving identity with strangers, but is slow. Symmetric encryption is fast, so it is used for the bulk data once a shared session key exists.

What does a certificate authority do?

A CA verifies that an applicant controls a domain and signs a certificate binding the domain name to a public key. Browsers trust a set of root CAs; trust flows through intermediate CAs to the site certificate.

What is TLS termination?

Decrypting TLS at a load balancer or reverse proxy, which holds the certificate, so backend servers receive plain HTTP (or a new TLS connection). It centralises certificates and offloads crypto work.

Is HTTP stateless? How do sites remember you?

Yes, each request is independent. Sessions are kept with cookies or tokens (for example a session id or a signed token) sent on every request.