Skip to content
learn
  1. Learn
  2. High Level System Design
  3. Computer and Network Foundations

System Design HLD-01.06

TLS and HTTPS

What TLS protects, how certificates prove identity, the one round trip TLS 1.3 handshake, and where large systems terminate TLS and use mutual TLS.

Beginner 10 min Last reviewed

The big idea

Data crossing the internet passes through many machines you do not control: the coffee shop's Wi-Fi router, your ISP, transit networks, sometimes a hostile one. Without protection, any of them could read your password or quietly change the page you receive. TLSTransport Layer Security: a protocol that encrypts a connection and proves the server's identity using certificates. HTTPS is HTTP over TLS. fixes both problems. HTTPS is simply HTTP sent inside a TLS connection.

TLS gives three guarantees. Confidentiality: nobody in the middle can read the data. Integrity: nobody can change it without detection. Authentication: you are really talking to shop.example.com, not an impostor. That last one is the subtle part, and it is what certificates are for.

Picture sending a locked box. Encryption is the lock. But if a stranger hands you a box claiming to be from your bank, you need a way to check. The certificate is an ID card for the server, signed by an authority your device already trusts.

How it works

Step 1: Certificates and authorities

A server has a key pair: a private key it keeps secret and a public key it shares. Its certificateA signed document binding a domain name to a public key, issued by a certificate authority and valid for a limited time. says "the public key for shop.example.com is this one", and is signed by a certificate authorityAn organization trusted by browsers and operating systems to verify domain ownership and sign certificates. (CA). Your browser and operating system ship with a list of trusted root CAs. When the server presents its certificate, the browser checks the signature chain back to a trusted root, checks the name matches, and checks it has not expired.

Before signing, the CA checks that the requester controls the domain, often automatically, for example by asking them to publish a token in DNS. Services like Let's Encrypt issue free certificates valid for short periods and renew them automatically.

Step 2: The TLS 1.3 handshake

After the TCP connection is open, client and server agree on keys in a single round trip:

TLS 1.3 handshake followed by an encrypted request A sequence diagram: the browser sends ClientHello with a key share. The server replies with ServerHello and its key share, its certificate, a proof that it holds the private key, and Finished. The browser verifies the certificate, sends Finished and the encrypted HTTP request, and receives an encrypted response. Browser Server has certificate + private key ClientHello: ciphers + key share start ServerHello: key share certificate + proof it owns the key Finished (encrypted) 1 round trip verify cert chain, name, expiry Finished + GET /cart (encrypted) 200 OK (encrypted) Figure 1. TLS 1.3 needs one round trip. Both sides combine their key shares into the same secret without ever sending it, the server proves it owns the certificate, and everything after the hello messages is encrypted.

The key shares use a method called Diffie-Hellman key exchangeA technique letting two parties derive the same secret by exchanging public values; someone watching the exchange cannot compute the secret.: each side sends a public value, and each combines the other's value with its own secret to get the same session key, which never crosses the wire. Fresh keys per connection mean that even if the server's private key leaks later, recorded old traffic stays unreadable, a property called forward secrecy. TLS 1.2, still around, needed two round trips; TLS 1.3 also allows zero round trip resumption for returning clients.

Step 3: Where TLS ends in a real system

Large systems rarely run TLS on every application server for traffic from the internet:

TLS terminated at the edge, with mutual TLS between internal services Users connect with HTTPS to a load balancer, which terminates TLS. Inside the network, the load balancer and services talk to each other over mutual TLS, where both sides present certificates. Inside the data center HTTPS mTLS mTLS mTLS Users Load balancer terminates TLS Orders service Payments Users service Figure 2. The edge (load balancer or CDN) terminates public TLS, holding the certificates in one place. Inside, services use mutual TLS so each side proves its identity, not just the server.

TLS terminationDecrypting TLS at a load balancer or edge proxy and forwarding the request to backends, so certificates and crypto work live in one place. at the load balancer or CDN means certificates are managed in one place, the edge can inspect requests to route them, and backends save CPU. Traffic behind the edge should still be encrypted, ideally with mutual TLSMutual TLS: both client and server present certificates, so each proves its identity to the other. (mTLS), where the client also presents a certificate. Then a compromised machine inside the network cannot simply impersonate the payments service. Service meshes automate this, which you will meet in Service mesh .

Going deeper

What TLS does not hide

TLS encrypts the content, but observers still see which IP addresses you connect to, roughly how much data flows and when. The site name is also often visible during the handshake, in a field called SNI, unless the newer Encrypted Client Hello extension is used. TLS protects data in transit only; data at rest needs its own encryption, covered in Encryption, keys and secrets .

Certificate expiry is an outage waiting to happen

Every certificate has an end date, now usually measured in months. An expired certificate makes browsers block the site with a full-page warning, and makes internal clients refuse to connect. Automate renewal and alert on expiry well in advance.

Trade-offs

OptionWins whenLoses when
Terminate TLS at the edge Central certificate management, request routing, CPU offload from backends Traffic behind the edge is plain text unless re-encrypted
Mutual TLS between services Zero-trust networks: every service proves its identity, traffic encrypted everywhere Teams without automation: issuing and rotating many certificates by hand is painful
End-to-end TLS to every backend Strict compliance where no intermediary may decrypt Edge features like caching and routing on paths, which need to see the request

Common mistakes

  • Renewing certificates by hand. Someone will forget, and the whole site will go down at once.
  • Turning off certificate verification in client code to "fix" an error. That removes the authentication guarantee completely.
  • Leaving internal traffic unencrypted because "it is our network". Attackers who get one foothold then read everything.
  • Assuming HTTPS means a site is trustworthy. It proves who you are talking to, not that they are honest.

Check yourself

  1. What does a certificate prove?

    Show answer

    B. The public key belongs to the named domain, as vouched for by a CA A CA-signed certificate binds a domain name to a public key. It says nothing about the site's honesty.

  2. How many round trips does a fresh TLS 1.3 handshake add, after TCP?

    Show answer

    B. One TLS 1.3 completes in one round trip. TLS 1.2 needed two.

  3. Why do large systems often terminate TLS at the load balancer?

    Show answer

    B. To manage certificates in one place, route on request content and save backend CPU Terminating at the edge centralizes certificates and lets the edge inspect requests; internal hops should still be encrypted.

  4. What does mutual TLS add over normal TLS?

    Show answer

    B. The client also proves its identity with a certificate In mTLS both sides present certificates, so services can verify who is calling them.

Recap

  • TLS gives confidentiality, integrity and authentication; HTTPS is HTTP inside TLS.
  • A certificate binds a domain to a public key and is signed by a CA your device trusts.
  • TLS 1.3 agrees fresh session keys in one round trip using Diffie-Hellman.
  • Large systems terminate public TLS at the edge and use mutual TLS between services.
  • Automate certificate renewal: an expired certificate is a full outage.

Get new lessons by email

Get new posts on backend and AI internals. No spam, unsubscribe anytime.

Your email is only used to send new posts. Privacy