HTTP ETags and Conditional Requests for Efficient, Correct API Caching
Revalidate cached representations cheaply and detect stale writes instead of overwriting newer data.
An ETag is a validator associated with a selected representation. Clients send it back in conditional requests, allowing a server to return 304 Not Modified for an unchanged GET or reject a stale mutation with a failed precondition.
THE PRODUCTION PROBLEM STATEMENT
Repeatedly downloading an unchanged large response wastes bandwidth, while unconditional updates can overwrite changes made after a form was loaded. HTTP validators solve these related but distinct problems with conditional request headers.
Revalidate a cached GET with If-None-Match
The server returns an ETag with a representation. Later, a client sends If-None-Match; if the current representation still matches, the server can respond with 304 and no body. The cache reuses its stored representation while refreshing validation state.
An ETag can derive from a content hash, version number, or another stable validator. If the response varies by language, authorization, or request headers, account for those dimensions with correct cache keys and Vary behavior.
GET /api/reports/42 HTTP/1.1
If-None-Match: "report-v17"
HTTP/1.1 304 Not Modified
ETag: "report-v17"
Cache-Control: private, no-cacheProtect updates with If-Match and strong validators
A client can send If-Match with the version it originally read when updating a resource. If the current representation no longer matches, the server returns 412 Precondition Failed rather than silently overwriting another user’s change.
For lost-update protection, use a strong validator that changes whenever the relevant representation changes. Weak ETags indicate semantic equivalence for cache validation and are not suitable for strong If-Match comparison.
PUT /api/reports/42 HTTP/1.1
If-Match: "report-v17"
Content-Type: application/json
{"title":"Quarterly report"}Separate freshness policy from representation validation
Cache-Control determines how long a response can be reused without contacting the origin. An ETag helps validate a stored response when revalidation is needed. These mechanisms complement each other; neither implies the other.
Do not expose personalized data through shared caches unless the policy and cache key are designed for it. Conditional requests improve efficiency and concurrency control, but they do not replace authorization on every request.
Frequently Asked Questions & Technical Inquiries
Direct, practical answers to common architectural and debugging questions.
No. It tells the client that its stored representation remains valid and avoids retransmitting that body.
Faisal Askari
Verified AuthorSoftware Engineer & Full-Stack Developer
Faisal Askari is a software engineer with deep expertise in web systems architecture, the JavaScript runtime ecosystem, and client-side performance engineering. Over years of hands-on production engineering, he has designed and shipped enterprise dashboards, high-converting digital interfaces, and specialized full-stack applications.
Distributed Cache Architectures: Stale-While-Revalidate, Cache Stampede Protection, and Redis Tag Invalidation
How to build high-concurrency caching tiers: probabilistic early expiration (XFetch), distributed mutex locks, and targeted cache-tag purging.
Resilient Full-Stack Architecture: Idempotent APIs, Optimistic UI, and Cache Invalidation
Engineering robust distributed state between client and server: idempotency keys, safe optimistic rollbacks, exponential backoff with jitter, and cache coherence.