Home › High-Level Design › HTTP, HTTPS and TLS
H

HTTP, HTTPS and TLS

Almost every service you will ever design talks HTTP, and the way it talks shapes your latency budget, your security model, and your infra bill. I have sat on both sides of the table for this topic, and the candidates who stand out are not the ones who recite RFC numbers. They are the ones who can tell me why a cold connection to a new region burns 150ms before a single byte of data moves, then show me exactly where that 150ms goes.

High-Level DesignIntermediate11 min read

If you remember five things

The whole topic in one glance. Everything below defends these five.

  1. HTTPS is just HTTP in a TLS tunnel. Same methods, same status codes, same headers. The only new thing is a handshake up front that agrees on encryption keys.
  2. TLS buys three things. Confidentiality (nobody reads it), integrity (nobody edits it undetected), and authentication (you are talking to who you think). Name them separately, because interviewers do.
  3. The cost is round trips, not bytes. AES-NI makes per-byte crypto nearly free. The real tax is handshake round trips on new connections, which is why connection reuse is the biggest latency win you have.
  4. Versions are a head-of-line story. HTTP/1.1 blocks at the app layer, HTTP/2 fixes that but still blocks at TCP, HTTP/3 over QUIC removes both.
  5. Do the handshake arithmetic out loud. Count the round trips, multiply by RTT, then move TLS to a near edge and watch the number collapse. That subtraction is the whole interview.

1The core idea#

HTTP is a request/response protocol, and the model is small on purpose.

  • The client sends: a method, a path, some headers, maybe a body.
  • The server sends back: a status code, some headers, maybe a body.
  • It is stateless by design. The server does not remember you between requests unless you hand it something to remember you by, like a cookie or a bearer token.

The mental model I give juniors.

  • HTTP is the letter: it defines what the bytes mean.
  • TCP is the postal service that delivers the bytes.
  • TLS is the sealed, tamper-proof envelope you put the letter in.
  • HTTP does not care how the bytes get there.

HTTPS is not a separate protocol. It is HTTP running inside a TLS tunnel.

  • Same methods, same status codes, same headers.
  • Before any HTTP flows, the client and server do a TLS handshake to agree on encryption keys.
  • After that, every HTTP byte is encrypted on the wire.
  • A network sniffer sees ciphertext and the destination IP, not your passwords or your API payloads.

TLS gives you three things, and naming them separately matters:

  • Confidentiality: nobody on the path can read your traffic.
  • Integrity: nobody can silently modify it. Flip a bit and the receiver detects it and tears down the connection.
  • Authentication: you are actually talking to the server you think you are, proven by a certificate signed by a trusted Certificate Authority.
The one asymmetry people miss

Plain TLS authenticates the server to the client, not the other way around. Mutual auth (mTLS), where both sides present certificates, is a separate choice you make, usually for service-to-service traffic inside a trust boundary.

2How it works#

Walk through what actually happens when a browser loads https://api.example.com. The order is the whole point.

  • DNS resolves the hostname to an IP.
  • TCP does its three-way handshake (SYN, SYN-ACK, ACK) to open a connection: one round trip.
  • TLS negotiates keys: one more round trip on TLS 1.3, two on the older TLS 1.2.
  • Only after all of that does the first HTTP request go out.
sequenceDiagram participant C as Client participant S as Server C->>S: TCP SYN S->>C: TCP SYN ACK C->>S: TCP ACK C->>S: TLS ClientHello S->>C: ServerHello and Certificate C->>S: Finished with keys S->>C: Finished C->>S: HTTP GET products S->>C: HTTP 200 with body
Notice how much happens before the first HTTP byte. TCP (1 RTT) and TLS (1 to 2 RTT) both complete before the GET even leaves. That stack of round trips is the latency you are paying for, and every optimization later is about shrinking it.

The TLS handshake is where the clever part lives.

  • The client sends a ClientHello: the cipher suites and TLS versions it supports, plus a random number.
  • The server picks a cipher suite, sends its certificate chain, and sends its own random.
  • Both sides run an ephemeral Diffie-Hellman key exchange to derive a shared secret that was never sent over the wire.
  • Record all the traffic, later steal the server's private key, and you still cannot decrypt old sessions. That property is forward secrecy, and it is the default in TLS 1.3.

The certificate is the trust anchor.

  • The server's cert is signed by an intermediate CA, which is signed by a root CA your OS or browser already trusts.
  • The client walks that chain up to a root it recognizes.
  • It checks the domain name matches, checks the expiry, checks revocation.
  • Any link fails and you get that scary browser warning.

