awesome-everything RU
↑ Back to the climb

Caching

ETags: reading HTTP exchanges

Crux Read real HTTP exchanges — first fetch, revalidation, weak-vs-strong matching, and a range request — then predict the status the server returns and the highest-leverage fix.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 14 min

ETag bugs are diagnosed in the wire log, not the source. Read each exchange the way you would read it in DevTools or a tcpdump, then pick what the server returns — and, where something is wrong, the fix a senior engineer reaches for first.

Goal

Practise the loop you run in every caching incident: read the request and response headers, trace the validator comparison, and predict the status — 200 vs 304 — before you touch a config.

Exchange 1 — the revalidation handshake

# First fetch
GET /api/config HTTP/1.1
Host: api.example.com

HTTP/1.1 200 OK
ETag: "a3f5c901"
Content-Length: 8192
... 8 KB JSON body ...

# 30s later, content unchanged
GET /api/config HTTP/1.1
Host: api.example.com
If-None-Match: "a3f5c901"
Quiz

The content has not changed since the first fetch. What does the server return to the second request, and what crosses the wire?

Exchange 2 — weak tag, strong precondition

GET /report.html HTTP/1.1
Host: cdn.example.com
If-None-Match: "v42"

# server's current validator for this resource:
#   ETag: W/"v42"
Quiz

The client sent the strong tag in If-None-Match; the server currently holds the weak form of the same value. What status comes back?

Exchange 3 — resuming a download

GET /video.mp4 HTTP/1.1
Host: media.example.com
Range: bytes=1000000-
If-Range: W/"clip-build-9"

# server's current validator:
#   ETag: W/"clip-build-9"
Quiz

The client is resuming a download with If-Range carrying a weak validator that matches the server's current weak ETag. What does the server return?

Exchange 4 — the per-node regression

# Request lands on pod A, which minted the client's cached tag
GET /api/config HTTP/1.1
If-None-Match: "pod-a-counter-7"

HTTP/1.1 304 Not Modified

# Next poll round-robins to pod B
GET /api/config HTTP/1.1
If-None-Match: "pod-a-counter-7"

HTTP/1.1 200 OK
ETag: "pod-b-counter-3"
Content-Length: 8192
Quiz

Identical config content, yet pod A returns 304 and pod B returns 200 for the same If-None-Match. What is broken, and what is the highest-leverage fix?

Recap

Every ETag incident is read in the exchange: a matching If-None-Match returns 304 with an empty body but still costs the round-trip; If-None-Match compares weakly, so W/ and strong forms of the same value match; If-Range is the one place that demands a strong validator, so a weak tag forces a full 200 instead of a 206; and when identical content yields different tokens on different pods, the bug is a node-local ETag — fix it by deriving the tag from the content, not the box.

Continue the climb ↑ETags: make revalidation survive the load balancer
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources2
expand
  1. 01
  2. 02

Trademarks belong to their respective owners. Editorial reference only.