<?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 Vikas Singla on Medium]]></title>
        <description><![CDATA[Stories by Vikas Singla on Medium]]></description>
        <link>https://medium.com/@ksingla.vikas?source=rss-8c13a4ca1c13------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Kr0BA5T_gHcbMX0zPgTzhg.png</url>
            <title>Stories by Vikas Singla on Medium</title>
            <link>https://medium.com/@ksingla.vikas?source=rss-8c13a4ca1c13------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 00:39:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ksingla.vikas/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[Anatomy of an Active-Active, Asymmetric, Multi‑Region Atlas Cluster]]></title>
            <link>https://medium.com/@ksingla.vikas/anatomy-of-an-active-active-asymmetric-multi-region-atlas-cluster-bc0f2638591a?source=rss-8c13a4ca1c13------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc0f2638591a</guid>
            <category><![CDATA[multi-cloud-deployment]]></category>
            <category><![CDATA[active-active]]></category>
            <category><![CDATA[sharding]]></category>
            <category><![CDATA[multi-region-deployment]]></category>
            <category><![CDATA[mongodb-atlas]]></category>
            <dc:creator><![CDATA[Vikas Singla]]></dc:creator>
            <pubDate>Tue, 10 Feb 2026 09:25:05 GMT</pubDate>
            <atom:updated>2026-02-10T09:25:05.505Z</atom:updated>
            <content:encoded><![CDATA[<p>If you live in the world of latency, SLAs, and “this region just went down” war rooms, you’ve probably heard some version of:</p><blockquote>“We need <strong>active-active</strong> across regions and cloud providers, with <strong>HA and DR</strong>, but we also don’t want to pay for identical capacity everywhere.”</blockquote><p>That sentence hides a lot of architecture.</p><p>The <a href="https://github.com/kSinglaVikas/atlas-multi-region-active-sharding">atlas-multi-region-active-sharding</a> project is a concrete, runnable answer to that requirement. It’s an end‑to‑end, infrastructure-as-code blueprint for building a <strong>geo‑sharded, zone‑based, active-active</strong> Atlas deployment with <strong>asymmetric sharding</strong> across regions &amp; cloud providers:</p><ul><li>More capacity where your users actually are</li><li>Less capacity where traffic is lighter or DR‑oriented</li><li>Still a single logical cluster that stays online when an entire region goes dark</li></ul><p>This post steps back from the Terraform and .mongodb.js scripts and looks at what this deployment <em>means</em> architecturally – and why it’s a useful reference pattern for your own multi-region, multi-cloud strategy.</p><h3>The Reference Architecture at a Glance</h3><p>The repository we’ll use as our blueprint:</p><ul><li><strong>GitHub repo:</strong> atlas-multi-region-active-sharding</li><li><strong>Top-level README (intro):</strong> the same one you’re reading in raw form <a href="https://raw.githubusercontent.com/kSinglaVikas/atlas-multi-region-active-sharding/refs/heads/main/README.md">here</a></li><li><strong>Terraform deployment guide:</strong> terraform/README.md</li><li><strong>Sharding &amp; data load guide:</strong> data-load/README.md</li></ul><p>At a high level, the project provisions a <strong>MongoDB Atlas geo‑sharded cluster</strong> with:</p><ul><li><strong>Cluster type:</strong> GEOSHARDED</li><li><strong>Shards:</strong> 3 logical shards</li><li><strong>MumbaiZone:</strong> 2 shards (Shard 0, Shard 1)</li><li><strong>USZone:</strong> 1 shard (Shard 2)</li><li><strong>Shard key:</strong> { region: 1, email: 1 }</li><li><strong>Autoscaling:</strong> M30–M40 (configurable)</li><li><strong>Replication:</strong> multi‑region replica sets in multiple cloud provider</li></ul><p>Instead of imaginary region labels, the project uses real cloud region identifiers in the data model — for example:</p><ul><li>region: &quot;ap-south-1&quot; for traffic landing in <strong>AWS ap-south-1 (Mumbai)</strong></li><li>region: &quot;us-east-1&quot; for traffic landing in <strong>AWS us-east-1 (N. Virginia)</strong></li></ul><p>From the app’s point of view, this is <strong>one logical cluster</strong>. Under the hood, <strong>zone‑based sharding</strong> routes documents to the right shard(s) based on the region field.</p><pre>Geographic Data        Zone Tag       Target Shards<br>────────────────────────────────────────────────────<br>ap-south-1      →     MumbaiZone  →  Shard 0, Shard 1<br>us-east-1       →     USZone      →  Shard 2</pre><p>That mapping — plus how we size each shard set — is what turns a generic geo‑sharded cluster into a purposeful <strong>active-active, asymmetric deployment</strong>.</p><h3>Zone Segregation Diagram (Regions → Shards)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dmTYOFdKp7iLmqQJYoQXVg.png" /></figure><h3>Why Active-Active (and Not Just Active-Passive)?</h3><p><strong>Active-active</strong> here means:</p><ul><li>You have <strong>multiple write‑capable regions</strong></li><li>Each region serves its <strong>local traffic</strong> as the “primary experience”</li><li>If a region fails, you still have a path to serve <strong>read and write traffic</strong> via surviving shards/regions</li></ul><p>In a classic <strong>active‑passive</strong> DR setup:</p><ul><li>The “DR” region is mostly idle until failover</li><li>Capacity is duplicated but underutilized</li><li>Testing failover is risky because you’re flipping the main production endpoint</li></ul><p>By contrast, in this <strong>active-active, geo‑sharded design</strong>:</p><ul><li>Regions are <strong>first‑class citizens</strong> — each has data that is <em>authoritative</em> for its own geography</li><li><strong>DR</strong> is baked into the topology (replica sets across AZs; optionally across regions and cloud providers)</li><li>You gain both:<br><strong>Low latency</strong> for local users<br><strong>Resilience</strong> when a region or AZ fails</li></ul><p>If you want to go deeper into the concepts behind this:</p><ul><li><strong>Sharding basics:</strong> <a href="https://www.mongodb.com/docs/manual/sharding/">https://www.mongodb.com/docs/manual/sharding/</a></li><li><strong>Zone‑based sharding (tag aware):</strong> <a href="https://www.mongodb.com/docs/manual/core/zone-sharding/">https://www.mongodb.com/docs/manual/core/zone-sharding/</a></li><li><strong>Atlas global clusters (geo‑sharding in Atlas):</strong> <a href="https://www.mongodb.com/docs/atlas/global-clusters/">https://www.mongodb.com/docs/atlas/global-clusters/</a></li></ul><p>Each of those terms deserves a full article; here we’ll stay focused on how they come together in this specific architecture.</p><h3>Asymmetric Sharding: Capacity Where It Matters</h3><p>Most real workloads are not perfectly balanced across geographies:</p><ul><li>Maybe <strong>70–80%</strong> of traffic is from India (ap-south-1)</li><li><strong>us-east-1</strong> is important, but much smaller today</li><li>You still want <strong>DR</strong> and <strong>presence</strong> in both</li></ul><p>That’s where the <strong>asymmetric</strong> part comes in.</p><p>In the reference implementation:</p><ul><li><strong>MumbaiZone</strong> has <strong>two shards</strong> (Shard 0, Shard 1)</li><li><strong>USZone</strong> has <strong>one shard</strong> (Shard 2)</li></ul><p>This gives you:</p><ul><li><strong>More write and storage capacity</strong> in Mumbai</li><li><strong>Horizontal scale‑out headroom</strong> where you’re actually growing</li><li><strong>A leaner footprint</strong> in the US, while still supporting local reads/writes</li></ul><p>Because we shard on { region: 1, email: 1 }:</p><ul><li>All documents for region: &quot;ap-south-1&quot; naturally land in the <strong>MumbaiZone</strong> shards</li><li>All documents for region: &quot;us-east-1&quot; land in <strong>USZone</strong></li><li>Within a zone, the secondary key (email) helps distribute data and queries evenly across the zone’s shards</li></ul><p>You control the asymmetry simply by:</p><ul><li><strong>Adding/removing shards per zone</strong> (e.g., add Shard 3 to USZone once US adoption grows)</li><li><strong>Up/down‑sizing tiers</strong> per region via Terraform variables</li></ul><p>The data-load/sharding.mongodb.js and data-load/chunks.mongodb.js scripts in the repo let you:</p><ul><li>Create zones and associate them with <strong>shard ranges</strong></li><li>Inspect <strong>chunk distribution</strong> across shards to validate that your <strong>asymmetric capacity</strong> is actually being used as intended</li></ul><h3>Shard &amp; Chunk Segregation View</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*vE3ewBBKppz4sC7dYlfiew.png" /></figure><h3>How Reads and Writes Flow in an Active-Active Geo‑Sharded Cluster</h3><p>Let’s make it concrete.</p><h3>Query patterns and scatter‑gather</h3><p>Because the shard key is { region: 1, email: 1 }, query shape matters a lot for performance and targeting.</p><h4>1. Email‑only query — the scatter‑gather anti‑pattern</h4><p>Consider a query like:</p><pre>db.customers.find({ email: &quot;alice@example.com&quot; })</pre><p>This query does <strong>not</strong> include the shard key prefix (region). The router (mongos or the Atlas routing layer) has no way to know which shard owns this document, so it must:</p><ol><li><strong>Scatter</strong> the query to <em>all</em> shards</li><li><strong>Gather</strong> the results</li><li>Merge and return the final cursor to the application</li></ol><p>On a tiny cluster this is fine. On a busy, multi‑region deployment it becomes a tax on:</p><ul><li><strong>Latency</strong> — queries fan out across regions, so you pay for the slowest shard in the set</li><li><strong>Network</strong> — you’re burning cross‑region bandwidth for queries that could have been local</li><li><strong>CPU</strong> — every shard is doing work even though only one of them actually owns the data</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gUrZjaE8QTZcIY0JyEiBgQ.png" /></figure><blockquote><strong><em>Email‑only scatter‑gather</em></strong><em><br></em><em>explain(&quot;executionStats&quot;) screenshot show the scatter‑gather plan across all shards.</em></blockquote><h4>2. Region‑based query — targeted to the right shards</h4><p>Now compare that with queries that include region:</p><pre>// Target Mumbai traffic<br>db.customers.find({<br>  region: &quot;ap-south-1&quot;,<br>  email: &quot;alice@example.com&quot;<br>})</pre><pre>// Broader range scan within the Mumbai zone<br>db.customers.find({ region: &quot;ap-south-1&quot; })</pre><pre>// Similarly for US traffic<br>db.customers.find({ region: &quot;us-east-1&quot; })</pre><p>Here the predicate includes the shard key prefix (region) with concrete values like ap-south-1 and us-east-1. Atlas can now route the query <strong>directly</strong> to only the shards whose zones cover that region:</p><ul><li>ap-south-1 → MumbaiZone → Shard0 / Shard1</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*UegsZY_owbN_PuvsNGT0AA.png" /></figure><ul><li>us-east-1 → USZone → Shard2</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*nW856L8aetOz8Nk641fhag.png" /></figure><p>The result is a <strong>targeted</strong> plan instead of a full scatter‑gather. If you also include email, most queries become <strong>single‑shard</strong> operations (often a single chunk).</p><p>The rule of thumb is the same one you’ll see in MongoDB’s sharding best practices:</p><ul><li>Design access patterns so that the <strong>shard key (or its prefix)</strong> is almost always present in critical queries.</li><li>When that’s not possible, be very intentional about which queries you’re willing to let <strong>scatter</strong>.</li></ul><p>For more on shard keys and query routing, the official docs are worth a read:</p><ul><li><strong>Shard key selection:</strong> <a href="https://www.mongodb.com/docs/manual/core/sharding-shard-key/">https://www.mongodb.com/docs/manual/core/sharding-shard-key/</a></li><li><strong>Query routing in sharded clusters:</strong> <a href="https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/">https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/</a></li></ul><h3>Example 1: An Indian Customer Logs In From ap-south-1</h3><ol><li>The app connects via the <strong>single Atlas SRV connection string</strong>.</li><li>It writes a document like:</li></ol><pre>{   &quot;region&quot;: &quot;ap-south-1&quot;,   <br>    &quot;email&quot;: &quot;customer@example.com&quot;,<br>     &quot;profile&quot;: { /* ... */ } }</pre><p>3. Because the <strong>shard key</strong> begins with &quot;region&quot;: &quot;ap-south-1&quot; and the <strong>zone mapping</strong> says:</p><pre>ap-south-1 → MumbaiZone → Shard0, Shard1</pre><p>the write lands on <strong>one of the MumbaiZone shards</strong>.</p><p>4. Subsequent reads for this user:</p><ul><li>Are automatically <strong>routed to the same shard/zone</strong></li><li>Can be served by <strong>secondaries</strong> in that region (if you configure read preference accordingly)</li><li>Benefit from <strong>low, intra‑region latency</strong></li></ul><h3>Example 2: A US Customer in us-east-1</h3><p>Same flow, but:</p><ul><li>region: &quot;us-east-1&quot;</li><li>Routed to <strong>USZone → Shard2</strong></li><li>Reads and writes stay <strong>local to us-east-1</strong>, assuming you’ve pinned the app tier there</li></ul><p>Again, as long as you keep region in your queries, you avoid global scatter‑gather and keep most traffic local.</p><h3>Failures and DR</h3><p>If:</p><ul><li>One shard’s <strong>primary</strong> fails, the <strong>replica set</strong> elects a new primary in the same or another region (depending on your placement)</li><li>An entire <strong>region</strong> becomes unavailable, Secondaries in other regions becomes Primary</li></ul><p>Because the cluster is <strong>sharded by region</strong>, blast radius is reduced:</p><ul><li>Issues local to USZone don’t directly affect MumbaiZone and vice versa</li><li>Yet the global deployment still looks like a <strong>single logical database</strong> to your application</li></ul><p>For more on how replication and failover work:</p><ul><li><strong>Replica sets and HA:</strong> <a href="https://www.mongodb.com/docs/manual/replication/">https://www.mongodb.com/docs/manual/replication/</a></li></ul><h3>Multi-Region and Multi‑Cloud for HA and DR</h3><p>The geo‑sharded, zone‑based layer decides <strong>which shard</strong> owns which data. High availability and DR are delivered by the <strong>replica sets</strong> backing each shard:</p><ul><li>Each shard is a <strong>replica set</strong> spread across <strong>multiple AZs</strong> in its primary region</li><li>You can extend that pattern by:<br>Adding <strong>secondaries in another region</strong> (e.g., ap-south-1 primary, ap-southeast-1 secondary)<br>Or even <strong>secondaries in another cloud provider</strong> (e.g., AWS primary, Azure or GCP secondary) where networking and compliance allow</li></ul><p>Within Atlas, you do this by configuring:</p><ul><li><strong>Region &amp; cloud distribution</strong> of each replica set when defining the cluster</li><li><strong>Electable / read‑only nodes</strong> per region, depending on whether that region is for:<br><strong>Local read/write</strong> (active region)<br>Or primarily <strong>DR / read‑only analytics</strong></li></ul><p>Conceptually, you end up with patterns like:</p><ul><li><strong>Multi‑region, single‑cloud:</strong> multiple AWS regions (ap-south-1, ap-southeast-1, us-east-1, …), each with its own zone‑mapped shard capacity</li><li><strong>Multi‑cloud, multi‑region:<br></strong>MumbaiZone primarily in <strong>AWS ap-south-1</strong>, with a secondary in <strong>Azure Central India<br></strong>USZone primarily in <strong>GCP us-east1</strong>, with a secondary in <strong>AWS us-east-1</strong></li></ul><p>The <strong>geo‑sharding</strong> and <strong>zone sharding</strong> patterns work the same in both cases. The difference is simply <em>where</em> each replica set member lives.</p><p>For the official details:</p><ul><li><strong>Atlas multi‑cloud clusters:</strong> <a href="https://www.mongodb.com/docs/atlas/multi-cloud-clusters/">https://www.mongodb.com/docs/atlas/multi-cloud-clusters/</a></li></ul><h3>Key Terms</h3><p>For readers who are newer to MongoDB, here are the core concepts we’ve been using:</p><ul><li><strong>MongoDB Atlas</strong> — the fully managed MongoDB service with automation, backups, monitoring, and global distribution<br><a href="https://www.mongodb.com/atlas/database">https://www.mongodb.com/atlas/database</a></li><li><strong>Sharding</strong> — horizontally splitting a collection across multiple servers for scale and throughput<br><a href="https://www.mongodb.com/docs/manual/sharding/">https://www.mongodb.com/docs/manual/sharding/</a></li><li><strong>Zone sharding (tag-aware sharding)</strong> — assign <strong>zones</strong> (tags) to shards and <strong>range filters</strong> to those zones so specific data ranges live only on specific shards (e.g., region: &quot;ap-south-1&quot; on Mumbai shards)<br><a href="https://www.mongodb.com/docs/manual/core/zone-sharding/">https://www.mongodb.com/docs/manual/core/zone-sharding/</a></li><li><strong>Geo‑sharded / global clusters in Atlas</strong> — opinionated Atlas configuration on top of zone sharding for <strong>location‑aware</strong> routing and data residency<br><a href="https://www.mongodb.com/docs/atlas/global-clusters/">https://www.mongodb.com/docs/atlas/global-clusters/</a></li><li><strong>Replica set</strong> — a group of mongod processes that keep the same data set, providing <strong>redundancy and automatic failover<br></strong><a href="https://www.mongodb.com/docs/manual/replication/">https://www.mongodb.com/docs/manual/replication/</a></li><li><strong>Multi‑cloud / multi‑region clusters in Atlas</strong> — clusters that span multiple cloud providers and/or regions for higher resilience and regulatory fit<br><a href="https://www.mongodb.com/docs/atlas/multi-cloud-clusters/">https://www.mongodb.com/docs/atlas/multi-cloud-clusters/</a></li></ul><p>Each of these is covered in depth in the official MongoDB documentation; this blog is deliberately opinionated and example‑driven rather than exhaustive.</p><h3>Getting Hands-On With the Repo</h3><p>If you want to move from architecture diagrams to running code, the repository is structured to keep that path clear:</p><ul><li><strong>Terraform IaC</strong> (cluster, project, networking, etc.):<br>terraform/README.md</li><li><strong>Sharding config &amp; data load</strong> (zones, shard key, test data, distribution checks):<br>data-load/README.md</li></ul><p>A typical flow looks like:</p><ol><li><strong>Deploy the Atlas cluster</strong> using the Terraform module in terraform/.</li><li><strong>Configure zone‑based sharding</strong> and apply { region: 1, email: 1 } as the shard key using data-load/sharding.mongodb.js.</li><li><strong>Load synthetic customer data</strong> with CustomerSingleView.json via mgeneratejs or your tool of choice.</li><li><strong>Inspect chunk and zone distribution</strong> with data-load/chunks.mongodb.js.</li><li><strong>Capture query explain plans</strong>:</li></ol><ul><li>Run an <strong>email‑only</strong> query and save the explain(&quot;executionStats&quot;) output as a screenshot for the scatter‑gather example.</li><li>Run <strong>region‑aware</strong> queries (for both ap-south-1 and us-east-1) and capture the targeted explain plans.</li></ul><p><strong>6. Point a sample application</strong> at the cluster and validate:</p><ul><li>Latency from <strong>India</strong> vs <strong>US</strong></li><li>Data locality by region</li><li>Behaviour during node/region failover tests</li></ul><p>The repo is intentionally small and focused, so you can clone it, deploy, and then adapt:</p><ul><li>Change <strong>regions</strong> to match your own footprint (e.g., add eu-west-1 for Europe)</li><li>Adjust the <strong>number and size of shards</strong> per zone</li><li>Evolve the <strong>shard key</strong> if your access patterns differ</li></ul><h3>Scaling Further: More Regions, More Clouds</h3><p>The pattern in this project is deliberately minimal — <strong>two regions, three shards, two zones</strong> — but it’s designed to scale.</p><p>Some natural next steps:</p><ul><li><strong>Add more regions<br></strong>Introduce a EUZone mapped to eu-west-1, backed by its own shard or shard pair.<br>Extend MumbaiZone to also cover ap-southeast-1 if your Asia traffic spreads out.</li><li><strong>Spread shards across multiple cloud providers<br></strong>Keep MumbaiZone primaries in <strong>AWS ap-south-1</strong>, but add secondaries in <strong>Azure Central India</strong> for DR and regulatory diversity.</li><li>Move USZone to a different provider (e.g., <strong>GCP us-east1</strong>) while still keeping the logical cluster unified in Atlas.</li><li><strong>Evolve the shard key and zones as the business changes</strong></li><li>Start with region + email for a customer‑centric workload.</li><li>If you later need per‑tenant isolation, add a tenantId prefix or create separate geo‑sharded collections per tenant.</li></ul><p>The crucial thing is that you don’t have to redesign everything when you add a new region or provider:</p><ul><li>You <strong>add a zone</strong> and map new <strong>region values</strong> (e.g., &quot;eu-west-1&quot;) to it.</li><li>You <strong>add shards and replica set members</strong> in the right regions/clouds.</li><li>Your application keeps using the same <strong>SRV connection string</strong> and the same <strong>query patterns</strong>, especially region‑aware ones.</li></ul><h3>Beyond the Blueprint</h3><p>The atlas-multi-region-active-sharding project isn’t just an IaC sample; it’s a <strong>reference implementation</strong> for a modern, opinionated pattern:</p><ul><li><strong>Active-active</strong>: multiple regions can serve as first‑class read/write endpoints</li><li><strong>Asymmetric</strong>: capacity and cost are weighted towards actual usage</li><li><strong>Multi‑region / multi‑cloud HA &amp; DR</strong>: replica sets and zones span failure domains without fragmenting your data model</li></ul><p>From here, you can extend the pattern to:</p><ul><li>Add a <strong>third region</strong> (e.g., eu-west-1) with its own zone (EUZone) and shard capacity</li><li>Introduce a <strong>DR‑only region</strong> with read‑only nodes that can be promoted during disaster scenarios</li><li>Layer on <strong>Atlas Search</strong>, <strong>Vector Search</strong>, or <strong>change streams</strong> to support richer workloads close to where your users are, and apply the same zoning pattern across additional regions and cloud providers by defining new zones and shard capacity there</li></ul><p>Start with the repo, run it end‑to‑end, and then reshape it around your own geography, SLAs, and cost envelope. The primitives — <strong>zones, shards, replica sets, regions, and cloud providers</strong> — are the same. The architecture is yours to tune.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc0f2638591a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Anatomy of a Modern Streaming Pipeline: From Postgres Transactions to Mongo Documents.]]></title>
            <link>https://medium.com/@ksingla.vikas/anatomy-of-a-modern-streaming-pipeline-from-postgres-transactions-to-mongo-documents-23e83894a2f0?source=rss-8c13a4ca1c13------2</link>
            <guid isPermaLink="false">https://medium.com/p/23e83894a2f0</guid>
            <category><![CDATA[modernization]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[apache-flink]]></category>
            <category><![CDATA[cqrs]]></category>
            <dc:creator><![CDATA[Vikas Singla]]></dc:creator>
            <pubDate>Tue, 25 Nov 2025 08:32:05 GMT</pubDate>
            <atom:updated>2025-11-25T08:32:05.671Z</atom:updated>
            <content:encoded><![CDATA[<p>If you inhabit the data engineering ecosystem, you have likely encountered the requirement to stream data from a transactional relational database to a document store. It is a classic pattern: taking rigid, normalized rows from Postgres and transforming them into flexible, JSON-like documents in MongoDB.</p><p>The <a href="https://github.com/kSinglaVikas/flink_streaming_pg_mongo">`flink_streaming_pg_mongo` repository</a> provides an excellent, hands-on implementation of this pipeline. The companion <a href="https://github.com/kSinglaVikas/flink_streaming_pg_mongo/blob/main/README.md">README</a> covers the “how-to” in great detail, walking through the setup of Debezium, Flink, and the necessary sinks.</p><p>However, I want to step back from the configuration files and talk about the <strong>architectural significance</strong> of this setup. This isn’t just a data pipe; it is a reference implementation for two critical modern patterns: <strong>Command Query Responsibility Segregation (CQRS)</strong> and the <strong>Operational Data Lake (ODL)</strong>.</p><h3>The System as a CQRS Implementation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*TDN8moCVSjrh2kNJo8AtPw.png" /></figure><p><a href="https://martinfowler.com/bliki/CQRS.html">CQRS</a> is often discussed in the context of complex microservices, but it applies perfectly here. The core principle is simple: <strong>separate the model used for updating information (Command) from the model used for reading information (Query).</strong></p><p>In a traditional monolith, you might query the same Postgres tables that you write to. As scale increases, complex analytical queries start locking rows, slowing down user transactions. The `flink_streaming_pg_mongo` project decouples these concerns entirely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ynT2fST6d5LXFGGcZgAhw.png" /></figure><p>In this architecture:</p><ul><li><strong>The Command Side (Postgres):</strong> Remains pure. It is normalized (3NF) to ensure consistency and speed up writes. It doesn’t care about how data is viewed on a dashboard.</li><li><strong>The Query Side (MongoDB):</strong> Is derivative. It can be denormalized. If your application needs a “User Summary” view, Flink can pre-aggregate that data into a single MongoDB document. When the user loads their dashboard, it’s a single, lightning-fast O(1) document fetch.</li></ul><h3>The Operational Data Lake (ODL)</h3><p>The second lens through which to view this project is that of the <strong>Operational Data Lake</strong>. Unlike a traditional Data Warehouse (which is often updated batch-nightly and used for historical reporting), an ODL is updated in near real-time and supports operational applications.</p><blockquote>“An ODL bridges the gap between the transactional application and the analytical warehouse. It allows for ‘in-the-moment’ decision making.”</blockquote><p>By using Flink to stream changes immediately into MongoDB, you are creating a data store that is fresh enough to trigger alerts, update live recommendations, or feed customer-facing APIs. The `flink_streaming_pg_mongo` repo demonstrates exactly how to lower the latency from “data creation” to “data availability” to mere milliseconds.</p><h3>Why This Matters</h3><p>Adopting this pattern solves three expensive problems:</p><ol><li><strong>Performance Isolation:</strong> Your analytics team can hammer the MongoDB instance with complex aggregations without ever degrading the performance of the main Postgres application database.</li><li><strong>Schema Evolution:</strong> Changing the read model (e.g., adding a field to a dashboard) doesn’t require a migration on the write database. You simply adjust the Flink job or the MongoDB view.</li><li><strong>Resilience:</strong> Flink provides stateful fault tolerance. If MongoDB goes down for maintenance, Flink buffers the stream. When Mongo returns, Flink replays the missed events, ensuring eventual consistency without data loss.</li></ol><h3>Start Building</h3><p>The concepts are theoretical, but the code is ready to run. Use the repository below as your boilerplate for a modern, scalable data platform.</p><p><a href="https://github.com/kSinglaVikas/flink_streaming_pg_mongo"><strong>View GitHub Repo</strong></a></p><p><a href="https://github.com/kSinglaVikas/flink_streaming_pg_mongo/blob/main/README.md"><strong>Read Implementation Guide</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23e83894a2f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>