Now the versions, because this is where the real system design decisions live:

  • HTTP/1.1: one request at a time per connection. Browsers worked around it by opening six connections per host. Request two waits for request one to finish: head-of-line blocking at the application layer.
  • HTTP/2: multiplexing. Many concurrent streams over a single TCP connection, plus header compression (HPACK). Solves application-layer head-of-line blocking. But it still rides one TCP connection, so a single lost packet stalls all streams at the TCP layer. That is TCP-level head-of-line blocking.
  • HTTP/3: runs over QUIC, which runs over UDP, not TCP. QUIC builds in its own streams, so a lost packet only stalls the one stream that needed it. QUIC also folds the transport and TLS handshakes together, so a fresh connection is one round trip instead of two, and reconnections can be zero round trips.
From the interviewer's chair

When I say "HTTP/2 fixes head-of-line blocking," I am baiting you. The sharp answer is "at the application layer, yes, but it reintroduces it at TCP, and only HTTP/3 over QUIC removes both." Candidates who catch that nuance have clearly debugged a slow page, not just read the spec.

3A worked example: why Singapore users wait 720ms for a Virginia API#

This is the number I want you to be able to produce on a whiteboard.

  • A user in Singapore hits an API served only from us-east-1 (Virginia).
  • Round-trip time between the two is about 180ms.
  • The user makes a fresh HTTPS connection over HTTP/2 to a TLS 1.2 origin.
  • Count the round trips before the first response byte arrives.
Step Round trips Latency at 180ms RTT
TCP handshake (SYN, SYN-ACK, ACK) 1 180ms
TLS 1.2 handshake 2 360ms
HTTP GET and first response byte 1 180ms
Total time to first byte 4 720ms

Three quarters of a second, and the app has not rendered anything yet. Now apply two fixes and watch the number fall.

Pause before you read on: the problem is 4 round trips at 180ms. Which of those round trips can you actually remove, and which one is stuck?
Reveal the answer
You can move the TCP and TLS handshakes off the 180ms link by terminating them at an edge 10ms away, and you can shave a TLS round trip by going to 1.3. The one round trip you cannot delete is the origin fetch itself: the data lives in Virginia, so at least one 180ms trip is baked in. That single stuck round trip is the floor every fix converges toward.

Fix 1: terminate TLS at a CDN edge 10ms from the user.

  • The user now does its TCP and TLS handshakes against an edge POP at 10ms RTT, not Virginia at 180ms.
  • That is 1 + 2 = 3 round trips at 10ms, so 30ms of handshake.
  • The edge already holds a warm, pooled HTTP/2 connection to origin, so the origin leg is a single 180ms round trip with zero handshake tax.
  • Time to first byte drops to roughly 30 + 180 = 210ms.

Fix 2: move the edge to TLS 1.3.

  • The handshake at the edge is now 1 round trip instead of 2, so 2 round trips total at 10ms = 20ms.
  • On a resumed connection with 0-RTT, the handshake is effectively free.
  • Time to first byte against a warm edge sits near 190ms, bounded by the one origin round trip.
~190ms
720ms down to 190ms, zero app code changedA 3.8x win that came entirely from network topology and handshake math. This is the point to drive home: where the bytes handshake often matters more than what the endpoint does. If you can do this subtraction out loud, you have shown the interviewer you know where the time actually goes.

4Trade-offs#

Start with the one every interviewer wants to hear you get right.

HTTPS is not free, but it is cheap, and you should always use it

Modern hardware does AES in dedicated instructions (AES-NI), so per-byte encryption is a few percent of CPU at most. The real cost is handshake round trips on new connections, which is exactly what the worked example quantifies. That is why connection reuse matters so much.

Concern HTTP/1.1 HTTP/2 HTTP/3 (QUIC)
Transport TCP TCP UDP
Concurrency per conn 1 (serial) Many streams Many streams
Head-of-line blocking App + TCP TCP only None
Handshake RTTs (new) 1 TCP + TLS 1 TCP + TLS 1 combined
Connection migration No No Yes
Middlebox friendliness Best Good Can be blocked

Keep-alive and connection pooling: the single biggest latency win.

  • Open a brand-new TLS connection for every outbound call and you pay 2 to 3 round trips of overhead every time.
  • Across a region that is 100 to 300ms of pure handshake tax per call.
  • Pool your connections and reuse them.
  • For a service making millions of internal calls, this is the difference between a snappy p99 and a miserable one.

