Chapter 17

Our Global Brain: Designing the Dukaan Edge Network

Subhash Choudhary · 17 min read

We had declared war on latency. Our mission was to build an e-commerce platform that was not just fast, but instantly fast, for every user on Earth. We knew the theory was sound: we had to move our servers closer to our users.

But this was no longer about adding a simple CDN for images. This was about moving our entire storefront application-the compute, the logic, and the database itself-to the edge. It was the most ambitious, complex, and audacious engineering project we had ever undertaken. It was our moonshot.

Part 1: The Whiteboard and the Magic IP Address

The project started with me and two of our senior engineers in front of a giant whiteboard. We were trying to answer a deceptively simple question: "What would the perfect, fastest possible architecture for a global e-commerce platform look like?"

The answer we sketched out was radical. We would deploy independent copies of our entire storefront application and its database in multiple AWS regions around the world: Mumbai for South Asia, Frankfurt for Europe, Singapore for Southeast Asia, Ohio for North America, and so on.

When I took this plan to Suumit, he immediately saw the business implications.

"This is amazing," he said, "but wait. Copies of the database? In every region? Won't that be a complete nightmare to keep in sync? And running this many servers all over the world... won't that cost us a fortune?"

He had put his finger on the two core challenges: data consistency and cost. The plan was ambitious, but it was fraught with technical risk. We were placing a huge bet that the performance gains would be so massive that they would justify the complexity. I was convinced they would.

Before we could even think about the data, we had to solve the first major problem: how do you direct users to the right server?

Technical Deep Dive: The Architecture of Speed

If we have a server in Mumbai and another in Frankfurt, how does a user's browser in Germany know to connect to the Frankfurt server? We couldn't ask our sellers to tell their German customers to go to a different URL. We needed one single, global address that would intelligently route users to the nearest location. The magic that makes this possible is called an Anycast IP.

Concept: Anycast IP - The Global Pizza Chain

Normally, an IP address on the internet is Unicast. This means one IP address leads to one specific machine in one specific location.

Anycast is different. With Anycast, we can announce the exact same IP address from multiple data centers around the world, all at the same time.

An Anycast IP is that global phone number for our application. We acquired our own IP address space (a block of IP addresses that we owned). We then configured our network providers to announce this IP from every one of our chosen AWS regions.

This was a complete game-changer.

It was seamless, automatic, and infinitely scalable. Anycast was our global front door. Now we had to make sure that behind that door, in every region, there was a fully functional, lightning-fast copy of our storefront ready to serve the user

Part 2: The Regional Brains

Anycast was our magic carpet, effortlessly delivering users from anywhere in the world to the doorstep of our nearest data center. But a user arriving at an empty building is useless. We had to ensure that behind that door in Frankfurt, Singapore, and Ohio, there was a complete, self-sufficient, and lightning-fast copy of our storefront platform, ready to serve their request instantly.

This meant deploying two key components in every single region: compute and data.

Technical Deep Dive: The Regional Architecture

We chose nine strategic AWS regions around the globe to be the home for our new "regional brains." In each of these nine locations, we built a standardized, identical, and completely independent setup.

Implementation: Independent Kubernetes Clusters

In each region, we deployed a small, self-contained Kubernetes cluster.

Implementation: Regional Read-Replica Databases

Having the application servers (the "kitchens") in each region was only half the battle. If a chef in Frankfurt still had to make a slow, 150ms round-trip call to the main library in Mumbai to get a recipe, we would have gained nothing. We had to bring the data to the compute.

In each of the nine regions, alongside the Kubernetes cluster, we deployed a read-only replica of our main PostgreSQL database.

We had successfully designed our regional brains. Each one was a self-sufficient pod, capable of serving its local users with incredible speed.

But this created a new, massive, and terrifying problem.

The New Problem: Global Data Synchronization

We now had nine perfect, read-only copies of our database scattered across the globe. But the "master recipe book"-the single source of truth where sellers made their changes-still lived in only one place: our main master database in Mumbai.

When a seller in India updates a product's price, that change is written to the Mumbai master database. How, then, do we propagate that single change to the nine other database replicas in Frankfurt, Ohio, Singapore, Brazil, and Sydney, reliably, in the correct order, and in near real-time?

The simple streaming replication we had used before was not designed for this complex, one-to-many, cross-continental data synchronization. A simple network hiccup could cause one region to fall out of sync, showing stale data for hours.

We had built the distributed brains of our network. Now, we had to build the global central nervous system that would connect them all and ensure they were all thinking in perfect, harmonious unison.

.

Part 3: The Global Nervous System

We had built nine powerful, independent regional brains. But a set of disconnected brains is useless. We needed a way to link them, to ensure that a change made in Mumbai was instantly known and reflected in Frankfurt, Ohio, and Singapore. We needed a global central nervous system.

The tool we chose for this monumental task was one we were already familiar with, but we were about to apply it on a global scale: Apache Kafka.

Technical Deep Dive: Global Data Sync with Kafka

We used Kafka and our Change Data Capture tool, Debezium, to create a real-time, durable, and reliable pipeline for synchronizing data across the planet.

The Architecture: A Central News Wire

The Data Flow: The Push Model

The entire system worked like a global news wire service (like Reuters or the Associated Press).

The step-by-step flow was incredibly elegant:

Within a second or two, a change made in India was reflected accurately across our entire global network.

The Benefit: Durability and Guaranteed Delivery This is why Kafka was so superior to simple database replication. Kafka's log is durable. If the network connection to our Frankfurt region went down for five minutes, the Frankfurt consumer would simply fall behind. The messages for it would pile up safely in the Kafka log in Mumbai. When the network came back, the consumer would reconnect and start reading from where it left off, quickly processing all the missed updates. This guaranteed that every region would eventually become consistent, and no data would ever be lost in transit.

The Shark Tank Mystery: Solved

This global, distributed architecture was the secret weapon that saved us during the Shark Tank effect. The 80,000 concurrent users weren't all hitting our central Mumbai servers. Thanks to our Anycast IP, the traffic was automatically distributed across our global footprint. Users from North America hit our Ohio cluster, European users hit our Frankfurt cluster, and so on.

The massive load was shared by nine independent, smaller systems. No single cluster was overwhelmed. It was a distributed defense against a concentrated traffic surge. Our obsession with global performance had accidentally created a system with incredible scalability and resilience.

We had declared war on latency. Our mission was to build an e-commerce platform that was not just fast, but instantly fast, for every user on Earth. This chapter is the detailed blueprint of our moonshot project: the Dukaan Global Edge Network. It's the story of how we moved beyond the conventional wisdom of web architecture to build something that gave us an almost unfair advantage in performance, security, and scale.

The Maggi Delivery Network Problem

To understand the leap we were about to take, you first need to understand the limitations of a traditional Content Delivery Network (CDN). A CDN, as we discussed in Chapter 11, is a fantastic tool. It's a global network of servers that caches your static files-your images, CSS, and JavaScript-close to your users. It's a vital first step.

But a traditional CDN is like a Maggi delivery network.

Imagine your main server in Mumbai is the Maggi factory. It produces the delicious, complex, and dynamic core of your product-the HTML document itself, which is built by your application and database. The images and other static files are the simple, unchanging masala packets.

A CDN is a network of delivery boys who have one job: they take a huge box of masala packets and store them in their local warehouses all over the country. When a customer in Delhi wants Maggi, a local delivery boy can instantly give them the masala packet from the Delhi warehouse. This is very fast.

But here's the problem: the delivery boy doesn't have the noodles. To get the actual noodles (the HTML page), he still has to send a request all the way back to the main factory in Mumbai. The factory has to process the order, cook up a fresh batch of noodles, and then ship them all the way to Delhi.

This is the fundamental limitation of a traditional CDN. It can deliver the simple, static parts of your website quickly, but for the most important part-the dynamic HTML generated by your server-the user still has to endure the long, slow, cross-continental journey back to your origin server. This is exactly why Shopify's TTFB was so high in India. Their CDN could deliver the images quickly, but the initial request for the page itself had to travel all the way to North America.

We realized that to be truly fast, we couldn't just deliver the masala packets from the edge. We had to build a fully functional Maggi factory in every major city. We needed to move the entire cooking process-the application servers and the database-to the edge. This is the core idea of a true edge computing platform.


### **The Three Pillars of the Edge**

Our Global Edge Network was built on three foundational pillars. These weren't just features; they were the strategic advantages that defined our platform and gave us our competitive edge.

Pillar 1: Performance - The 100ms Promise

Our war on Shopify was a war on latency, and the edge network was our ultimate weapon. The entire architecture was a symphony of components designed to crush TTFB and deliver near-instant page loads.

The combination of these technologies allowed us to achieve our moonshot goal. From the moment a user clicked a link to the moment their browser started rendering the page (TTFB), the delay was consistently under 50 milliseconds. The full page, with images delivered from the same regional edge, would load in well under 100 milliseconds. While our competitors were taking seconds to deliver their sites across continents, we were delivering ours in the blink of an eye. It was a categorical and undeniable performance victory.

Pillar 2: Security & Stability - The Global Immune System

When you build a centralized system, you create a single, massive target. A failure in that one location, whether due to a technical fault or a malicious attack, takes down your entire platform. A distributed edge network fundamentally changes this dynamic, creating a more resilient, self-healing system.

Pillar 3: Scale - The Elastic Coastline

The Shark Tank event was the ultimate proof of our network's incredible scalability. The secret wasn't just that the load was distributed, but that the system had multiple, cascading layers of elasticity.

Let's walk through the exact sequence of events during a massive traffic spike:

This multi-layered system-combining proactive global distribution with reactive local scaling-was our masterpiece. It allowed us to absorb the most extreme, unpredictable traffic spikes imaginable, not just surviving them, but doing so without our on-call engineers even receiving a single alert. It was the ultimate validation of our long and complex journey to the edge.

Key Takeaways

  • To achieve global low latency, you must move both compute and data to the edge. A regional application server is useless if it has to make a cross-continental call to a central database.
  • Anycast IP is the magic that makes global routing seamless. It allows you to use a single IP address to automatically direct users to the nearest physical data center.
  • A distributed architecture provides incredible fault tolerance. By deploying independent clusters in multiple regions, a failure in one region will not impact users in others, dramatically increasing your overall uptime.
  • Use a durable event log like Kafka as a global data synchronization backbone. It provides a reliable and scalable way to keep dozens of distributed databases in near real-time sync.
  • Sometimes, solving for one problem (performance) creates an elegant solution for another (scalability). Our quest for speed resulted in a system that could handle massive traffic spikes without breaking a sweat.

Excellent. The architecture is built. It has been tested by fire. Now, we enter the final phase of our journey: mastering the powerful, complex, and expensive machine we have created.

Part 5: Mastering the Machine (Optimization and Automation)

Building a powerful engine is one thing. Learning how to tune it for maximum performance, refuel it efficiently, and automate its maintenance is another. In this final part of our story, we move from being architects and builders to being master operators.

We had created a global, resilient, and lightning-fast platform. But it was expensive and, at times, still a black box. The next chapters are about our quest for efficiency, visibility, and total automation. It's the story of how we took our powerful machine and turned it into a truly world-class, cost-effective, and self-driving operation.