{"canonical_url":"https://engineer.company/glossary/etag/","content_markdown":"# ETag\n\n## What it is\n\nAn ETag is an HTTP validator for a particular representation of a resource. The\nserver sends a tag with a response so another request can refer to the version\nthe client already received. Clients treat the value as opaque. A server may\nderive it from its own representation identity, but the client can use the\nvalidator without knowing how it was generated.\n\nA strong validator supports comparison where exact representation data matters.\nA weak ETag indicates that the server considers the representations equivalent\nfor certain operations even though their data can differ. In the HTTP header\nsyntax a weak validator has a `W/` prefix. Use the comparison required by the\nrequest condition. A check that needs strong comparison cannot gain that\nguarantee from a weak ETag.\n\nConditional retrieval is a common use. A client can send `If-None-Match` with a\nvalidator it has. For a matching representation, a `GET` or `HEAD` request can\nreceive status `304`, which lets an existing stored response be reused.\nConditional writes can use `If-Match` to require that the resource still matches\na strong validator before an update. A failed condition can produce status\n`412`. The server still needs to apply ordinary access checks for the operation.\n\n## Why it matters\n\nA reader who returns to an article may already have its body. Repeating the\ntransfer adds latency and work. A validator allows the server to confirm that\nthe selected representation remains current. It also gives the reader a way to\nfetch a changed version when the stored validator no longer matches. The cache\npolicy determines when to ask the server, and the validator helps it answer.\n\nA shared document editor can use validators for a different decision. Two people\nmay read the same version. If one saves an update, the other can submit a\nconditional write based on the version they originally edited. When the stored\nversion has changed, the service can refuse the second condition and offer a way\nto review the new document. The user can see and resolve the editing conflict\nwhile the newer document stays intact.\n\nRepresentation identity needs care when there are variants. A URL can serve a\ncompressed response and an uncompressed one. A locale, media type or selection\nrule can also affect the data. A validator has to be meaningful for the\nrepresentation the condition refers to. Include that boundary in tests,\nparticularly when an intermediary adds compression or another transformation.\n\n## What it looks like in practice\n\nConsider a published help page. Load it through its public address and retain\nboth the body and ETag. Send a conditional GET with the stored tag. Verify that\na matching representation produces the expected status and that the response\ncarries the metadata the cache needs to use its previous copy. Change the\ndocument through the normal release path and repeat the condition. The client\nshould receive the updated body and a meaningful validator for it.\n\nFor an editing example, read a record and remember its strong validator. Apply\nan update through another authorised operation, then submit the original edit\nwith its older tag as a condition. Verify the failure result and read the stored\nrecord back. A test that checks only a status code can miss a server that\napplied the write before rejecting the response. Check both the client-facing\noutcome and durable state.\n\nEngineer's\n[small-server case study](/portfolio/a-whole-company-on-one-small-server/)\ndescribes hosting public content with limited resources. Conditional retrieval\nis an example of making a repeated read economical on such a service. Measure it\nat the public route and verify the behaviour after content changes. The\nimplementation can give returning readers current content while avoiding a body\ntransfer when the version is still valid.\n\nTest both request conditions using real clients or a reproducible fixture.\nObserve a returning browser, then a request with a deliberately older tag.\nInclude a public path that passes through the service's normal compression and\nrouting. The tests show which layer produced the validator and which\nrepresentation the comparison applied to.\n\n## Where it goes wrong\n\nA validator generated from a resource's name or deployment timestamp can have a\nmisleading relationship to the bytes. Two responses might share the same tag\neven though the representation differs. Other outputs can acquire new tags\nunnecessarily on every build. Tie validator generation to the comparison the\napplication promises. Include compressed variants and responses where only an\nimportant generated field changes.\n\nConditional writes need their comparison in the same operation that changes\nstate. An application can read the current version, check the tag and execute a\nlater unconditional update. Another writer then has room to change the record\nbetween those steps. Arrange for the update to check the version it changes and\ntest two overlapping requests. An expected conflict should leave the existing\nedit intact.\n\nAn intermediary can generate, adjust or remove a validator while applying a\ntransformation. Capture the response seen by the client after compression and\nrouting. Compare the tags for the supported variants and reproduce the\nconditional request through that same boundary. This prevents a test from\ncertifying a private origin response whose validator never reaches the public\nclient. If a cache reuses the stored body, inspect its metadata too. The test\nshould show that the retained bytes match the representation the client\nrequested.\n\nFinally, distinguish the version of a representation from permission to use it.\nA cached tag says what content a client observed and supplies no authority.\nProtect the request through the same access checks the normal route uses. A\nuseful validator has a clear resource scope, a documented comparison and a test\nthat can demonstrate what happens after an update.\n\n## Further reading\n\n- [RFC 9110 on entity tags](https://www.rfc-editor.org/rfc/rfc9110.html#section-8.8.3).\n  Defines strong and weak entity-tag semantics.\n- [Mozilla's ETag documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag).\n  Shows practical validation and concurrent editing examples.\n- [Amazon S3 conditional writes](https://docs.aws.amazon.com/AmazonS3/latest/userguide/conditional-writes.html).\n  Documents precondition checking for an object store.\n\n\u003chttps://engineer.company/glossary/etag/\u003e\n","date_modified":"2026-11-25T07:18:46Z","description":"Use ETags to validate a cached response or guard an edit, and understand where strong comparison matters.","formats":{"gemtext":"https://engineer.company/glossary/etag/index.gmi","gopher":"https://engineer.company/glossary/etag/gophermap","html":"https://engineer.company/glossary/etag/","json":"https://engineer.company/glossary/etag/index.json","markdown":"https://engineer.company/glossary/etag/index.md","pdf":"https://engineer.company/glossary/etag/index.pdf"},"kind":"page","language":"en","title":"What is an ETag?","url":"https://engineer.company/glossary/etag/","version":1}