<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Prathit  Malik on Medium]]></title>
        <description><![CDATA[Stories by Prathit  Malik on Medium]]></description>
        <link>https://medium.com/@prathitmalik06?source=rss-ec95541b5010------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*wxVJ8tjkwwbC6iA7</url>
            <title>Stories by Prathit  Malik on Medium</title>
            <link>https://medium.com/@prathitmalik06?source=rss-ec95541b5010------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 17:28:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prathitmalik06/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How INTEGER and INT Produced Different Schemas in Debezium]]></title>
            <link>https://lambda.blinkit.com/how-integer-and-int-produced-different-schemas-in-debezium-9c98e8a80aa2?source=rss-ec95541b5010------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c98e8a80aa2</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[debezium]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[blinkit]]></category>
            <dc:creator><![CDATA[Prathit  Malik]]></dc:creator>
            <pubDate>Wed, 02 Sep 2026 07:02:01 GMT</pubDate>
            <atom:updated>2026-09-02T07:02:01.372Z</atom:updated>
            <content:encoded><![CDATA[<p>A Debezium investigation: how MySQL synonyms INT and INTEGER were treated as different types.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8VlS0lmNjq5AhTYmG5ncUg.png" /></figure><p>One of our CDC pipelines started failing with a ClassCastException on every batch.</p><pre>java.lang.ClassCastException: class java.lang.Integer<br>  cannot be cast to class java.lang.Long</pre><p>The pipeline was producing an Integer, but the downstream consumer expected a Long. Every run failed in the same way, which pointed us toward a schema mismatch rather than an issue with individual records.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JLzPPLEpEccPkthPOGNGWw.png" /></figure><h3>Background: how CDC works</h3><p>To see why a mismatch like that can hide for years, it helps to know how CDC actually works. Most companies replicate their transactional database (MySQL, Postgres, something similar) into a separate <strong>data lake</strong> for analytics, rather than querying the source directly, and <strong>Change Data Capture (CDC)</strong> is what keeps that copy in sync: it tails the database’s transaction log and replays every insert, update, and delete downstream. <strong>Debezium</strong> is the most widely used open-source CDC tool for MySQL, and it builds a table’s schema in one of two ways that are supposed to agree but do not always.</p><ul><li><strong>Streaming mode</strong>: the first time it sees a CREATE TABLE or ALTER TABLE in the binlog, it parses the raw SQL text and writes the result to its own internal Kafka topic, database.history.kafka.topic. Every restart after that rebuilds the in-memory schema by replaying that topic, not by re-reading the binlog.</li><li><strong>Snapshot mode</strong>: reads the table definition fresh through MySQL’s JDBC metadata interface, which normalizes types, every time it runs.</li></ul><p>Schema Registry sits downstream of both: each connector writes whatever schema it built into the registry, but neither connector reads its own schema back from it. Keep that in mind; it matters later.</p><h3>The trigger: a routine migration</h3><p>With that in mind, here’s what actually happened to us. Rewind two years: one of our upstream service teams added a few columns to a source table as part of a standard schema change.</p><pre>ALTER TABLE &lt;source_table&gt;<br>    ADD COLUMN length           double          NULL,<br>    ADD COLUMN volume_remaining bigint UNSIGNED NULL,<br>    ADD COLUMN status           varchar(50)     NULL,<br>    ADD COLUMN volume_total     bigint UNSIGNED NULL,<br>    ADD COLUMN weight_total     integer UNSIGNED NULL,<br>    ADD COLUMN volume_used      bigint UNSIGNED NULL,<br>    ADD COLUMN weight_used      integer UNSIGNED NULL;</pre><p>None of it looked dangerous and it caused zero observable problems. Then, on the day the pipeline actually crashed, a much smaller and completely unrelated migration landed on the same table: a new tracking column, inserted mid-table with AFTER. That’s what we assumed had triggered the failure.</p><h3>Investigation: ruling out the obvious</h3><p>Our first guess was positional drift. The AFTER clause had shifted column ordinals, and plenty of pipelines read by position (&quot;column 7 is always the price&quot;), so a mid-table insert shifts everything that follows. Checking our own reshaping code turned up a real bug of exactly that shape: our transformer was prepending internal metadata columns to the front of every row before writing to Hudi, which meant any positional mismatch downstream landed on the wrong column.</p><pre>// Before: metadata columns prepended, business columns shift<br>List&lt;String&gt; reordered = new ArrayList&lt;&gt;(metadataColumns);<br>reordered.addAll(businessColumns);</pre><pre>// After: metadata columns appended, business columns keep source order<br>List&lt;String&gt; reordered = new ArrayList&lt;&gt;(businessColumns);<br>reordered.addAll(metadataColumns);</pre><p>We fixed it, re-ran the pipeline, and the crash came right back, immediately. So we checked every layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ANtEB3fJw2MFphjJpjiIEQ.png" /></figure><h3>Root cause</h3><p>In MySQL, INT and INTEGER are exact synonyms, and no database treats them differently. Debezium, it turns out, does.</p><p>Streaming mode parses raw DDL text with an <strong>ANTLR</strong>-generated grammar, and the parser keeps whatever token the migration author literally typed, INTEGER or INT, verbatim. Deep in Debezium’s MySQL connector, a separate method then determines the schema type for each numeric column by matching on the <em>exact string</em> of that token.</p><pre>if (matches(typeName, &quot;INT UNSIGNED&quot;) || matches(typeName, &quot;INT UNSIGNED ZEROFILL&quot;)<br>        || matches(typeName, &quot;INT4 UNSIGNED&quot;) || matches(typeName, &quot;INT4 UNSIGNED ZEROFILL&quot;)) {<br>    return SchemaBuilder.int64();<br>}</pre><p>That migration used INTEGER UNSIGNED for weight_total and weight_used, but &quot;INTEGER UNSIGNED&quot; simply wasn&#39;t on that list. The spelling didn&#39;t match, so Debezium fell through to its default: int32 instead of int64. Snapshot mode doesn’t share this problem: it reads the same column fresh through JDBC, which normalizes the type name to INT UNSIGNED, allowing it to match and produce int64. Same column, same table, two different Avro types, depending only on which mode read it.</p><p>Our pipeline had run in streaming mode for years and never noticed. The situation changed only when we ran a snapshot to debug the positional-drift theory: it registered a new schema version with long, and every subsequent batch crashed.</p><p>What surprised us is that the snapshot registering the correct long schema did not fix anything going forward. That&#39;s the Schema Registry nuance from earlier: it&#39;s not something Debezium&#39;s CDC connector reads from, it&#39;s only something the connector writes to. The streaming connector had already built its own table schema from replaying db_history, the Kafka topic where it keeps a record of every DDL statement it has seen. It does not re-check the registry or MySQL on every batch. So even with a correct long schema now sitting in the registry, the streaming connector kept encoding total_weight and used_weight as int32 from its own stale cache, and every message it produced still collided with the schema the snapshot had just registered.</p><h3>The fix</h3><p>We checked the git history: the matcher was added in <strong>May 2017</strong> as part of <a href="https://issues.redhat.com/browse/DBZ-228">DBZ-228</a> (<a href="https://github.com/debezium/debezium/pull/240">PR #240</a>), an unrelated fix about MySQL unsigned integer handling, and INTEGER was never added to that list.</p><p>The fix is straightforward:</p><pre>if (matches(typeName, &quot;INT UNSIGNED&quot;) || matches(typeName, &quot;INT UNSIGNED ZEROFILL&quot;)<br>        || matches(typeName, &quot;INTEGER UNSIGNED&quot;) || matches(typeName, &quot;INTEGER UNSIGNED ZEROFILL&quot;)<br>        || matches(typeName, &quot;INT4 UNSIGNED&quot;) || matches(typeName, &quot;INT4 UNSIGNED ZEROFILL&quot;)) {<br>    return SchemaBuilder.int64();<br>}</pre><p>One catch we nearly missed: this matcher exists in <em>two</em> places, one for schema type resolution and one for byte conversion. Fixing only the schema side would have produced silently truncated data. We fixed both.</p><p>The fix was submitted and merged upstream in the Debezium repository:</p><ul><li><a href="https://github.com/debezium/dbz/issues/2172">DBZ-2172</a>, the bug report</li><li><a href="https://github.com/debezium/debezium/pull/7590">PR #7590</a>, the fix, merged</li><li>Debezium <a href="https://debezium.io/blog/2026/08/04/debezium-3-6-1-final-released/">release</a></li></ul><p>We considered a narrower fix: casting those two columns to int32 in our own pipeline. It would have been faster to ship, but it came with real problems of its own. Values above roughly 2.1 billion could get truncated, and streaming and snapshot would still disagree for anyone reading the same table a different way. We filed the issue and PR above instead: fixing it in Debezium means it stays fixed everywhere.</p><blockquote>Streaming mode had been treating INTEGER UNSIGNED as int32 for years, while snapshot mode treated the same column as int64. Nothing forced the two schemas to agree until we ran a snapshot, and that&#39;s when the mismatch finally surfaced.</blockquote><p><em>If you enjoy solving large-scale distributed systems problems, digging into subtle failures, and building systems for commerce at scale, join us at Blinkit Tech.</em><br><em>Reach out at </em><a href="http://techhiring@blinkit.com/"><em>techhiring@blinkit.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c98e8a80aa2" width="1" height="1" alt=""><hr><p><a href="https://lambda.blinkit.com/how-integer-and-int-produced-different-schemas-in-debezium-9c98e8a80aa2">How INTEGER and INT Produced Different Schemas in Debezium</a> was originally published in <a href="https://lambda.blinkit.com/">Lambda by Blinkit</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>