Skip to content
Lesson 56

HTTP and TLS

Open up the safe line: what an HTTP message carries, which headers decide who keeps a copy, what a TLS certificate proves, and why one expiry date took StayHub's bookings to zero.

The lesson in text

Click a paragraph to hear it.

01Midnight on Saturday

Saturday, 00:00 UTC. Omar's phone wakes up the team. Every call to api.stayhub.com is failing. Browsers show "Your connection is not private". Bookings drop from 200 an hour to zero.

Karim, the CTO, asks who deployed on a Friday night. Nobody did. The servers are healthy, using 12% of their processors. Nothing has crashed.

When we followed one click to a website, that error pointed at step two: the safe line. Today we open that line up. What HTTP really carries, what TLS really checks, and how a single date can take a company offline.

02Inside an HTTP message

Start with what travels inside the line. HTTP is plain text with a simple shape. A request has a method, like GET to read or POST to send, then a path, then headers, and sometimes a body with the data.

The response has the same shape: a status code, headers, then the body. You know 200, 404 and 500 already. Two more are worth knowing. 301: moved for good, go to this new address. And 304: not modified, the copy you have is still right.

An HTTP request and its response
Request
POST /bookings HTTP/2method + path
Host: api.stayhub.comwhich site
Cookie: session=7f3a…who you are
Content-Type: application/jsonwhat the body is
{"hotel":42,"nights":2}the body
Response
HTTP/2 201 Createdstatus code
Cache-Control: private, no-storewho may keep a copy
Content-Type: application/jsonwhat the body is
{"booking":"BK-1093"}the body
200
OK
301
moved for good
304
not modified
404
not found
500
server error
Same shape both ways: a first line, headers, an empty line, then the body. The status code's first digit says who had the problem: 3 = go elsewhere or reuse your copy, 4 = the request, 5 = the server.

Headers are where many decisions hide. They say which language you read, who you are, with a cookie, and one more thing that matters a lot: who is allowed to keep a copy of the answer.

That header is Cache-Control. A photo whose file never changes: anyone may keep it for a year. Hotel prices: keep them for one minute, then ask again. A guest's own bookings: private, no-store. Nobody in between may keep them.

The one-minute rule comes with a trick, the ETag: a fingerprint of the answer. After the minute, the browser asks: has it changed since this fingerprint? If not, the server replies 304, a few bytes instead of the whole answer.

Cache-Control: who may keep a copy
AnswerHeaderWho keeps it
A photo or script whose file name changes with its contentpublic, max-age=31536000Anyone, for a year
Hotel prices and availabilitymax-age=60 + ETagOne minute, then ask: changed? (304 if not)
A guest's own bookings, profile, paymentsprivate, no-storeNobody in between
The same bookings with public, max-age=3600public, max-age=3600A CDN serves guest A's bookings to guest B
Claude Code tends to copy the header from the nearest file. Decide the rule per kind of answer; anything that depends on who is logged in starts from private, no-store.

Get this wrong and it's a leak. If Claude Code copies "public" onto the bookings API, a CDN in front of it can keep the first guest's bookings and serve them to the next people who ask. Personal answers start from private, no-store.

03What TLS promises

Now the line itself. Without TLS, HTTP crosses the internet as readable text. Anyone along the way, the café Wi-Fi, any router, can read it, and even change it.

TLS gives you two things. First, encryption: only the two ends can read what is sent. Second, and just as important, identity: proof that you are really talking to api.stayhub.com, and not to someone pretending to be it.

Encryption without identity is worth nothing. A perfect secret code shared with an impostor is just a private conversation with the thief.

04An ID card at the desk

Here's how identity works. Before you hand your bank card to a hotel clerk, you'd want to see some ID. The name matches the hotel. The card hasn't expired. It carries the stamp of an authority you trust. You don't phone that authority: the stamp is enough.

A certificate is the server's ID card. It holds the server's name, its public key, a start date, an end date, and the signature of a certificate authority, a CA.

Your phone and your browser come with a short list of authorities they trust, called roots. A root rarely signs a server's card itself. It signs an intermediate, and the intermediate signs the server's certificate. That's the chain of trust.

The chain of trust
  1. Root certificatethe authority you trust
    Already on your phone and in your browser
  2. Intermediate certificatethe server must send it
    Signed by the root
  3. api.stayhub.comname · public key · start and end dates
    Signed by the intermediate
The browser follows the signatures upward until it reaches a root it already has. If the server forgets to send the intermediate, the chain stops short: browsers often fill the gap themselves, servers and apps usually don't.

In the handshake, the browser says hello and names the site it wants. The server answers with its certificate and the intermediate. The browser checks on its own: the right name, valid dates, signatures all the way up to a root it knows. Then both sides agree on keys. One round trip.

The TLS 1.3 handshake: one round trip
Browser
api.stayhub.com
hello · I want api.stayhub.com · my key share
hello · my key share · certificate + intermediate
checks passed · encrypted request
  • ✓ Right name?
  • ✓ Valid dates?
  • ✓ Signatures up to a known root?
The browser checks the certificate itself, without calling anyone. Any check fails, and it hangs up: that's the “Your connection is not private” page.

Why not phone the CA every time? Because that would add a round trip to every connection, and every website would go down whenever the CA did. So the CA signs in advance, and a signature can't be taken back. That's why every certificate has an end date.

And the browser has no judgement at all. If the ID expired one second ago, it walks away. No grace period, and no "it was fine yesterday".

