Skip to main content
Insyrge - Zoho CRM & Business Automation Consulting
← Back to All ArticlesAI & Business Automation

How Do I Build Redundancy for a Web Application and Its Database Across Separate Availability Zones?

Multi-AZ load balancing, stateless app tiers, database replication and failover, RTO and RPO, and how to test it, with AWS, Azure and Google Cloud references

•Insyrge

Build redundancy for a web app and database across availability zones: multi-AZ load balancing, replication and failover, RTO and RPO targets, and failover testing.

TL;DR: To make a web application and its database survive the loss of one availability zone (AZ), run the web tier in at least two zones behind a load balancer, keep the app servers stateless, and put the database in a high availability setup with a standby copy in a different zone. Decide your RTO (how long you can be down) and RPO (how much data you can lose) first, because they decide the design and the cost. Then test by actually failing a zone or a database, not just reading the diagram.

Key takeaways

  • An availability zone is a separate group of data centres in a region with independent power, cooling and networking, so one zone can fail while others keep running.
  • Spread the web tier across at least two zones, behind a load balancer that checks health and stops sending traffic to failed targets.
  • Make the app stateless. Keep sessions, uploads and queues outside the servers.
  • Use the database provider's multi-zone high availability: a synchronous standby in another zone with automatic failover.
  • Set RTO and RPO, size the surviving zones to carry full load, and rehearse failover regularly.

If your whole application runs in one zone, a power or network problem in that zone takes you offline. Running across zones is the standard first step to avoid that. This guide covers the web tier, the database, the targets that guide the design, and how to test it. Product names are from AWS, Azure and Google Cloud, but the pattern is the same elsewhere. For related reading, see high availability architecture for web apps and when you need multi-region.

Want your app and database to survive a zone failure? Contact Insyrge or book a call.

What does multi-AZ redundancy mean?

Cloud regions are divided into availability zones. Microsoft describes Azure zones as separated groups of data centres within a region, each with independent power, cooling and networking, so that if one zone has an outage the remaining zones keep services running (What are Azure availability zones?). Other clouds use similar designs. Multi-AZ means you place copies of each layer of your application in more than one zone and arrange for traffic and data to move when one disappears.

How do you set up the web tier across zones?

  1. Run at least two copies, in different zones. Use an auto scaling group, scale set or managed instance group that spans zones, so replacements launch in the healthy zones.
  2. Put a load balancer in front. AWS explains that a load balancer sends requests only to healthy targets and recommends enabling multiple zones. For Application Load Balancers, at least two zones are required (How Elastic Load Balancing works). Azure and Google Cloud offer zone-aware load balancing too.
  3. Understand cross-zone behaviour. With cross-zone load balancing on, each load balancer node spreads traffic over targets in all enabled zones. With it off, each node only uses targets in its own zone (How Elastic Load Balancing works). Know which one you have, because it changes how evenly load is shared when a zone is lost.
  4. Set meaningful health checks. Check a page that exercises the database connection, not just that the server responds.
  5. Make servers stateless. Keep sessions in a shared store, uploads in object storage, and background jobs in a queue. Any server in any zone should be able to handle any request.
  6. Size for failure. If you run in two zones and lose one, the survivor must carry the full load. Many teams run enough capacity so that the loss of one zone is survivable without scaling delay.

How do you make the database redundant across zones?

Do not build this by hand unless you have to. Managed databases offer it as a setting.

  • Amazon RDS. A Multi-AZ DB instance deployment provisions a synchronous standby replica in a different zone, and the standby does not serve read traffic (Multi-AZ DB instance deployments). A Multi-AZ DB cluster has two standby instances that can also serve reads (Amazon RDS Multi-AZ deployments).
  • Azure SQL Database. Zone redundancy is available to keep the database available through the loss of a zone (Azure SQL Database availability through redundancy). Check the tier and region you plan to use.
  • Google Cloud SQL. A high availability instance is regional, with a primary and a standby in different zones. Writes are replicated synchronously to disks in both zones before a transaction is committed, and the standby takes over in a failover (About high availability for Cloud SQL).

