<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vinay Arvind Badgujar</title>
    <description>The latest articles on DEV Community by Vinay Arvind Badgujar (@vinaybadgujar102).</description>
    <link>https://dev.to/vinaybadgujar102</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1110388%2F2f91d665-827a-4d38-a44a-1f8673d005bd.jpeg</url>
      <title>DEV Community: Vinay Arvind Badgujar</title>
      <link>https://dev.to/vinaybadgujar102</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vinaybadgujar102"/>
    <language>en</language>
    <item>
      <title>Understanding Serialization Anomalies from First Principles</title>
      <dc:creator>Vinay Arvind Badgujar</dc:creator>
      <pubDate>Mon, 29 Jun 2026 05:31:51 +0000</pubDate>
      <link>https://dev.to/vinaybadgujar102/understanding-serialization-anomalies-from-first-principles-5en5</link>
      <guid>https://dev.to/vinaybadgujar102/understanding-serialization-anomalies-from-first-principles-5en5</guid>
      <description>&lt;p&gt;Yeah so what exactly is a &lt;strong&gt;serialization anomaly&lt;/strong&gt; in the context of database transactions?&lt;/p&gt;

&lt;p&gt;Suppose we have two transactions, &lt;code&gt;T1&lt;/code&gt; and &lt;code&gt;T2&lt;/code&gt;, running concurrently. They both read and write some of the same rows.&lt;/p&gt;

&lt;p&gt;After both transactions finish, the database reaches some final state.&lt;/p&gt;

&lt;p&gt;As we all know, if transactions are allowed to freely interleave their reads and writes, we can end up with anomalies like lost updates, dirty reads, non-repeatable reads, etc.&lt;/p&gt;

&lt;p&gt;One way databases reason about correctness is through &lt;strong&gt;serializability&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The idea is simple:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run &lt;code&gt;T1&lt;/code&gt; then &lt;code&gt;T2&lt;/code&gt; (serial execution) → Final State 1&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;T2&lt;/code&gt; then &lt;code&gt;T1&lt;/code&gt; (serial execution) → Final State 2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These two serial executions don't necessarily produce the same final state.&lt;/p&gt;

&lt;p&gt;Now suppose &lt;code&gt;T1&lt;/code&gt; and &lt;code&gt;T2&lt;/code&gt; actually execute concurrently. If the final state produced by this concurrent execution is equivalent to &lt;strong&gt;either&lt;/strong&gt; of the valid serial executions, then the schedule is &lt;strong&gt;serializable&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If the concurrent execution produces a state that &lt;strong&gt;cannot&lt;/strong&gt; be obtained by any serial ordering of those transactions, then you've hit a &lt;strong&gt;serialization anomaly&lt;/strong&gt; (or equivalently, the schedule is &lt;strong&gt;not serializable&lt;/strong&gt;).&lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;

&lt;p&gt;Suppose we have two rows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A = 100
B = 100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;T1&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;read A
read B
write A = A + B
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;T2&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;read A
read B
write B = A + B
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first glance, you might expect:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;T1 updates &lt;code&gt;A&lt;/code&gt; to &lt;code&gt;200&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;T2 updates &lt;code&gt;B&lt;/code&gt; to &lt;code&gt;200&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;giving the final state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A = 200
B = 200
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's compare that with the serial executions.&lt;/p&gt;

&lt;h3&gt;
  
  
  T1 → T2
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;T1:
reads A=100, B=100
writes A=200

State:
A=200
B=100

T2:
reads A=200, B=100
writes B=300

Final:
A=200
B=300
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  T2 → T1
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;T2:
reads A=100, B=100
writes B=200

State:
A=100
B=200

T1:
reads A=100, B=200
writes A=300

Final:
A=300
B=200
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Neither serial execution produces &lt;code&gt;(A=200, B=200)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That result is only possible if both transactions read the original values &lt;code&gt;(100, 100)&lt;/code&gt; before either transaction committed.&lt;/p&gt;

&lt;p&gt;That's the serialization anomaly.&lt;/p&gt;

&lt;p&gt;Each transaction made a decision based on a snapshot that the other transaction later invalidated. The resulting database state cannot be explained by &lt;strong&gt;any&lt;/strong&gt; serial execution of &lt;code&gt;T1&lt;/code&gt; and &lt;code&gt;T2&lt;/code&gt;, so the concurrent schedule is &lt;strong&gt;not serializable&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>backend</category>
      <category>computerscience</category>
      <category>database</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
