0
0
GCPcloud~10 mins

Read replicas in GCP - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Read replicas
Primary Database
Create Read Replica
Replica Syncs Data
Read Traffic Directed to Replica
Replica Handles Read Queries
Primary Handles Writes
The primary database creates a read replica that syncs data continuously. Read queries go to the replica, while writes stay on the primary.
Execution Sample
GCP
gcloud sql instances create my-replica \
  --master-instance-name=my-primary \
  --region=us-central1
This command creates a read replica named 'my-replica' for the primary instance 'my-primary' in the specified region.
Process Table
StepActionResultState Change
1Create primary database instancePrimary instance 'my-primary' createdPrimary database ready
2Run command to create read replicaRead replica 'my-replica' creation startedReplica instance initializing
3Replica syncs data from primaryData replication in progressReplica data catching up
4Replica sync completesReplica data up-to-dateReplica ready to serve reads
5Application sends read queriesQueries routed to replicaReplica handles read traffic
6Application sends write queriesWrites sent to primaryPrimary handles writes
7Replica continues syncing changesReplica stays updatedContinuous replication ongoing
💡 Read replica is fully operational and serving read traffic while primary handles writes.
Status Tracker
VariableStartAfter Step 2After Step 4After Step 7
Primary InstanceNot createdCreated and runningRunningRunning
Read ReplicaNot createdInitializingReady and syncedReady and continuously syncing
Data Sync StatusNoneStarting syncSyncedContinuous sync ongoing
Read TrafficNoneNoneStarts routing to replicaReads served by replica
Write TrafficNoneNoneHandled by primaryHandled by primary
Key Moments - 3 Insights
Why does the read replica not handle write queries?
Because the read replica is designed only to serve read queries to reduce load on the primary. Writes must go to the primary to keep data consistent, as shown in execution_table steps 5 and 6.
What happens if the replica is not fully synced?
If the replica is not synced (step 3), it cannot serve accurate read queries. The system waits until sync completes (step 4) before routing reads to the replica.
Does the replica operate independently from the primary?
No, the replica continuously syncs data from the primary (step 7). It depends on the primary for updates and cannot accept writes.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the replica become ready to serve read queries?
AStep 2
BStep 4
CStep 5
DStep 7
💡 Hint
Check the 'Result' column for when the replica data is up-to-date and ready.
According to variable_tracker, what is the status of 'Data Sync Status' after step 7?
ANone
BSynced
CContinuous sync ongoing
DStarting sync
💡 Hint
Look at the last column for 'Data Sync Status' in variable_tracker.
If the application sends a write query, where does it go according to execution_table?
APrimary database
BBoth primary and replica
CRead replica
DNeither
💡 Hint
Refer to step 6 in execution_table under 'Action' and 'Result'.
Concept Snapshot
Read replicas copy data from a primary database to handle read queries.
Writes always go to the primary to keep data consistent.
Replica syncs continuously to stay updated.
This reduces load on the primary and improves read performance.
In GCP, create replicas with 'gcloud sql instances create' using --master-instance-name.
Full Transcript
Read replicas are copies of a primary database that handle read queries to reduce load on the primary. The primary database handles all write queries to maintain data consistency. When you create a read replica in GCP, it initializes and syncs data from the primary. Once synced, the replica serves read traffic while continuously syncing updates. This setup improves performance by distributing read load. The replica cannot accept writes and depends on the primary for data updates.