Escaping the Golden Cage: From AWS to Bare Metal
We had done it. We had built our masterpiece on the best foundation we could find: Amazon Web Services. The cloud had given us the power to deploy servers around the world with a few clicks, to build a global database network, and to scale to incredible heights. We were living in a golden age of engineering, powered by the seemingly infinite resources of the cloud.
But we soon discovered that our beautiful home was, in fact, a golden cage. It gave us comfort, power, and speed, but it came at a staggering price and kept us locked into a system where we didn't have ultimate control. This is the story of our daring escape.
Part 1: The $80,000 Phone Call
The call came at the end of the month. It was Suumit. He wasn't angry or panicked. His voice just had a flat tone of pure, unadulterated shock.
"Subhash," he said, "the AWS bill just came in. It's eighty thousand dollars."
I stopped what I was doing. "Eighty thousand? For the month?"
"For one month," he confirmed. "Eighty thousand US dollars."
I pulled up our AWS Cost Explorer dashboard. He was right. The graph of our monthly spending wasn't a gentle slope; it was a rocket launch, mirroring the growth of our user base. Our success was literally costing us a fortune, and our profitability was evaporating into the cloud.
We dug into the line items. The culprits were everywhere. We were paying for:
- Dozens of powerful EC2 instances to act as Kubernetes nodes across our nine global regions.
- A premium for using AWS's managed Kubernetes service (EKS).
- A massive bill for our managed PostgreSQL databases (RDS), including the powerful master instance and all the regional replicas.
- Hefty data transfer costs for the Kafka traffic that was synchronizing our global network.
At every layer of our stack, we were paying a "convenience tax." We were paying AWS for the privilege of not having to manage the underlying hardware. In the early days, this tax was worth it. It allowed us to move incredibly fast. But now, that convenience was threatening to bankrupt us. We were trapped in the golden cage.
Technical Deep Dive: The Economics of Infrastructure
That $80,000 bill forced us to have a long, hard conversation about the fundamental economics of our infrastructure. We had to analyze the trade-offs between the two primary ways of running an internet company: in the Cloud or on Bare Metal.
Concept: The Cloud vs. Bare Metal Trade-off
1. The Public Cloud (AWS, Google Cloud, Azure)
- Analogy: This is like renting a high-end, fully-furnished, and serviced apartment in the heart of a major city.
- Pros (The "Golden"):
- Speed & Convenience: You can move in today. The electricity, plumbing, and security are all handled for you. Need another room? Just make a phone call (an API call). This is what allowed us to build our global network in weeks instead of years.
- Elasticity: You can scale up or down on demand. You pay for what you use on a monthly basis.
- Cons (The "Cage"):
- Prohibitively Expensive at Scale: You are paying a massive premium for that convenience. The rent is exorbitant because it includes the landlord's staff, their brand, their marketing, and their profit margins on top of the raw cost of the building.
- Lack of Control: You can't change the plumbing or knock down a wall. You are limited by the landlord's rules and the specific "appliance models" (server types) they offer. You are fundamentally renting, not owning.
2. Bare Metal (Self-Hosted)
- Analogy: This is buying a plot of land and building your own house from the ground up, using a provider like Hetzner, OVH, or a local data center.
- Pros:
- Drastic Cost Savings: This is the headline feature. You are only paying for the raw materials: the servers themselves, the power, and the network connection. There is no middleman's profit margin. The cost can be 10x to 20x cheaper than the equivalent resources in the cloud. That $80,000 AWS bill could become a $5,000 bare-metal bill.
- Total Control & Performance: You own the house. You can build it however you want. You can choose specialized, high-performance hardware (e.g., servers with the fastest possible CPUs and NVMe drives) that are often better and cheaper than what the cloud providers offer.
- Cons:
- High Operational Overhead: This is the massive trade-off. You are now responsible for everything. You have to be the architect, the construction worker, the plumber, and the security guard. If a hard drive fails at 3 AM, there's no AWS support team to fix it; you have to have your own team and processes in place to handle it.
- Inelasticity: You are buying, not renting. It's a capital expense. Scaling up means physically ordering and racking new servers, which can take days or weeks. Scaling down is even harder.
In the beginning, renting the fancy AWS apartment was absolutely the right decision. It gave us the speed we needed to find product-market fit and build our global network. But now our architecture was stable, our workload was predictable, and the rent was simply too high.
We made the bold, terrifying decision to move out. It was time to buy our own land and build our own houses across the globe. It was time to migrate Dukaan to bare metal.
Part 2: The Great Migration
The decision was made. We were leaving the golden cage of AWS. But this presented a terrifying new challenge: how do you move your entire global, live production system, serving millions of users, from one provider to another without a single second of downtime?
You can't just turn off the old system and turn on the new one. That would be a planned outage, and in our business, that's unacceptable. We had to perform the ultimate high-wire act: rebuilding our entire infrastructure on a new foundation and seamlessly shifting the traffic over while the show was still in full progress.
Our Secret Weapon: The Anycast IP
This entire zero-downtime migration was only possible because of one crucial decision we had made months earlier: we owned our own IP address space.
Because our Anycast IP belonged to Dukaan and not to AWS, we had ultimate control over where on the internet it was announced from. We weren't tied to AWS's network. This IP address was our permanent, portable address on the internet. We could move house, but our address would stay the same. This was the key that unlocked our ability to migrate without our users ever knowing.
The Strategy: The Strangler Fig on a Global Scale
We decided to apply the same Strangler Fig Pattern we used to break apart our monolith, but this time on a global, infrastructural scale.
- Analogy: We weren't going to move out of our expensive rented apartment in a single day. Instead, we would start building our new house on the plot of land next door. For a period of time, we would be paying for both the old rent and the new mortgage. We would then gradually start moving our furniture (our traffic), room by room, from the old apartment to the new house. We would test each room thoroughly. Only when the old apartment was completely empty and we were sure the new house was perfect would we finally stop paying rent.
This gradual, controlled migration was the only way to do it safely.
Technical Deep Dive: The Migration Playbook
Step 1: Build the New Foundation
First, we had to build our new houses. We chose a bare-metal provider, Hetzner, known for its powerful servers and affordable pricing. We rented physical servers in data centers that were geographically close to our existing AWS regions (for example, a data center in Helsinki, Finland, to replace our AWS cluster in Frankfurt, Germany).
This is where the "operational overhead" we talked about became very real. We didn't get a nice AWS dashboard. We got a root password to a bare-metal Linux server. We were responsible for everything:
- Installing the operating system.
- Configuring the complex networking between the servers.
- Building our own Kubernetes clusters from scratch.
We used tools like k3s, a lightweight but powerful Kubernetes distribution, to make this process easier. But it was still a massive undertaking. We had to become experts not just in our application, but in the low-level infrastructure it ran on. Over several weeks, we painstakingly built and tested our new, self-hosted Kubernetes clusters in nine new data centers around the world.
Step 2: The Gradual Traffic Shift
This was the most critical and delicate phase of the migration. Let's take our European traffic as an example.
- Initial State: 100% of our European traffic was being routed via our Anycast IP to our Kubernetes cluster running on AWS in Frankfurt. Our new, self-hosted Kubernetes cluster in Helsinki was ready, but taking zero traffic.
- The Dual Announcement: We configured our network to start announcing our Anycast IP from both the AWS Frankfurt location and our new Hetzner Helsinki location simultaneously.
- The 1% Test: Using the internet's routing protocol (BGP), we could control how much traffic preferred one route over the other. We shifted just 1% of our European traffic away from AWS and over to our new bare-metal cluster in Helsinki. The other 99% continued to be served by the old, stable AWS infrastructure.
- Monitor Everything: We watched our monitoring dashboards like hawks. We scrutinized the error rates, page load times, and CPU usage for that tiny 1% of traffic. Was the new cluster stable? Was it performing as expected?
- Ramp Up: Once we were confident that the new cluster was healthy, we gradually increased the traffic. We'd move to 10%. A day later, 25%. Then 50%. Each step was carefully monitored. If we saw any issues, we could instantly shift all the traffic back to AWS with zero downtime.
- The Final Switch: After a few days of rigorous testing, we shifted 100% of our European traffic to the new Helsinki cluster.
The AWS cluster in Frankfurt was now completely idle, receiving no traffic at all. It was an empty, expensive apartment.
Step 3: Decommission and Repeat
With the traffic fully migrated, we could safely log into the AWS console and terminate every single server, database, and load balancer in our Frankfurt region. The first room of the golden cage was dismantled.
We then repeated this incredibly careful and deliberate process, region by region, over the next two months, until our entire global application was running on our own self-hosted, bare-metal infrastructure.