Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 7 min read

AI Writes Code. Who Recovers the Data? An Introduction to Disaster Recovery

They say it has never been easier to build software, that code has become a commodity and that the programmer / developer profession is living on borrowed time. Whether all of that is really true, I don't know, but there

AI Writes Code. Who Recovers the Data? An Introduction to Disaster Recovery

They say it has never been easier to build software, that code has become a commodity and that the programmer / developer profession is living on borrowed time. Whether all of that is really true, I don't know, but there's no denying how capable AI is at generating code and building systems. Every day we hear about a new SaaS, a new app and a new solution to a problem that sometimes isn't even a problem. But what happens to these applications when the hosting machine crashes, the data center is destroyed or the system gets hacked? That's what we'll talk about today: disaster recovery (DR).

Sooner or later, something will go wrong

Putting a system online and making it accessible to the world is just one of the early phases of a whole operation that has to be maintained to keep everything working. It's common to assume everything will go fine and that the application will never run into any kind of trouble. But one thing we can count on in the software world is that, if your application lives long enough, something will go wrong, sooner or later.

Data can be deleted by mistake (who hasn't accidentally deleted data in prod, right?), the machine can crash due to a spike in resource usage, some physical failure can happen, or even more serious situations, such as intrusions, which are becoming more and more common, or drone strikes. That last one isn't hypothetical: in 2026, AWS data centers in the United Arab Emirates and Bahrain were hit, and AWS itself admitted the permanent loss of customer data.

In situations like these, Claude, or any other AI, will hardly be able to restore your data. For many, losing data or being unavailable for a few hours means losing money, customers and credibility. That's why one of the first steps after putting an application online is defining how it will be restored if something goes wrong.

First things first: what do RTO and RPO mean?

To define how to restore a system, we need to keep two concepts in mind:

  • Recovery Time Objective (RTO): the maximum time the system can stay down until it's recovered. It's the acceptable downtime.
  • Recovery Point Objective (RPO): the maximum amount of data that can be lost, measured between the last backup and the moment of the failure.

Consider a scenario where the backup runs every day at 00:00, the system goes down at 10:00 and you manage to recover it at 11:00. The system was down for 1 hour and you lost 10 hours of data, that is, everything written between the last backup and the outage. If your RTO was 2 hours, it worked. If your RPO was 4 hours, the plan failed.

The lower the RPO and RTO, the less time the system will be unavailable and the less data will be lost. On the other hand, there will certainly be a higher cost and possibly greater operational complexity.

The 4 best-known disaster recovery strategies

With these concepts in hand, we can talk a bit about the best-known techniques for restoring a system. How the implementation is done varies according to the particularities of each business, and there are many guides online that present different views and even complement the techniques described here. The idea is just to introduce the concepts.

To make it easier, let's follow the same system throughout: a Laravel application with a MySQL database running on an AWS EC2 instance (virtual machine), in us-east-1 (US East region).

1. Backup and restore

It's the simplest strategy and usually comes enabled by default, or for an additional cost, with cloud providers. It consists of periodically generating copies of the data, through snapshots, dumps and the like. It usually doesn't have an active secondary region, although it's recommended to replicate or store the backups in a different region from where the application runs, so you don't lose everything in a full regional disaster. It's also recommended to keep the infrastructure versioned, using IaC (Infrastructure as Code) tools like Terraform, to reduce the environment's recovery time even further.

In our system, we can generate a database dump every day at 00:00 and store it in S3 in us-west-1 (US West region). In a disaster that takes down the entire region, we recreate the infrastructure in us-west-1 with Terraform, or even manually, restore the latest dump and redirect traffic by updating the DNS. In practice, this is usually done with a service like Amazon Route 53, with a low TTL and health checks.

It's the lowest-cost approach. The RPO depends on how often backups run, and the RTO is usually hours.

Backup and restore

2. Pilot light

Here we already create the resources needed to run the application in a second region. However, only the storage resources stay active, receiving data replicated from the primary region. The rest of the infrastructure can already be provisioned and configured, but it usually stays switched off.

Since data is replicated continuously, data loss is minimal, meaning the RPO drops. And since the infrastructure already exists, all you need to do is start and scale the resources, which also reduces the RTO.

Back to our example: given that the application runs on an EC2 instance in us-east-1, we can have another EC2 instance in us-west-1 running only the MySQL database, receiving data through asynchronous replication. The application's EC2 instance in us-west-1 also already exists, with Laravel and its dependencies configured, but it stays stopped. That's the difference from backup and restore, where everything is created from scratch. If something happens, we promote the replica to primary, start the application in us-west-1 and redirect traffic by updating the DNS.

Pilot light

3. Warm standby

In this scenario, there's a working copy of the application in the secondary region, but at a smaller scale. Data replication continues.

The difference from pilot light is that this environment can already serve requests immediately, even with reduced capacity. In case of a disaster, you just redirect traffic and scale up. The cost goes up, since besides the resources that store the data, there are also application resources running.

Now consider that our system has grown and we need two instances of the Laravel application running at the same time to handle the load. Since we now have more than one application instance, MySQL moves to its own EC2 instance, shared by all of them. In us-east-1, we'll have a load balancer distributing traffic between the two instances, plus the database's EC2 instance. In us-west-1, we'll also have a load balancer, but with only one application instance, and MySQL will keep receiving asynchronously replicated data. If something goes wrong, we promote the replica to primary, launch one more application instance in us-west-1, redirect traffic by updating the DNS and can scale the environment up to match the primary one.

Warm standby

4. Multi-site active/active

It's the technique that will probably require more financial resources than the others, but it provides the lowest downtime and data loss. It consists of a second region identical to the "primary" region, with the same resource proportions and receiving traffic in a distributed way.

The trickiest part here is the data: with both regions writing at the same time, you need to make sure it stays consistent between them, which usually requires databases built for this scenario.

In our example, we keep the application running at full capacity in both us-east-1 and us-west-1, serving requests in a distributed way. If one region fails, traffic is redirected to the other with almost no interruption, limited basically by how long the DNS takes to update. This approach also gives customers in different regions lower latency.

Again, all the examples were put together for illustration and may differ, a lot, from a real implementation.

Multi-site active/active

Summary

DR summary

Looks pretty simple, right?

How to choose the right strategy?

The answer, as with most software problems, is: it depends.

The level of complexity and financial resources needed varies according to how critical the operation is. For small applications, daily or weekly backups, often provided by hosting companies, are enough. For larger software, it's essential to have a defined and validated disaster recovery plan, or even to hire specialized third-party services.

Broadly speaking, we need to be clear about the impact, whether financial, operational or regulatory, of a sudden service interruption. We also need an objective criterion for what counts as a disaster. With that structured and, ideally, documented, it becomes easier to define each system's RTO and RPO and choose a coherent strategy.

Be prepared

There are many other ways to plan disaster recovery and make a system more fault-tolerant and redundant. The idea here was to illustrate a few ways to implement it and show how important this kind of operation is day to day.

A plan that has never been tested isn't a plan. Simulate a failure every now and then: restore a backup, run the failover, time it. Better to find out something doesn't work on a quiet day than in the middle of a disaster. At the very least, do the bare minimum.

I hope this helped a little!

References

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.