The BAC Theorem: Disaster Recovery in a Microservices Architecture

Tanmay Shah
3 min readNov 12, 2019

--

As more and more companies migrate towards a microservices architecture, it is important for the engineering teams at these firms to understand the best practices for an effective Disaster Recovery (DR) solution that works with this new kind of architecture.

As such, the BAC (Backup Availability Consistency) Theorem is the theoretical underpinning for DR in microservices. In this blog post, we’ll unpack this theorem.

The defining research paper for BAC Theorem was authored by engineers part of IEEE, and the paper succinctly states the theorem to be the following: “When backing up an entire microservices architecture, it is not possible to have both availability and consistency.”

This definition may sound similar to the CAP theorem, and that’s because BAC was inspired by CAP. To quickly recap, CAP Theorem states that any distributed system can satisfy only two out of the following three principles: consistency, availability, partition tolerance. Microservices are indeed distributed computing systems- hence this comparison holds.

Let’s discuss each of the three components of the BAC Theorem.
In their isolated context, the principles can be defined as follows:

Backup:
In the ideal scenario, we’d like to have a fully backed up microservices architecture in which each service and corresponding database has been backed up in the event of a disaster. The “backup” would be in the form of a point-in-time snapshot that captures the state of all components.

In reality, microservices architectures follow polyglot persistence, meaning that each service has its own database whether that is a separate instance of the same kind of database or a different database technology altogether. As a result, database backups are much more complicated due to the increased number and type of databases. See the following diagram for a depiction of polyglot persistence:

Availability:
In the ideal scenario, we can have a microservices architecture in which each component is fully available, and it is possible to read and update the state of any service at any point in time.
In reality, due to the aforementioned polyglot persistence, it is best practice to perform synchronized backups of all microservices and corresponding databases, but this means that no updates would be allowed during this backup process — the availability of the components is curtailed.

Consistency:
In the ideal scenario, “during normal operations, each microservice will eventually reach a consistent state.”
In reality, “if we allow each microservice to evolve its state independently and perform a backup of every microservice at a different time, the whole set of backups will not offer a consistent view over the state of the whole application”.

When we bring these principles together, we see that we can achieve the following combinations:

a) Backup and Availability
We can achieve backup and availability at the cost of inconsistency. If we back up each microservice independently in order to preserve the availability of the overall system during the backup process, we would be faced with an inconsistency in the architecture since backups would be taken at different times. It is possible relationships between two databases would be broken or missing.

b) Backup and Consistency
We can achieve backup and consistency at the cost of unavailability. If we try to avoid the previous problem of inconsistent backups by performing synchronized backups, we would limit the availability of the system since updates would not be possible during the backup process.

Several best practices and approaches have been engineered in order to work around the limitations that the BAC Theorem presents. To learn about these, refer to the IEEE paper.

References:
For a high-level overview of Business Continuity & Disaster Recovery: check here
For a high-level overview of microservices vs monolithic (traditional) architectures: check here

To learn more about handling failure & disaster recovery with microservices architectures:

Tanmay Shah, Hack the Industry Blog Contributor

--

--

Tanmay Shah

Interests: media, biotech, ML, venture capital, startups. I love coffee chats & meeting people —reach out to me at tdshah1@gmail.com to talk about any of these!