HTTP/2 to the backend: careful at the load balancer.

  • HTTP/2's single-connection model is great for browsers but can bite you at a load balancer.
  • A client holding one long-lived HTTP/2 connection, balanced at the connection level, pins all its traffic to one backend.
  • You usually want per-request balancing, which means the proxy terminates HTTP/2 and re-dispatches each stream.

TLS termination: where do you decrypt?

  • At the edge: the load balancer decrypts and talks plaintext internally. Centralizes cert management, offloads crypto from app servers, but your internal network now carries plaintext.
  • End to end: TLS all the way to the service. Safer in a zero-trust or multi-tenant environment, where you re-encrypt internally or use mTLS between services.
  • The cost of end to end: more cert rotation machinery and a bit more CPU everywhere.

0-RTT in TLS 1.3 and QUIC: fast, but with a sharp edge.

  • You can send application data in the very first packet on a resumed connection, saving a round trip (about 180ms in the Singapore example).
  • The catch: 0-RTT data is replayable by an attacker.
  • So you only put idempotent requests in 0-RTT. A GET for a product page, fine. A POST that charges a card, never.

5Where it is used#

Everywhere, but the shape changes with the layer.

  • Public web and mobile APIs: HTTPS is mandatory. Browsers mark plain HTTP as "not secure," and features like service workers and HTTP/2 only work over TLS. You will almost always terminate TLS at a CDN or load balancer.
  • CDNs: a CDN terminates TLS close to the user, cutting handshake round trips dramatically because the user is 10ms away instead of 180ms. It then talks a warm, pooled, often HTTP/2 connection back to origin. This is exactly the fix from the worked example.
  • Service-to-service inside a datacenter: weigh raw speed against trust boundaries. Many large systems run mTLS between every service via a service mesh sidecar, so identity is cryptographic, not based on "it came from inside the network."
  • Streaming and real-time: HTTP/3's connection migration is a real win for mobile. When a phone switches from WiFi to cellular its IP changes. A TCP connection dies and must be rebuilt (another 4 round trips of handshake); a QUIC connection carries a connection ID that survives the IP change, so the stream continues without a new handshake.

When would you not reach for HTTP?

  • Need persistent bidirectional push: move up to WebSockets (which still start life as an HTTP upgrade request).
  • Need streaming RPC: gRPC streaming over HTTP/2.
  • Very high-throughput internal RPC: gRPC over HTTP/2 with protobuf is a common default because it is binary, multiplexed, and strongly typed.

6Common pitfalls and gotchas#

Expired or misconfigured certificates.

  • The classic outage. A cert expires at 2am, pagers go off, half your traffic 500s.
  • Automate renewal and alert well before expiry, say 30 days out.
  • I have seen a billion-dollar product go dark because one cert lapsed.

Sending the wrong intermediate chain.

  • Your leaf cert is valid but you forgot to serve the intermediate.
  • Some clients cache the intermediate and work; others fail. It passes in your browser and fails for a fraction of users.
  • Test with a fresh client, not your dev laptop that already trusts everything.

Treating HTTP methods as suggestions.

  • GET must be safe and idempotent. A GET that mutates state gets quietly corrupted by a prefetcher or a retry.
  • PUT and DELETE should be idempotent so a client can safely retry after a timeout.
  • POST is the one that is not, which is exactly why 0-RTT and blind retries are dangerous for it.

Retrying non-idempotent requests.

  • A client times out waiting for a POST response, but the server actually processed it.
  • The client retries, you charge twice.
  • The fix is an idempotency key the server deduplicates on, not hoping the network behaves.

Mixed content.

  • An HTTPS page that pulls a script over plain HTTP.
  • Browsers block it, and an attacker could have swapped that script anyway.
  • Everything on a secure page must be secure.

Forgetting that TLS hides the body, not the destination.

  • The server IP and, historically, the SNI hostname are visible on the wire.
  • People assume HTTPS means total invisibility. It does not.
  • It means confidentiality of content and proof of who you are talking to.
Red flag that fails you here

Saying "HTTP/2 fixes head-of-line blocking" and stopping there. It fixes it at the application layer and reintroduces it at the TCP layer; only HTTP/3 over QUIC removes it fully. The half-right version signals you memorized a bullet point instead of debugging a stall.

