ETags and the Environmental Cost of Data That Didn’t Need to Move

I recently came across an API where the same resource was being requested over and over again.
Nothing unusual about that. APIs get polled. Clients refresh. Dashboards fetch the latest state.
What caught my attention was that most of those requests were returning exactly the same response.
The client already had the data.
The server knew the data had not changed.
And yet, we were still doing the entire request-response cycle again.
That got me thinking.
What if the client could simply ask, “Has this changed?” instead of asking, “Give me this again?”
HTTP already has an answer for this
That question is actually built into HTTP.
The first time the client requests the resource, the server can return an ETag along with the response.
HTTP/1.1 200 OK
ETag: "a8f31c"
{
...
}
The client stores that ETag.
When it requests the same resource again, it sends the ETag back:
GET /resource
If-None-Match: "a8f31c"
Now the server has two possibilities.
If the representation has changed:
HTTP/1.1 200 OK
ETag: "b72d91"
{
...
}
If it hasn’t:
HTTP/1.1 304 Not Modified
No response body.
The client doesn’t need the resource again because it already has the current representation.
The interesting thing here is that we didn’t make the response smaller.
We made the response unnecessary.
Where does the ETag come from?
The interesting part is that HTTP doesn’t tell you what the ETag should be.
It only gives you the mechanism.
You have to decide what should represent the identity of your response.
One simple approach is to hash the response body:
etag = sha256(response_body).hexdigest()
If the response is identical, the hash is identical.
If the response changes, the ETag changes.
But this isn’t always the best option.
If the resource already has a version number, we could use that instead:
ETag: "user-123-v42"
Now we don’t need to hash a potentially large response just to figure out whether it changed.
And this is where I think ETags get more interesting.
The question isn’t really:
“How do I generate an ETag?”
It is:
“What does my system consider to be the same response?”
If an internal database field changes but that field isn’t exposed by the API, should the ETag change?
Probably not.
If two different internal states produce the same API representation, the client doesn’t care that the internal state changed.
The ETag is ultimately a statement about the representation, not necessarily about the underlying resource.
That distinction becomes important when designing the system.
ETags are not a replacement for caching
This is where it is easy to oversell ETags.
An ETag can tell us that the representation the client already has is still valid.
But the server still has to determine that.
If generating the ETag requires rebuilding a large response and hashing it every time, we may have saved network bandwidth while doing almost all the work on the server anyway.
This is why the way we generate the ETag matters.
If a cheap version number already exists, we can use that.
If the response is already being generated for another reason, hashing it may be perfectly reasonable.
And if the data itself is expensive to compute, application-level caching may still be necessary.
So I don’t think of ETags as a caching strategy.
I think of them as a validation mechanism.
Caching asks:
Can I avoid generating this again?
ETags ask:
Does the client already have the representation it needs?
They can work together, but they solve different problems.
When ETags actually save work
There is an important distinction here.
An ETag does not magically make the server stop querying the database.
If you generate the ETag by hashing the response, you may still have to build that response before you can hash it.
So the real benefit depends on where the ETag comes from.
If the resource already has a cheap version or revision number, the server can check that first.
For example:
resource version = 42
client version = 42
→ 304 Not Modified
No need to build and serialize the full response.
But if determining the current version requires an expensive computation, we haven’t really eliminated that work.
We’ve only avoided the work that comes after it.
This is an important distinction when implementing ETags.
An optimization is only useful when the thing you do to decide whether to optimize is cheaper than the thing you’re trying to avoid.
That is probably the part of ETags I find most interesting.
Strong and weak ETags
There is another detail here that makes the idea more interesting.
Not every change in a response necessarily matters to the client.
HTTP gives us two kinds of ETags for this.
A normal ETag is a strong validator:
ETag: "a8f31c"
It means the representation is considered identical.
A weak ETag is prefixed with W/:
ETag: W/"a8f31c"
This means the representations may not be byte-for-byte identical, but the server considers them equivalent for the purpose of validation.
That distinction is useful when the representation can change in ways that don’t actually matter to the consumer.
For example, maybe the ordering of some fields changes, or some insignificant formatting changes.
The deeper point is that “has this changed?” is not always a binary question.
Changed in what sense?
Changed internally?
Changed byte-for-byte?
Changed in a way that matters to the client?
The ETag forces us to be explicit about what kind of change our system actually cares about.
And that is a surprisingly important question when designing any system.
The deeper idea
The more I think about ETags, the less I see them as a caching feature.
They are really a mechanism for knowing when not to repeat yourself.
We often approach optimization by asking:
How can I make this operation faster?
Use a faster database.
A faster serializer.
A faster network.
More compute.
But there is another question that is easy to miss:
Do I need to perform this operation at all?
That is a different kind of optimization.
ETags are a very small example of it.
The client already has a representation.
The server can establish whether that representation is still valid.
If it is, there is nothing new to send.
The system becomes more efficient not because it became better at doing the work, but because it became better at knowing when the work was unnecessary.
Maybe doing less is an engineering skill
ETags are a small feature in HTTP.
But they capture an idea I find useful far beyond HTTP.
Good systems don’t just know how to do things efficiently.
They know when something doesn’t need to be done.
Sometimes the best optimization is not doing the same work faster.
It is recognizing that you already have the answer.