<?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"><channel><title><![CDATA[Distributed by Aadinir]]></title><description><![CDATA[Distributed by Aadinir]]></description><link>https://aadinir.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 07 Nov 2026 10:04:29 GMT</lastBuildDate><atom:link href="https://aadinir.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[The Database Anti-Pattern That Accidentally Explains Distributed AI Training]]></title><description><![CDATA[If you propose a synchronous multi-leader replication architecture in a system design interview, you better have a really good reason for it. Why? Because…]]></description><link>https://aadinir.hashnode.dev/the-database-anti-pattern-that-accidentally-explains-distributed-ai-training</link><guid isPermaLink="true">https://aadinir.hashnode.dev/the-database-anti-pattern-that-accidentally-explains-distributed-ai-training</guid><dc:creator><![CDATA[Aadithya niranjan]]></dc:creator><pubDate>Mon, 26 Oct 2026 20:12:14 GMT</pubDate><content:encoded><![CDATA[<p>If you propose a synchronous multi-leader replication architecture in a system design interview, you better have a really good reason for it.</p>
<p>Why? Because coordinating writes across multiple nodes can get ridiculously complicated. You have conflicting updates, network latency, consistency guarantees, and a whole lot of edge cases that can turn a seemingly simple architecture into an operational nightmare.</p>
<p>But here's the funny part.</p>
<p>Some of the same ideas that make distributed systems engineers nervous about coordination are helping researchers solve one of the biggest problems in AI training: <strong>how do you train massive models across geographically distributed hardware without forcing everything to communicate constantly?</strong></p>
<p>I stumbled upon this connection while reading about database replication. I was deep in the weeds of multi-leader systems, trying to understand why an architecture that looks so intuitive on paper can become so painful in production.</p>
<p>And I kept thinking: surely there's a situation where letting independent nodes make progress and coordinating them less frequently is actually the right move?</p>
<p>That's when I stumbled upon a paper from Google DeepMind called <a href="https://arxiv.org/abs/2311.08105">DiLoCo: Distributed Low-Communication Training of Language Models</a>.</p>
<p>And later, I found its 2026 follow-up, <a href="https://arxiv.org/abs/2604.21428">Decoupled DiLoCo</a>.</p>
<p>Ngl, this was one of those moments where two completely different areas of computer science suddenly started making sense together.</p>
<p>So let's unpack it. No crazy AI prerequisites needed.</p>
<h2>1. First, why is multi-leader replication so complicated?</h2>
<p>Let's say you're building a globally distributed database.</p>
<p>You have one data center in India and another in Europe. Instead of routing every write to a single leader, you allow both data centers to accept writes locally.</p>
<p>Sounds great, right?</p>
<p>Users get lower write latency, and your application doesn't have to depend on a single geographical location to accept updates.</p>
<p>But now imagine both data centers update the same record at roughly the same time.</p>
<p>What happens?</p>
<p>You need a replication protocol, a conflict-resolution strategy, and clearly defined consistency guarantees. If the network goes down, the two locations might continue accepting writes without immediately seeing each other's changes.When connectivity returns, you need to reconcile those changes according to your system's rules.And if you try to synchronously coordinate every write across geographically distant nodes, network latency can become a serious bottleneck.</p>
<p>That's <strong>why multi-leader replication isn't a free performance upgrade. It introduces trade-offs that you need to understand before choosing it.</strong></p>
<p>The <strong>important distinction is that multi-leader replication isn't inherently bad. It's simply a design with costs that might not be worth paying for your particular workload.</strong></p>
<p>But here's the idea I couldn't stop thinking about:</p>
<p><strong>What if independent components could make meaningful progress locally and only coordinate globally when they actually needed to?</strong></p>
<p>Turns out, that's a pretty interesting question to ask about AI training.</p>
<h2>2. Why does training an AI model require so much coordination?</h2>
<p>Let's say you're training a neural network using thousands of GPUs.</p>
<p>One common approach is <strong>data parallelism</strong>.</p>
<p>Each GPU maintains a replica of the model and processes a different portion of the training data. During backpropagation, each worker calculates gradients that describe how the model parameters should change.</p>
<p>Those gradients need to be combined so the workers can make consistent updates according to the training algorithm.</p>
<p>In standard PyTorch DistributedDataParallel, this synchronization uses a collective operation called <code>all_reduce</code>.</p>
<p>At a high level, all-reduce allows participating workers to combine their values, commonly by summing them, and make the result available to every participant. In DDP, gradient averaging is a central part of this process.</p>
<p>The important thing is that the workers coordinate their updates rather than independently changing the model and hoping everything works out.</p>
<p>And for a tightly coupled training cluster, this works extremely well.</p>
<p>But imagine taking that same communication pattern and spreading the workers across continents.</p>
<p>Now you're dealing with WAN latency, limited bandwidth, network disruptions, and machines that might not all perform at the same speed.</p>
<p>The problem isn't just the amount of data being transferred.</p>
<p>It's <strong>how frequently the system needs to communicate before useful computation can continue.</strong></p>
<p>If one worker becomes a straggler at a synchronization point, other workers may have to wait. If a worker fails, the distributed job might require recovery before it can proceed.</p>
<p>This is where the a<strong>nalogy to distributed systems becomes interesting.</strong></p>
<p>In databases, coordination can become expensive when independent nodes need to reconcile changes frequently.</p>
<p>In distributed training, coordination can become expensive when independent workers need to exchange information frequently.</p>
<p>They're not the same problem, but they share an important engineering question:</p>
<p>How much coordination do we actually need?</p>
<h2>3. Enter DiLoCo: what if we communicated less often?</h2>
<p>In November 2023, Google DeepMind published a paper called DiLoCo, short for Distributed Low-Communication.</p>
<p>The basic idea is surprisingly intuitive.</p>
<p>Instead of requiring geographically distributed workers to synchronize their model updates after every local optimization step, let them train locally for many steps before communicating globally.</p>
<p>Think of each group of GPUs as an island.</p>
<p>Each island has enough local infrastructure to perform its training efficiently. Communication within an island can be relatively fast, while communication between islands might be slow or expensive.</p>
<p>Rather than constantly coordinating across the WAN, each island performs a series of local optimization steps and periodically contributes an update to the broader training process.</p>
<p>In the original DiLoCo algorithm, the inner optimizer is AdamW, while the outer optimizer uses Nesterov momentum.</p>
<p>The number of local steps between outer updates is configurable. The paper investigates settings with hundreds of local steps, including 500-step intervals.</p>
<p>Here's the clever part.</p>
<p>The system doesn't need to send every individual update generated during those local steps. Instead, it can communicate information about how the model parameters have changed over the local training phase.</p>
<p>Let's make that concrete.</p>
<p>Suppose the model parameters at the beginning of a local training phase are:</p>
<p>θ_start</p>
<p>After many local optimization steps, the learner has new parameters:</p>
<p>θ_local</p>
<p>The parameter displacement is:</p>
<p>Δθ = θ_local - θ_start</p>
<p>DiLoCo uses a pseudo-gradient based on this parameter difference, with the sign convention defined by the algorithm.</p>
<p>That pseudo-gradient summarizes the effect of multiple local optimization steps. The outer optimizer then uses the aggregated information to update the shared model state.</p>
<p>In other words, instead of constantly communicating the intermediate results of local training, the system can communicate a summary of the progress made over a much longer interval.</p>
<p>This is related to <strong>federated averaging</strong>, but DiLoCo adapts the idea for large-scale language-model training using its particular inner and outer optimization scheme.</p>
<p>And the results were pretty interesting.</p>
<p>On the C4 dataset, the researchers reported that DiLoCo with eight workers performed comparably to fully synchronous optimization while communicating <strong>500 times less</strong> in their experiments.</p>
<p>Let that sink in.</p>
<p>A distributed training approach that communicates dramatically less can still achieve comparable model quality under the conditions tested.</p>
<p>That doesn't mean every AI model can be trained with 500 times less communication. It's a result from a particular experimental setup.</p>
<p>But it demonstrates something important:</p>
<p><strong>Frequent global synchronization isn't always necessary for effective distributed training.</strong></p>
<p>And if you're thinking about training models across distant data centers, that changes the economics of the problem.</p>
<p><a href="https://arxiv.org/abs/2311.08105">Read the original DiLoCo paper.</a></p>
<h2>4. But wait. What happens when the islands don't cooperate?</h2>
<p>At this point, you might be thinking that DiLoCo solves the communication problem.</p>
<p>Well, it addresses a major part of it. But reducing communication frequency isn't the same as eliminating synchronization dependencies.</p>
<p>Imagine you have several training islands spread across different data centers.</p>
<p>One island has newer hardware and completes its local work quickly.</p>
<p>Another has older hardware and takes considerably longer.</p>
<p>A third experiences a hardware failure.</p>
<p>Even if the islands communicate less frequently, a training architecture that still requires all participants to reach the same synchronization point can suffer from stragglers and failures.</p>
<p>And this is where the 2026 follow-up becomes particularly interesting.</p>
<p>In April 2026, Google DeepMind published <a href="https://arxiv.org/abs/2604.21428">Decoupled DiLoCo</a>, extending the approach to address these coordination and resilience problems.</p>
<p>The central idea is to decouple the learners from the global synchronization process.</p>
<p>Instead of treating the entire training job as one tightly synchronized unit, the system lets separate learner units perform local optimization and communicate asynchronously with a central synchronizer.</p>
<p>Let's break that down.</p>
<h2>5. Decoupled DiLoCo: stop waiting for everyone</h2>
<p>Imagine five training islands.</p>
<p>In a tightly synchronized system, a global synchronization point can force faster participants to wait for slower ones.</p>
<p>Now imagine that one island temporarily goes offline.</p>
<p>Depending on the training architecture and recovery mechanisms, the failure can disrupt the progress of the broader job.</p>
<p>Decoupled DiLoCo changes this coordination model.</p>
<p>Learners perform their local training and send parameter fragments to a central synchronizer asynchronously. The synchronizer is responsible for aggregating updates and producing new global model state.</p>
<p>The key difference is that the system doesn't require every learner to be ready at precisely the same moment for every global update.</p>
<p>The paper describes several mechanisms that make this possible.</p>
<p><strong>Minimum quorum</strong></p>
<p>The synchronizer can proceed when enough learner contributions are available, rather than requiring every learner to report back.</p>
<p>This helps prevent one slow or unavailable learner from blocking the entire process.</p>
<p><strong>Adaptive grace window</strong></p>
<p>The synchronizer can balance waiting for additional contributions against making progress with the updates already received.</p>
<p>Waiting longer might allow more learners to contribute. Waiting less can reduce the delay caused by stragglers.</p>
<p><strong>Dynamic token-weighted merging</strong></p>
<p>Learners can contribute different amounts of training work. The system accounts for differences in the number of tokens processed when merging updates.</p>
<p>This matters because treating every learner's contribution identically isn't necessarily appropriate when their workloads differ.</p>
<p>Together, these mechanisms make global coordination more flexible.</p>
<p>Notice what's happening here.</p>
<p>We're no longer talking only about reducing how often communication occurs. We're also changing the dependency between local computation and global coordination.</p>
<p>That's a much more substantial architectural change.</p>
<p>And it's the part I find particularly interesting as a software engineer.</p>
<p>We're separating the work that needs to happen locally from the work that needs to happen globally, then designing the coordination mechanism so that delays and failures in one part of the system don't automatically stall every other part.</p>
<p>Of course, asynchronous communication doesn't eliminate all synchronization. Learners still have local dependencies, and the synchronizer still needs to aggregate updates according to the algorithm.</p>
<p>The goal is to remove unnecessary global lock-step dependencies, not to pretend coordination no longer exists.</p>
<h2>6. Okay, but how do you transfer a massive model over a WAN?</h2>
<p>Let's do some napkin math.</p>
<p>Suppose a model has one trillion parameters, with each parameter represented using 16 bits.</p>
<p>That's two bytes per parameter.</p>
<p>So the raw parameter storage is:</p>
<p>1 Trillion parameters × 2 bytes = 2 Terabytes (TB)</p>
<p>That's <strong>2 TB of raw parameter data</strong>, using decimal units.</p>
<p>Now imagine transferring that entire payload over a 2 Gbps network connection.</p>
<p>Since one byte is eight bits:</p>
<p>2 Terabytes × 8 bits = 16,000 Gigabits (Gb)</p>
<p>The ideal transfer time would be:</p>
<p>16,000 Gb ÷ 2 Gbps = 8,000 seconds</p>
<p>That's approximately <strong>2 hours and 13 minutes</strong>.</p>
<p>And that's before accounting for protocol overhead, congestion, or other real-world limitations.</p>
<p>Obviously, you don't want your training architecture to depend on repeatedly transferring the entire model across continents at that rate.</p>
<p>But there's an important distinction here.</p>
<p><strong>DiLoCo doesn't solve this problem merely by splitting the model into shards. It reduces how frequently distributed learners need to communicate globally.</strong></p>
<p>Sharding can distribute model state across devices, but it doesn't automatically reduce the total number of bytes required for a given transfer.</p>
<p>The bigger architectural win comes from doing more computation locally between global updates.</p>
<p>Decoupled DiLoCo adds asynchronous communication and a synchronization mechanism that doesn't require every learner to participate in every update.</p>
<p>And we have an actual result to look at here, rather than relying only on hypothetical calculations.</p>
<p>In its April 2026 technical report, Google DeepMind described training a 12-billion-parameter model across four separate US regions using WAN connectivity of approximately 2–5 Gbps.</p>
<p>The researchers reported that this approach completed the training run more than 20 times faster than conventional synchronization methods in their comparison.</p>
<p>They also reported a bandwidth comparison across eight data centers:</p>
<ul>
<li>Conventional data-parallel training: 198 Gbps.</li>
<li>Decoupled DiLoCo: 0.84 Gbps.</li>
</ul>
<p>Those figures belong to the specific configurations and experiments described by the researchers; they're not universal bandwidth requirements.</p>
<p>Still, they demonstrate why this architecture is worth paying attention to.</p>
<p>The point isn't that network bandwidth has magically stopped mattering.</p>
<p>It's that <strong>changing the communication pattern can make a previously impractical network topology viable for training.</strong></p>
<p><a href="https://deepmind.google/blog/decoupled-diloco/">Source: Google DeepMind's Decoupled DiLoCo announcement and experimental results.</a></p>
<h2>7. The other interesting consequence: heterogeneous hardware</h2>
<p>There's another constraint worth discussing.</p>
<p>Large-scale training systems often benefit from homogeneous hardware because devices with different performance characteristics can complicate scheduling and synchronization.</p>
<p>If one group of devices is much faster than another, tightly synchronized execution can waste time waiting for slower participants.</p>
<p>Now consider the architecture we've been discussing.</p>
<p>Independent learner units can make local progress without requiring every other unit to complete the same amount of work at the same time.</p>
<p>The synchronizer can then account for differences in contributions when merging updates.</p>
<p>That creates an opportunity to combine hardware that might otherwise be difficult to use efficiently in a single tightly synchronized training job.</p>
<p>Google DeepMind reports experiments combining different hardware generations, including TPU v6e and TPU v5p, while maintaining comparable model performance to training on a single hardware type.</p>
<p>That's an important result.</p>
<p>It suggests that training infrastructure doesn't always need to be built around one perfectly uniform pool of accelerators.</p>
<p>Instead, a system can potentially make useful progress with resources distributed across different locations and hardware generations.</p>
<p>Of course, heterogeneous hardware introduces its own challenges: different compute speeds, memory capacities, communication characteristics, and scheduling requirements.</p>
<p>The architecture doesn't make those problems disappear.</p>
<p>It changes how much those differences constrain the entire training job.</p>
<p>And that distinction is huge.</p>
<h2>8. So is this basically multi-leader replication for AI?</h2>
<p>Not exactly.</p>
<p>And this is where I think the comparison becomes more interesting than the original analogy.</p>
<p>In a multi-leader database, multiple nodes accept application writes and replicate changes. Concurrent writes can create conflicts, and the replication protocol determines how those conflicts and consistency requirements are handled.</p>
<p>In DiLoCo, learners perform local optimization steps and periodically contribute parameter updates to a shared training process.</p>
<p>In Decoupled DiLoCo, the learners can communicate asynchronously with a synchronizer that aggregates their contributions.</p>
<p>These systems have different correctness requirements and different mechanisms.</p>
<p>A database might need to preserve a strict invariant for every committed transaction. A training algorithm can sometimes tolerate delayed or approximate updates, provided the resulting optimization remains effective.</p>
<p>So we shouldn't claim that DiLoCo is literally a multi-leader database architecture.</p>
<p>But the connection is still useful.</p>
<p>Both systems force us to think about the cost of coordination, the degree of independence we can allow between components, and what happens when parts of a distributed system become slow or unavailable.</p>
<p>And both show why the answer isn't always to synchronize everything as frequently as possible.</p>
<p><strong>Sometimes the better approach is to identify which operations genuinely require coordination, let everything else progress independently, and design a robust mechanism for combining the results.</strong></p>
<p>That is a distributed systems problem, regardless of whether the state being coordinated is a database record or a neural network's parameters.</p>
<h2>9. What I took away from this</h2>
<p>When I started reading about multi-leader replication, I was mostly focused on the things that could go wrong.</p>
<p><strong>Conflicting writes. Replication lag. Consistency guarantees. Network partitions.</strong></p>
<p>And that's fair. Those are real problems.</p>
<p>But looking at DiLoCo and Decoupled DiLoCo made me think about a different question.</p>
<p>Instead of asking how we can synchronize every component more efficiently, what if we first asked whether every component needs to synchronize that frequently at all?</p>
<p>That question leads to a different way of designing distributed systems.</p>
<p>In databases, the answer depends on the application's consistency requirements and workload.</p>
<p>In AI training, the answer depends on the optimization algorithm, communication costs, model quality, and failure model.</p>
<p>The solutions aren't interchangeable. But the underlying engineering instinct is surprisingly similar.</p>
<p><strong>Don't pay the cost of global coordination unless the system actually needs it.</strong></p>
<p>And if you can safely reduce that dependency, you might be able to build systems that are cheaper to operate, more resilient to failures, and capable of using resources that were previously too difficult to combine.</p>
<p>That's what makes these papers interesting to me.</p>
<p>Not that an infamous database anti-pattern somehow became the secret foundation of AI.</p>
<p>It's that a question I first encountered while reading about database replication led me to a different way of thinking about distributed computation.</p>
<p>And honestly, that's one of the best parts of learning distributed systems.</p>
<p>Sometimes the most useful insight isn't a new algorithm or a new technology.</p>
<p>It's recognizing the same fundamental trade-off appearing in two completely different places.</p>
<hr />
<p><strong>P.S.</strong> If you want to explore the research yourself, start here:</p>
<ul>
<li><a href="https://arxiv.org/abs/2311.08105">DiLoCo: Distributed Low-Communication Training of Language Models (2023)</a></li>
<li><a href="https://arxiv.org/abs/2604.21428">Decoupled DiLoCo: Resilient Distributed Pre-training (2026)</a></li>
<li><a href="https://deepmind.google/blog/decoupled-diloco/">Google DeepMind's explanation of Decoupled DiLoCo and its experimental results</a></li>
</ul>
<p>I'm considering writing a separate post on the optimization side of this, especially how AdamW, pseudo-gradients, and Nesterov momentum fit together. That's a rabbit hole of its own.</p>
]]></content:encoded></item><item><title><![CDATA[The Underrated Engineering Behind Rating Systems]]></title><description><![CDATA[Learn how to design a highly available, low-latency rating system using sharding, consistent hashing, caching, and pre-materialized views at scale.]]></description><link>https://aadinir.hashnode.dev/the-underrated-engineering-behind-rating-systems</link><guid isPermaLink="true">https://aadinir.hashnode.dev/the-underrated-engineering-behind-rating-systems</guid><category><![CDATA[System Design]]></category><category><![CDATA[distributed systems]]></category><category><![CDATA[scalability]]></category><category><![CDATA[caching]]></category><category><![CDATA[backend]]></category><dc:creator><![CDATA[Aadithya niranjan]]></dc:creator><pubDate>Sat, 31 Jan 2026 09:06:37 GMT</pubDate><content:encoded><![CDATA[<p>I believe the rating section in most applications such as (Bookings.com, Amazon, Uber) is highly underrated. Most people see it as straightforward, but capturing this information at scale can be both challenging and frustrating. Many business products especially service-based applications rely heavily on ratings, but making this system coherent is strenuous.</p>
<p><strong>Why is this important?</strong> Consumer decisions are often driven by the quality of service, which is reflected in these ratings. From a technical perspective, this system must be highly available and low-latency. To talk numbers: let’s aim for a <strong>P99 of 50ms</strong> with peak traffic of <strong>10k RPS</strong> (Requests Per Second).</p>
<p>To accommodate this, we need an efficient caching mechanism and <strong>pre-materialized views</strong> on a relational DB (meaning all necessary joins are performed beforehand).</p>
<p><strong>Calculating the Scale</strong> Imagine we have 500 million reviews in total across all products. If each review is roughly 2KB, we are looking at <strong>1TB of data</strong>. While 1TB isn't massive by modern standards, hitting a single-node PostgreSQL or MongoDB instance with 10k GET requests per second would likely lead to a system crash. To solve this, we shard the database. Imagine 5 master nodes, each with 2 replicas—giving us 5 write nodes and 10 read replicas. To ensure <strong>High Availability (HA)</strong>, these replicas should be placed in different Availability Zones (AZ) so that an infra failure in one zone doesn't impact the business.</p>
<p><strong>The Routing Problem</strong> How does the system know which DB node holds User A’s data? A naive approach is a simple hash function using a deterministic number to route requests. However, in large systems, cost and scalability are concerns. If your user base grows or shrinks by 40%, a fixed hash function is hard to scale because it requires massive data re-sharding.</p>
<p>This is where <strong>Consistent Hashing</strong> comes in. Avoiding the jargon: instead of a direct mapping, we use a "circular" range (the hash ring). Imagine a loop from 0 to 100. If you have two nodes, one might cover 0–50 and the other 50–100. If a request hash is 26, it goes to the first node. If you need to add a third node (e.g., at 75), you only need to move the data falling between 50 and 75. In the big picture, the amount of data moved is minimized, which is a huge win for system stability.</p>
<p>Even with efficient sharding, we have to consider "Hot Keys." Imagine a major product launch where a single item's reviews are fetched redundantly millions of times. Even with sufficient read replicas, every database operation adds latency and puts a load on your disk I/O.</p>
<p>Caching helps mitigate this issue. Using a <strong>CDN</strong> for static content or <strong>Redis</strong> for frequently accessed review data allows you to serve these requests from memory rather than hitting the database. This drastically reduces the load on your primary storage and ensures that a single popular product doesn't bring down your entire sharded architecture.</p>
<p><strong>Conclusion</strong> A combination of consistent hashing, smart caching, and distributed data can solve the majority of scaling headaches. Follow for more—I am Aadinir.</p>
]]></content:encoded></item></channel></rss>