professional-cloud-data-engineer
Replication in GCP managed databases provides high availability and disaster recovery capabilities. Google Cloud offers managed database services including Cloud SQL and Memorystore for Redis, each with different replication options to meet various business requirements. Understanding these options helps organizations design resilient architectures that can withstand failures while maintaining acceptable performance levels.
GCP supports two primary replication models that differ in how data is written to primary and replica nodes. Synchronous replication ensures data is written to both the primary and replica nodes before acknowledging the write operation, providing strong data consistency but potentially increasing write latency. Asynchronous replication sends data to replicas after acknowledging the write to the primary, which minimizes latency but may result in some data loss if the primary fails before replication completes.
The choice between these models directly impacts the recovery point objective (RPO)—the maximum acceptable amount of data loss measured in time. Synchronous replication offers near-zero RPO, while asynchronous replication may have higher RPO depending on network conditions and replication lag. Organizations must weigh the tradeoff between data consistency and write latency when selecting their replication model.
Cloud SQL provides several replication configurations for its managed database instances:
These options enable organizations to balance data consistency, latency, and operational complexity based on their specific needs.
Memorystore for Redis offers both standalone and high availability deployment options. The Standard Tier provides high availability with automatic failover, replicating data across multiple zones within a region. For more advanced requirements, Redis Enterprise Cloud supports cross-region active-active multi-primary writes with a 99.999% SLA, enabling writes to occur simultaneously in multiple geographic locations.
Key replication features include automatic failover detection and recovery, read replicas for scaling read-intensive workloads, multi-zone and multi-region deployment options, and integration with Cloud Monitoring for visibility into replication health.
When designing replication topologies, organizations must evaluate trade-offs between write latency, data consistency, and cost. Synchronous replication across regions significantly increases write latency due to network distance, while asynchronous replication may introduce temporary data inconsistency during normal operations or failures. The selection between fully managed services like Memorystore and self-managed solutions depends on organizational expertise, operational requirements, and specific feature needs.
Monitoring replication health ensures that data remains available and consistent across your database infrastructure. Proper monitoring helps identify issues before they cause outages or data loss.
In Cloud SQL Enterprise Plus, advanced disaster recovery (DR) allows administrators to manage replication health and execute failovers using a designated DR replica. A standard replica failover is immediate to minimize downtime but can result in data loss if the DR replica experiences high replication lag at the moment of failure. Conversely, a switchover is a planned, zero-data loss operation where the primary database is placed in read-only mode until the DR replica's replication lag reaches zero.
Exam tip: To maintain high availability (HA) throughout a switchover process, administrators must verify HA is enabled on the primary before performing the switchover, then re-enable HA on the new primary.
Managing replication throughput requires diagnosing potential bottlenecks on the primary database, especially during asynchronous replication in AlloyDB Omni. In these systems, any data that has not yet been replicated to the secondary cluster is temporarily stored on the primary instance as Write-Ahead Logging (WAL) files. To prevent primary database degradation and unbounded log growth, administrators must allocate adequate disk space and monitor connection speeds between data centers.
Additionally, if a failed primary instance in Cloud SQL remains offline for more than 24 hours, Cloud SQL automatically removes it from the replication topology to protect the active database's storage.
When executing database migrations with Cloud Spanner, configuring a robust fallback mechanism like reverse replication is vital for mitigating migration risks. This process reads changes from Spanner and writes them back to the source database, which requires capturing and temporarily ordering changes due to Spanner's distributed architecture.
Key steps in establishing a reverse replication flow include:
Building these fallback mechanisms ensures that applications can switch back to the source database with minimal downtime if inconsistent performance occurs after cutover.
Organizations can optimize database performance and latency by selecting the appropriate global deployment pattern based on user geographic distribution. Deployments can range from a single region to highly distributed models where both frontend and backend servers are placed in multiple global regions. While distributing backends minimizes user latency by answering requests locally, it introduces complex data synchronization challenges across regions. To simplify this complexity, administrators can leverage Cloud Spanner's multi-region configurations, which provide low-latency read access globally using built-in read-only replicas.
Automated failover is a critical component for ensuring high availability and disaster recovery in GCP managed database services. This process involves designing systems that can automatically detect failures and promote a standby or replica instance to become the primary, minimizing downtime and data loss. The goal is to create resilient data workloads that can withstand infrastructure outages with minimal manual intervention.
The design of an automated failover strategy revolves around several key principles. First, you must establish clear health checks to monitor the primary instance's status, often performed via heartbeats or monitoring metrics, to determine when a failure has occurred. Second, you need defined promotion logic that dictates which replica should take over, considering factors like data freshness (replication lag) and geographic location. Finally, the entire procedure must be automated and tested to ensure it executes reliably during a real incident, meeting your defined Recovery Time Objective (RTO).
GCP offers built-in automated failover capabilities for several managed database services:
Cloud SQL: When configured for High Availability (HA), Cloud SQL uses a standby instance in a different zone. A heartbeat system monitors the primary; if multiple heartbeats are missed (typically after ~60 seconds), an automatic failover is initiated, and the standby becomes the new primary, serving data through the same IP address. For cross-region disaster recovery, you can use advanced disaster recovery (DR) with designated DR replicas to enable controlled failover with minimal data loss.
BigQuery: Managed disaster recovery for Enterprise Plus editions uses cross-region dataset replication. You can initiate a hard or soft failover to a secondary region, promoting both the dataset replicas and the associated compute reservation. A hard failover happens immediately, while a soft failover waits for all committed changes to replicate, helping to control the Recovery Point Objective (RPO).
Memorystore (Redis): Redis clusters inherently provide high availability. Automated failover is managed internally where a replica node is promoted to primary if the master fails, a process that is transparent to the application.
Implementing automated failover involves important trade-offs that impact your application. During the failover event, application connectivity will be temporarily interrupted as connections to the old primary are closed; applications must be designed to reconnect using the same endpoint. Data consistency is a key concern: promoting an asynchronous replica (like a cross-region read replica) may result in data loss equivalent to the replication lag at the time of failure, directly affecting your RPO. Furthermore, you must assess the performance implications of your failover configuration, such as the increased latency of synchronous replication or the cost of maintaining standby instances in multiple regions. Regular testing of your failover procedures is essential to validate your RTO and RPO assumptions.
Prepare and test your skills
Prepare and test your skills
Synchronous replication ensures data is written to both the primary and replica nodes before acknowledging the write, providing near-zero RPO but increasing write latency. Asynchronous replication acknowledges the write to the primary first and then sends data to replicas, minimizing latency but potentially causing data loss if the primary fails before replication completes.
A replica failover is immediate to minimize downtime but can result in data loss if the DR replica has high replication lag. A switchover is a planned, zero-data loss operation where the primary is placed in read-only mode until the DR replica's replication lag reaches zero.
When configured for High Availability, Cloud SQL uses a standby instance in a different zone and a heartbeat system. If multiple heartbeats are missed, typically after about 60 seconds, an automatic failover is initiated and the standby becomes the new primary, serving data through the same IP address.
Reverse replication is used during database migrations with Cloud Spanner to configure a fallback mechanism. It reads changes from Spanner and writes them back to the source database, requiring capturing and temporarily ordering changes due to Spanner's distributed architecture, and disabling forward change data capture before enabling reverse replication.
Increase the max_connections database flag on the primary instance and the replica instance
Increase the threshold of the cloudsql.googleapis.com/database/replication/network_lag alerting metric beyond 25 seconds
Deploy an intermediate read replica in us-central1 and configure cascading replication to europe-west1
Enable and configure the wal_compression database flag on the primary instance
An enterprise maintains a primary Cloud SQL for PostgreSQL database in us-central1 and a cross-region read replica in europe-west1 for regional reporting and disaster recovery readiness. During heavy transaction processing periods, operations teams observe growing replication delay.
A review of Cloud Monitoring telemetry reveals:
database/replication/network_lag metric is elevated near the 25-second reporting threshold.database/postgres/replication/replica_byte_lag metric with replica_lag_type: sent_location displays a steadily accumulating byte backlog.Which configuration change should you implement on the primary database to reduce network lag and improve cross-region replication throughput?