7How it shows up in interviews#

Interviewers rarely ask "what is HTTPS" as a standalone question. It surfaces inside a bigger design: "design an image hosting service," "design a payment flow," "why is this API slow from Singapore." They are checking whether you reason about the network, not just the app logic.

Here is what separates strong from weak answers.

  • On latency. Weak: "we use HTTPS for security." Strong: "every new HTTPS connection from Singapore to Virginia costs a TCP handshake plus a TLS 1.2 handshake, about 4 round trips at 180ms RTT, so roughly 720ms before data flows. I would terminate TLS at a CDN edge 10ms from the user and keep warm pooled HTTP/2 connections to origin, which drops time to first byte to around 190ms."
  • On versions. Weak: "use the latest HTTP version." Strong: "HTTP/2 multiplexing lets the browser avoid six connections, but it still suffers TCP head-of-line blocking on packet loss, so for lossy mobile networks HTTP/3 over QUIC is worth it, and it survives WiFi-to-cellular handoff via connection migration."
  • On where to terminate TLS. Weak: "the load balancer handles TLS." Strong: "I terminate at the edge for central cert management and CPU offload, but since internal traffic is sensitive and multi-tenant, I re-encrypt with mTLS between services so identity is cryptographic, not perimeter-based."
  • On idempotency and retries. This is the one that quietly reveals seniority. Bring up idempotency keys unprompted on a write path over HTTP and interviewers notice. It tells them you have debugged a real double-charge.

Treat HTTP as a system with costs and failure modes, not a magic pipe. Know where the round trips are, and do the handshake arithmetic out loud.

Follow-ups the interviewer will ask (and your answers)
"This API is slow from Singapore. Walk me through the latency."
A fresh HTTPS connection to a Virginia origin is 4 round trips before first byte: 1 for TCP, 2 for TLS 1.2, 1 for the GET. At 180ms RTT that is about 720ms. I terminate TLS at a CDN edge 10ms away and keep warm pooled HTTP/2 connections to origin, which leaves one 180ms origin round trip and drops time to first byte to around 190ms. Moving the edge to TLS 1.3 shaves another handshake round trip.
"Does HTTP/2 fix head-of-line blocking?"
At the application layer, yes: multiplexed streams mean request two no longer waits on request one. But all streams still share one TCP connection, so a single lost packet stalls every stream at the transport layer. Only HTTP/3 over QUIC removes that, because QUIC has independent streams over UDP and a lost packet only stalls the one stream that needed it.
"Where would you terminate TLS, and why?"
At the edge for public traffic, because it centralizes cert management and offloads crypto from app servers while cutting handshake round trips for far-away users. Inside the datacenter, if traffic is sensitive or multi-tenant, I re-encrypt with mTLS between services so identity is cryptographic rather than perimeter-based. The trade-off is more cert rotation machinery and a little extra CPU everywhere.
"Can we send data in the first packet to save a round trip?"
Yes, with 0-RTT on a resumed TLS 1.3 or QUIC connection, worth about one RTT. The catch is that 0-RTT data is replayable, so I only allow it for idempotent requests. A GET is fine; a POST that charges a card is not, because a replay would double the charge.
"A client retries a POST after a timeout. How do you avoid a double charge?"
The client times out but the server may have processed the request, so a blind retry charges twice. The fix is an idempotency key: the client sends a unique key with the request, the server records it, and a retry with the same key returns the original result instead of re-executing. You do not rely on the network behaving.

What you can now explain in the room

  • Why HTTPS is just HTTP in a TLS tunnel, and the three guarantees TLS actually provides.
  • How to count handshake round trips and turn 720ms from Singapore into about 190ms with edge TLS termination.
  • Why connection reuse is the single biggest latency win on a service making many outbound calls.
  • The head-of-line blocking story across HTTP/1.1, HTTP/2, and HTTP/3, at both the app and TCP layers.
  • When 0-RTT is safe (idempotent reads) and when it bites you (replayable writes).
  • Why TLS hides the body but not the destination, and when to reach for mTLS between services.

Want to see this applied end to end? Try the System Design Question walkthrough on designing a low-latency global API, where connection reuse and edge TLS termination decide whether you hit your p99 target.

Get a prep plan built around your HTTP, HTTPS and TLS interview

Tell us the role and your interview date. We will send back a dated, day by day plan. Free.

Thanks. Check your inbox, your HTTP, HTTPS and TLS prep plan is on the way.