<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Design Archives - Codersee blog- Kotlin on the backend</title>
	<atom:link href="https://blog.codersee.com/tag/design/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Kotlin &#38; Backend Tutorials - Learn Through Practice.</description>
	<lastBuildDate>Wed, 16 Apr 2025 04:49:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://blog.codersee.com/wp-content/uploads/2025/04/cropped-codersee_logo_circle_2-32x32.png</url>
	<title>Design Archives - Codersee blog- Kotlin on the backend</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>What are HTTP ETags?</title>
		<link>https://blog.codersee.com/what-are-http-etags/</link>
					<comments>https://blog.codersee.com/what-are-http-etags/#respond</comments>
		
		<dc:creator><![CDATA[Piotr]]></dc:creator>
		<pubDate>Sun, 19 Jan 2025 06:00:00 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[REST]]></category>
		<guid isPermaLink="false">https://codersee.com/?p=16011368</guid>

					<description><![CDATA[<p>In this article, we will learn what ETags are and how they relate to If-None-Match, If-Match headers, and 304 and 412 HTTP status codes. </p>
<p>The post <a href="https://blog.codersee.com/what-are-http-etags/">What are HTTP ETags?</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">At the end of this blog post, you will know:</p>



<ul class="wp-block-list">
<li>what problems do they solve?</li>



<li>what is an ETag and how is it calculated?</li>



<li>how do they relate to <code data-enlighter-language="generic" class="EnlighterJSRAW">If-None-Match</code> and <code data-enlighter-language="generic" class="EnlighterJSRAW">If-Match</code> headers?</li>



<li>what do <code data-enlighter-language="generic" class="EnlighterJSRAW">412 Precondition Failed</code> and <code data-enlighter-language="generic" class="EnlighterJSRAW">304 Not Modified</code> got do to with all of that?</li>
</ul>



<p class="wp-block-paragraph">Of course, this is more theoretical content, and you can expect some pragmatic examples with Spring Boot and Ktor soon😉<a href="https://blog.codersee.com/what-are-http-etags/" target="_blank" rel="noreferrer noopener"></a></p>



<h2 class="wp-block-heading" id="h-video-content">Video Content</h2>



<p class="wp-block-paragraph">As always, if you prefer a video content, then please check out my latest YouTube video:</p>



<div style="text-align: center; width: 90%; margin-left: 5%;">
<a href="https://blog.codersee.com/what-are-http-etags/"><img decoding="async" src="https://blog.codersee.com/wp-content/plugins/wp-youtube-lyte/lyteCache.php?origThumbUrl=%2F%2Fi.ytimg.com%2Fvi%2FtWu9lBlghOc%2Fhqdefault.jpg" alt="YouTube Video"></a><br /><br /></p></div>



<p class="wp-block-paragraph">If you find this content useful,<strong> please leave a subscription</strong> 🙂</p>



<h2 class="wp-block-heading" id="h-what-problems-etags-solve">What Problems ETags Solve?</h2>



<p class="wp-block-paragraph">Let&#8217;s start everything by figuring out the most important thing- <strong>what actual problems Etags help us solve? </strong>At the end of the day, what is the point of any additional work if it does not bring any value?😉</p>



<p class="wp-block-paragraph">Well, long story short, the Entity Tags help us to deal with two problems:</p>



<ul class="wp-block-list">
<li>waste of bandwidth and resources to consume the response of unchanged data,</li>



<li>updating data that changed since we last fetched them.</li>
</ul>



<h2 class="wp-block-heading" id="h-problem-1-waste-of-bandwidth-amp-resources">Problem #1- Waste of Bandwidth &amp; Resources</h2>



<p class="wp-block-paragraph">So what do we exactly mean by problem #1- the waste of bandwidth? Let&#8217;s imagine a pretty standard client &lt;-&gt; server communication. The client asks the server for some data, like product details (also known as <em>entity</em>, or <em>resource </em>in terms of REST). The server fetches necessary data from the database, sometimes performs additional actions, and eventually returns them to the client (let&#8217;s say a mobile application) with <code data-enlighter-language="generic" class="EnlighterJSRAW">200 OK</code> status code.</p>



<p class="wp-block-paragraph">Then, our client consumes that response- for example, converts the returned JSON and displays that to the user.</p>



<p class="wp-block-paragraph">And up until now, everything is perfectly fine. But, let&#8217;s imagine a situation, in which our product remains untouched- no price, no title, nothing changes- but our client keeps querying the server. In such a case, the <strong>bandwidth </strong>used to transfer the exact same data over and over, and the client resources used to process that could be utilized better, right?</p>



<p class="wp-block-paragraph">And as you might have guessed- that&#8217;s where ETags come with help🙂</p>



<h2 class="wp-block-heading" id="h-what-is-an-etag-and-how-it-is-calculated">What is an ETag and How It is Calculated?</h2>



<p class="wp-block-paragraph">Long story short- ETag (aka Entity Tag)- <strong>uniquely identifies a version of the entity</strong>.</p>



<p class="wp-block-paragraph">In other words, it is a bunch of characters (like <code data-enlighter-language="generic" class="EnlighterJSRAW">0633010ca130d326f83ef9fee25491e7e</code>) that remain constant for a particular version of an entity. If the entity (product in our example) is updated, a new tag is generated and remains constant until the next update.</p>



<p class="wp-block-paragraph">From the implementational perspective, this can be anything from a version field in the database, a hashed timestamp of an update, or a hash of the response. Oftentimes, this hash is obtained using the <strong>MD5 algorithm</strong>.</p>



<h2 class="wp-block-heading" id="h-solve-problem-1-with-etags">Solve Problem #1 With ETags</h2>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="576" src="http://blog.codersee.com/wp-content/uploads/2025/01/codersee_etags_bandwidth_waste_solution-1024x576.png" alt="Image is a diagram explaining HTTP communication between client and server using ETags " class="wp-image-16011373" srcset="https://blog.codersee.com/wp-content/uploads/2025/01/codersee_etags_bandwidth_waste_solution-1024x576.png 1024w, https://blog.codersee.com/wp-content/uploads/2025/01/codersee_etags_bandwidth_waste_solution-300x169.png 300w, https://blog.codersee.com/wp-content/uploads/2025/01/codersee_etags_bandwidth_waste_solution-768x432.png 768w, https://blog.codersee.com/wp-content/uploads/2025/01/codersee_etags_bandwidth_waste_solution-1536x864.png 1536w, https://blog.codersee.com/wp-content/uploads/2025/01/codersee_etags_bandwidth_waste_solution.png 1920w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">Alright, so how we can use this identifier/tag to fix the waste in our client &lt;-&gt; server scenario? Well, pretty easily.</p>



<p class="wp-block-paragraph">From the server perspective, whenever clients ask us for the data, we fetch them, calculate the ETag, and return <code data-enlighter-language="generic" class="EnlighterJSRAW">200 OK</code> response with an <strong>additional </strong><code><strong>ETag</strong></code><strong> header. </strong>For example: <code data-enlighter-language="generic" class="EnlighterJSRAW">ETag: "0e927523c29b6de3a9e3653df0e11762d"</code> .</p>



<p class="wp-block-paragraph">The client, on the other hand, is responsible for persisting ETags locally and later, sending them as an <strong>additional <code data-enlighter-language="generic" class="EnlighterJSRAW">If-None-Match</code> header</strong>, example: <code data-enlighter-language="generic" class="EnlighterJSRAW">If-None-Match: "0e927523c29b6de3a9e3653df0e11762d"</code> .</p>



<p class="wp-block-paragraph">And whenever our server detects the <code data-enlighter-language="generic" class="EnlighterJSRAW">If-None-Match</code> , it fetches the data from the database, calculates the hash, and compares them. If they match, it means the resource has not changed since the last request. And in such a case, the server will send an <strong>empty response body </strong>with <code data-enlighter-language="generic" class="EnlighterJSRAW">304 Not Modified</code> HTTP status code. If they don&#8217;t match, then the request body is sent along with <code data-enlighter-language="generic" class="EnlighterJSRAW">200 OK</code> status code (and another ETag value).</p>



<p class="wp-block-paragraph">As we can see, this allows us to fix the issue of wasted bandwidth, and potentially, the client resources. However, this does not prevent the client from making requests to the server, and the server from computing the data. For that purpose, we should lean towards <strong>client caching</strong> and proper <strong>cache control</strong>.</p>



<h3 class="wp-block-heading">Problem #2- Update Changed Entity</h3>



<p class="wp-block-paragraph">At this point, we know both the issue and solution for repeated queries. So in this paragraph, let&#8217;s take a closer look into issue #2.</p>



<p class="wp-block-paragraph">This time, let&#8217;s imagine we have 2 users that simultaneously fetched the same version of the entity- product in our case. Now, <em>user 1 </em>decides to update the product title. He hits update, his application sends a PUT request and the update succeeds. As we are using HTTP, <em>user 2</em> (client) is not aware of the update. The application still displays old data. So, if he decides now to update some other field, like description, the PUT request may override the title with old data!</p>



<h3 class="wp-block-heading">How ETags Can Help With Collisions?</h3>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="576" src="http://blog.codersee.com/wp-content/uploads/2025/01/codersee_etags_collision_solution-1024x576.png" alt="This image presents a HTTP communicate schema for the entity update and how ETags can help to avoid updating changed entity" class="wp-image-16011378" srcset="https://blog.codersee.com/wp-content/uploads/2025/01/codersee_etags_collision_solution-1024x576.png 1024w, https://blog.codersee.com/wp-content/uploads/2025/01/codersee_etags_collision_solution-300x169.png 300w, https://blog.codersee.com/wp-content/uploads/2025/01/codersee_etags_collision_solution-768x432.png 768w, https://blog.codersee.com/wp-content/uploads/2025/01/codersee_etags_collision_solution-1536x864.png 1536w, https://blog.codersee.com/wp-content/uploads/2025/01/codersee_etags_collision_solution.png 1920w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">In order to avoid this situation, we must make a small change in our API.</p>



<p class="wp-block-paragraph">So, just like previously, when both clients make their 1st request, they get <code data-enlighter-language="generic" class="EnlighterJSRAW">200 OK</code> response with an <strong>additional <code data-enlighter-language="generic" class="EnlighterJSRAW">ETag</code> header. </strong>For example: <code data-enlighter-language="generic" class="EnlighterJSRAW">ETag: "0e927523c29b6de3a9e3653df0e11762d"</code> .</p>



<p class="wp-block-paragraph">Now, whenever any client application wants to update the product, it sends a PUT request with an <strong>additional <code data-enlighter-language="generic" class="EnlighterJSRAW">If-Match</code> header</strong>, like: <code data-enlighter-language="generic" class="EnlighterJSRAW">If-Match: "0e927523c29b6de3a9e3653df0e11762d"</code><strong> . </strong>And this time, the server calculates the ETag of the desired entity <strong>before making any changes</strong>. If it does not match, it means that the entity was changed in the meantime, and the server notifies our client with <code data-enlighter-language="generic" class="EnlighterJSRAW">412 Precondition Failed</code> status code.</p>



<p class="wp-block-paragraph">Thanks to that, the client application has the chance to inform users about the updated entity/resource and handle that appropriately (for example, by displaying the popup).</p>



<p class="wp-block-paragraph">This time, we can clearly see that the solution is not about performance and resources- it is about <strong>consistency</strong>.</p>



<h2 class="wp-block-heading" id="h-summary">Summary</h2>



<p class="wp-block-paragraph">And basically that is all for this article about ETags.</p>



<p class="wp-block-paragraph">I hope it helped you to understand them better and provide you with ideas on how to apply them in your project.</p>



<p class="wp-block-paragraph">Let me know your thoughts in the comments section!🙂</p>
<p>The post <a href="https://blog.codersee.com/what-are-http-etags/">What are HTTP ETags?</a> appeared first on <a href="https://blog.codersee.com">Codersee blog- Kotlin on the backend</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.codersee.com/what-are-http-etags/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 

Served from: blog.codersee.com @ 2026-06-11 00:59:45 by W3 Total Cache
-->