This principle in the reliability pillar of the
[Google Cloud Well-Architected Framework](https://docs.cloud.google.com/architecture/framework)
provides recommendations to help you design and run tests for recovery in the
event of failures.

This principle is relevant to the *learning*
[focus area](https://docs.cloud.google.com/architecture/framework/reliability#focus-areas)
of reliability.

## Principle overview

To be sure that your system can recover from failures, you must periodically
run tests that include regional failovers, release rollbacks, and data
restoration from backups.

This testing helps you to practice responses to events that pose major risks to
reliability, such as the outage of an entire
[region](https://docs.cloud.google.com/docs/geography-and-regions#regions_and_zones).
This testing also helps you verify that your system behaves as intended during a
disruption.

In the unlikely event of an entire region going down, you need to fail over all
traffic to another region. During normal operation of your workload, when data
is modified, it needs to be synchronized from the primary region to the failover
region. You need to verify that the replicated data is always very recent, so
that users don't experience data loss or session breakage. The load balancing
system must also be able to shift traffic to the failover region at any time
without service interruptions. To minimize downtime after a regional outage,
operations engineers also need to be able to manually and efficiently shift user
traffic away from a region, in as less time as possible. This operation is
sometimes called *draining a region*, which means you stop the inbound traffic
to the region and move all the traffic elsewhere.

## Recommendations

When you design and run tests for failure recovery, consider the
recommendations in the following subsections.

### Define the testing objectives and scope

Clearly define what you want to achieve from the testing. For example, your
objectives can include the following:

- Validate the recovery time objective (RTO) and the recovery point objective (RPO). For details, see [Basics of DR planning](https://docs.cloud.google.com/architecture/dr-scenarios-planning-guide#basics_of_dr_planning).
- Assess system resilience and fault tolerance under various failure scenarios.
- Test the effectiveness of automated failover mechanisms.

Decide which components, services, or regions are in the testing scope. The
scope can include specific application tiers like the frontend, backend, and
database, or it can include specific Google Cloud resources like
Cloud SQL instances or GKE clusters. The scope must also specify any
external dependencies, such as third-party APIs or cloud interconnections.

### Prepare the environment for testing

Choose an appropriate environment, preferably a staging or sandbox environment
that replicates your production setup. If you conduct the test in production,
ensure that you have safety measures ready, like automated monitoring and manual
rollback procedures.

Create a backup plan. Take snapshots or backups of critical databases and
services to prevent data loss during the test. Ensure that your team is prepared
to do manual interventions if the automated failover mechanisms fail.

To prevent test disruptions, ensure that your IAM roles,
policies, and failover configurations are correctly set up. Verify that the
necessary permissions are in place for the test tools and scripts.

Inform stakeholders, including operations, DevOps, and application owners,
about the test schedule, scope, and potential impact. Provide stakeholders with
an estimated timeline and the expected behaviors during the test.

### Simulate failure scenarios

Plan and execute failures by using tools like
[Chaos Monkey](https://netflix.github.io/chaosmonkey/).
You can use custom scripts to simulate failures of critical services such as a
shutdown of a primary node in a multi-zone GKE cluster or a disabled
Cloud SQL instance. You can also use scripts to simulate a region-wide
network outage by using firewall rules or API restrictions based on your scope
of test. Gradually escalate the failure scenarios to observe system behavior
under various conditions.

Introduce load testing alongside failure scenarios to replicate real-world
usage during outages. Test cascading failure impacts, such as how frontend
systems behave when backend services are unavailable.

To validate configuration changes and to assess the system's resilience against
human errors, test scenarios that involve misconfigurations. For example, run
tests with incorrect DNS failover settings or incorrect IAM
permissions.

> [!NOTE]
>
> #### Zone and region disconnect testing in production
>
> To aim for the highest levels of service continuity, Google Cloud conducts rigorous resilience testing in a dedicated, production-equivalent environment. Unlike standard simulations, this testing uses an internal-only Google Cloud region that is architecturally identical to our customer-facing regions. The region's network connectivity is then physically disconnected to validate precisely how our products behave during a total zonal or regional failure.
>
> The goal is to ensure that while local services within the affected area might go offline as expected, control planes and services that operate in other zones and regions remain unaffected.
>
> Validation occurs on a consistent, periodic schedule, ensuring a repeatable feedback loop. This ongoing validation ensures our global infrastructure remains resilient against large-scale outages.
>
> For guidance on how to implement testing for your services running on Google Cloud, see [Fault Injection Testing](https://docs.cloud.google.com/fault-injection-testing).

### Monitor system behavior

Monitor how load balancers, health checks, and other mechanisms reroute
traffic. Use Google Cloud tools like Cloud Monitoring and
Cloud Logging to capture metrics and events during the test.

Observe changes in latency, error rates, and throughput during and after the
failure simulation, and monitor the overall performance impact. Identify any
degradation or inconsistencies in the user experience.

Ensure that logs are generated and alerts are triggered for key events, such as
service outages or failovers. Use this data to verify the effectiveness of your
alerting and incident response systems.

### Verify recovery against your RTO and RPO

Measure how long it takes for the system to resume normal operations after a
failure, and then compare this data with the defined RTO and document any
gaps.

Ensure that data integrity and availability align with the RPO. To test
database consistency, compare snapshots or backups of the database before and
after a failure.

Evaluate service restoration and confirm that all services are restored to a
functional state with minimal user disruption.

### Document and analyze results

Document each test step, failure scenario, and corresponding system behavior.
Include timestamps, logs, and metrics for detailed analyses.

Highlight bottlenecks, single points of failure, or unexpected behaviors
observed during the test. To help prioritize fixes, categorize issues by
severity and impact.

Suggest improvements to the system architecture, failover mechanisms, or
monitoring setups. Based on test findings, update any relevant failover policies
and playbooks. Present a postmortem report to stakeholders. The report should
summarize the outcomes, lessons learned, and next steps. For more information,
see
[Conduct thorough postmortems](https://docs.cloud.google.com/architecture/framework/reliability/conduct-postmortems).

### Iterate and improve

To validate ongoing reliability and resilience, plan periodic testing (for
example, quarterly).

Run tests under different scenarios, including infrastructure changes, software
updates, and increased traffic loads.

Automate failover tests by using CI/CD pipelines to integrate reliability
testing into your development lifecycle.

During the postmortem, use feedback from stakeholders and end users to improve
the test process and system resilience.