Migrating from DigitalOcean to Hetzner: From $1,432 to $233 With Zero Downtime
This detailed post chronicles a complex, zero-downtime migration of a large production stack from DigitalOcean to Hetzner, slashing infrastructure costs from $1,432 to $233 per month. The author's methodical approach, including advanced MySQL replication and Nginx proxying, provides a masterclass in cost-saving without service interruption. It resonates with HN's skepticism towards expensive cloud providers for stable workloads, demonstrating significant savings and robust technical execution.
The Lowdown
A Turkish software company, grappling with soaring dollar-denominated infrastructure costs due to local inflation, undertook an ambitious migration from DigitalOcean to Hetzner. Their goal was to drastically cut expenses without compromising service availability for a substantial production environment.
Key aspects of this impressive migration included:
- Motivation and Savings: DigitalOcean costs of $1,432/month for a 192GB RAM, 32 vCPU droplet were replaced by a more powerful Hetzner AX162-R for just $233/month, yielding over $14,000 in annual savings.
- Complex Workload: The migrated stack was far from trivial, encompassing 30 MySQL databases (248 GB), 34 Nginx sites, GitLab EE, Neo4j, Gearman, and live mobile app traffic.
- Operating System Upgrade: The migration offered an opportunity to upgrade from an End-of-Life CentOS 7 to AlmaLinux 9.7, bringing MySQL from version 5.7 to 8.0.
- Zero-Downtime Strategy: A meticulous six-phase plan ensured no service interruption. This involved full stack installation on the new server, cloning web files, setting up MySQL master-slave replication, reducing DNS TTLs, converting the old server to a reverse proxy, and a final DNS cutover.
- MySQL Deep Dive: The author leveraged
mydumperfor parallel bulk data loading, which dramatically reduced the time compared tomysqldump. They also navigated challenges like MySQL 5.7 to 8.0 schema incompatibilities and resolved replicationDuplicate Keyerrors usingIDEMPOTENTmode. - Pre-Cutover Testing: Clever use of
/etc/hostson local machines allowed thorough testing of the new environment before any public DNS changes. - Unexpected Hurdles: A
SUPERprivilege issue was discovered where application users could bypassread_onlyon the slave, necessitating a bulk privilege revocation. - Scripting Everything: From DNS updates via API to Nginx configuration rewrites and GitLab webhook updates, extensive scripting was crucial for efficiency and accuracy.
This detailed account serves as a testament to how careful planning and a deep understanding of infrastructure can lead to significant financial benefits and improved system performance, offering a powerful counter-narrative to the perception that managed cloud services are always the optimal solution for established, stable applications.
The Gossip
Cloud Cost Conundrum
The discussion widely validates the author's move, agreeing that major cloud providers like DigitalOcean and AWS have become excessively expensive for stable, non-elastic workloads. Commenters shared similar experiences of significant savings by switching to providers like Hetzner. While acknowledging the convenience of managed cloud services for quick setup or ephemeral tasks, many argue that the high premium for these services is no longer justified for mature applications, pointing out the substantial financial gains that could be reinvested elsewhere. There's a strong sentiment that EU cloud providers often offer better value and transparency compared to their US counterparts, sometimes even with legal benefits.
Resilience Realities and Risks
A central debate revolved around the trade-offs of moving from a managed virtualized environment (DigitalOcean droplets) to a dedicated bare-metal server (Hetzner AX series). Critics highlighted the loss of inherent cloud redundancy, live migration capabilities, and integrated backup solutions. They argued that while cost savings are substantial, the operational burden of ensuring high availability, disaster recovery, and hardware maintenance shifts entirely to the user. Some suggested running identical backup servers or leveraging Hetzner's cloud offerings for better resilience, while others countered that not all applications require hyper-level uptime and that the author's comparison might be 'skewed' by not accounting for these managed service differences.
Mastering Migration Mechanics
Many users appreciated the detailed technical breakdown of the zero-downtime migration, calling it 'admirable and useful teaching.' Specific techniques like using `mydumper` for large MySQL datasets and scripting DNS/Nginx configurations were praised. Some commenters offered additional tips, such as utilizing Percona XtraBackup for MySQL. The discussion also touched upon the increasing role of AI tools in simplifying complex migrations, suggesting a future where such transitions become even more accessible.