05The certificate nobody owned

Back to Saturday. The certificate for api.stayhub.com was bought by hand two years ago, for one year, and renewed once, by an engineer who has since left. At 00:00 UTC it expired, and every browser and every app hung up in the same second.

The photos still loaded, because the CDN renews its own certificates. Only the API was dead. Installing a new certificate took minutes. Finding the login to the CA account took until 01:50.

One hour and fifty minutes, at about 200 bookings an hour: around 370 bookings lost. Nothing deployed, nothing crashed. Just a date.

Saturday: one date, two hours
00:00:00 UTC certificate endsevery browser and app hangs up
00:04 Omar paged100% of API calls failing; servers healthy (CPU 12%)
01:50 new certificate installedafter finding the CA account login
1 h 50 min × ~200 bookings/hour≈ 370 bookings lost
every certificate listed, public and internalinventory
ACME renewal at two-thirds of the lifetimeno human in the loop
daily check: alerts at 30, 14, 7 days leftpages on-call at 7
Bought by hand, renewed once by an engineer who left. The CDN's certificates renew themselves, so photos kept loading while the API was down.

Lina's rule: never again by hand. First, list every certificate, public and internal, with its end date. Then renew automatically with ACME, the protocol Let's Encrypt uses: a bot proves it controls the domain and gets a fresh certificate, long before the old one ends.

Then watch the result, not just the bot. A daily check warns at 30, 14 and 7 days left, and at 7 it wakes someone up, because bots fail quietly too. And lifetimes keep shrinking: since March 2026 a public certificate lasts at most 200 days, and from 2029, just 47. Renewing by hand is over.

06Turning the check off

The second classic mistake is worse, because nothing breaks. One day, calls from StayHub's workers to a partner's API start failing with: unable to verify the first certificate.

Someone finds a quick fix online and sets NODE_TLS_REJECT_UNAUTHORIZED to 0 in the setup every worker shares. The error disappears. So does every certificate check, for every call those workers make, the payment provider included.

Now the workers would encrypt, happily, to whoever answers. That's the impostor again. Nothing failed, so nobody noticed. A security test found it five weeks later.

The real cause was small: the partner's server didn't send its intermediate. Chrome quietly fills that gap; servers don't. The right fix: ask the partner to send the full chain, or trust that intermediate for that one client only. Never turn the check off.

“unable to verify the first certificate”
NODE_TLS_REJECT_UNAUTHORIZED=0 in the shared worker setup
Turns off every check, for every call, payment provider included. Found 5 weeks later.
Ask the partner to send its full chain
Fixes the real cause: the missing intermediate.
Trust that intermediate for that one client only
A narrow exception while the partner fixes it.
The error almost always means a missing intermediate. Silence it and you encrypt to whoever answers; fix it and you keep the identity check.

07Inside the walls

At the postmortem, Lina raises one more thing. Today, TLS ends at the load balancer. Behind it, StayHub's own services talk to each other in plain HTTP.

Karim pushes back: we just lost two hours to one certificate, and you want a hundred more? Lina answers: our network is private until one machine inside is broken into. Then every password and token between services is readable.

The decision: encrypt inside too, but only once certificates renew themselves. By hand, a hundred certificates would mean a hundred Saturdays. Both of them were right, in that order.

08Your job as lead

When Claude Code writes an HTTP response, check the caching header it chose. Ask: who may keep a copy of this answer? Anything that depends on who is logged in gets private, no-store.

When it touches TLS, ask three things. Which certificates do we have, and when does each one end? How does each one renew? And who gets warned, how many days before?

And search every diff for the check being turned off: NODE_TLS_REJECT_UNAUTHORIZED, or rejectUnauthorized set to false. Zero hits, always. A chain error gets fixed, never silenced.

Let's recap. HTTP is the message, and its headers decide who keeps a copy. TLS is the line: encryption plus identity. A certificate is an ID card with an end date, checked strictly by a browser with no judgement. Renew by bot, watch every date, and never turn the check off. Next: DNS, the internet's contacts list, in depth.

Check yourself

0/10 answered
  1. 1TLS protects a connection in two ways. Which two?

  2. 2Saturday at 00:00:00 UTC, every browser refuses api.stayhub.com. Nobody deployed and the servers are healthy. What's the most likely cause?

  3. 3How does a browser decide to trust a server's certificate?

  4. 4Why does every certificate have an end date?

  5. 5Claude Code adds `Cache-Control: public, max-age=3600` to the API that returns a guest's own bookings. What do you say?

  6. 6A browser asks for hotel prices with the ETag it received a minute ago, and nothing has changed. What does the server answer?

  7. 7Calls to a partner fail with "unable to verify the first certificate". Claude Code proposes `NODE_TLS_REJECT_UNAUTHORIZED=0` in the shared worker setup. What do you answer?

  8. 8The partner's site opens fine in Chrome, yet our server can't verify its certificate. Why?

  9. 9After the outage, what stops it from happening again?

  10. 10Lina wants to encrypt traffic between StayHub's own services. Karim fears a hundred more certificates. What's the best call?

Free account

Save your progress — create a free account

Free. No card. Your finished lessons follow you to any device, and you can ask questions in the community.

Create my free account
Founding members

Every lesson is free while we build. Lock in €9/month for later.

The first 100 members keep the founding price for as long as they stay. Reserving is free: no card, nothing is charged.

See the founding offer

Questions from the community

All questions →