A few rules apply on any platform:

  • Synchronous replication across zones protects data but can add a little write latency. That is the usual price of a low RPO.
  • A standby is for failover, not read scaling, unless the product says otherwise. For read scaling use replicas, as covered in PostgreSQL read replicas.
  • Use the endpoint name, not an IP address. After a failover the name points at the new primary, so the app reconnects without a config change.
  • Add retry logic. Connections drop during failover. Microsoft notes that downtime is not impactful when the app uses retry logic (Azure SQL Database availability through redundancy).
  • Keep backups too. Multi-zone replication copies mistakes as well, such as a bad delete. You still need point-in-time backups.

How do RTO and RPO shape the design?

RTO is the longest outage you can accept. RPO is the most data, measured in time, that you can afford to lose. A target of near-zero RPO points to synchronous replication, which is what the multi-zone database options above use. A longer RTO may let you rely on automated recovery rather than a warm standby.

Multi-AZ covers the loss of a zone, not a whole region. AWS's disaster recovery guidance notes that for the disruption or loss of one data centre, a well-architected highly available workload may only need backup and restore, and that you should look at pilot light, warm standby or multi-site approaches if your definition of disaster includes a whole region (AWS disaster recovery options in the cloud). Google Cloud offers a similar planning guide (Google Cloud disaster recovery planning guide). Decide which failures you are planning for and write them down.

How do you test it?

An untested failover is a hope, not a design. AWS says it is critical to regularly assess and test your disaster recovery strategy (AWS disaster recovery options in the cloud).

  1. Run a game day in a test environment first. Stop all app servers in one zone and watch traffic, errors and recovery time.
  2. Trigger a database failover and measure how long the app takes to reconnect. Compare it with your RTO.
  3. Check that no data written before the failover is missing, which tests your RPO.
  4. Use a fault injection tool if you have one. AWS Fault Injection Service is one example.
  5. Restore a backup into a fresh environment and time it.
  6. Write down what you learn, fix it and repeat every few months.

Sources

Frequently asked questions

How do I build redundancy for a web application across availability zones?

Run the web tier in at least two zones behind a load balancer with health checks, keep servers stateless by storing sessions, files and jobs outside them, and use auto scaling that spans zones so replacements launch in healthy zones.

How do I make a database redundant across availability zones?

Use your provider's multi-zone high availability option: a synchronous standby in another zone with automatic failover, such as RDS Multi-AZ, Azure SQL zone redundancy or Cloud SQL high availability. Connect through the endpoint name and add retry logic.

What is the difference between RTO and RPO?

RTO is how long you can be down. RPO is how much data, measured in time, you can lose. Together they decide how much redundancy you need and what it costs.

Is multi-AZ the same as multi-region?

No. Multi-AZ protects against the loss of a zone inside one region. Multi-region protects against the loss of a whole region, and is more complex and costly. Decide which failures you are planning for.

Does a multi-AZ database replace backups?

No. Replication copies deletes and corruption to the standby as well. Keep point-in-time backups and test restores.

How do I test a failover?

Stop the app servers in one zone in a test environment, trigger a database failover, measure recovery time against your RTO, check for missing data against your RPO, and repeat on a schedule.

Insyrge will help you build redundancy across availability zones

We design the multi-zone web tier and database, set your RTO and RPO targets, and test failover so you know it works before you need it. Contact Insyrge or book a call.

See also: solutions architecture and custom app development.

Related resources

About the Author

Manav Sharma is the founder of Insyrge and a CRM solutions architect. He works across Zoho, Salesforce, HubSpot, Odoo and more, designing the CRM setups, integrations and automations that keep sales and operations teams working from the same data.

Need Help Implementing This in Your Business?

Our certified Zoho consultants and automation experts can help you design and deploy custom workflows tailored to your operations.

Book Free Consultation