I found lots of articles on how to migrate data from RDS to Cloud SQL, however all of them do just master-slave replication and then the switch. However I couldn't find anything about master-master replication between two clouds.
We need that to switch our backend to Cloud SQL after sync is done, but we want to keep a way of easy switch back without losing any data.
Let's say we switch to Cloud SQL and then we decide that it doesn't work as expected due to some currently unknown issues and we want to switch back. So we'd have to migrate all data with new data back to RDS and then switch back to RDS. This will take time and we'll have downtime of an hour at least (set up replication CloudSQL -> RDS, switch; Or export data from CloudSQL and import into RDS, switch). So we want to avoid this downtime in case if we decide to switch back.
Is there any way to set up master-master replication between two clouds?
So after some investigation and research I was able to set up master-master replication between GCP and AWS. Here's the howto:
rds.logical_replication1track_commit_timestamp1pglogical.conflict_resolutionlast_update_winsshared_preload_librariespglogicalcloudsql.enable_pglogicalONcloudsql.logical_decodingONmax_replication_slots10max_worker_processesset8max_wal_senders10track_commit_timestampONpglogical.conflict_resolutionlast_update_winsAWS
GCP
AWS
GCP
Notes
After setting up the replication, data writes to both tables works and the data is appearing in each database regardless where it's written. If the row was inserted with same id error is shown and that doesn’t mess the data.
Make sure you use primary keys and ids to avoid messing up the data
Turning on the replication in 11th step didn’t copy data from GCP to AWS which was created between enabled replication AWS → GCP and 11th step (AWS ← GCP). So you must enable AWS → GCP replication first, then enable GCP → AWS replication and only after that switch backend to new database, so that data would start flowing back to AWS.
Basically I was following these two official guides to set this up: