Problem: Cloud SQL instances run indefinitely and are monetarily expensive to host.
Goal: Save money while not compromising on database availability.
It has been almost four years and Google Cloud has not fulfilled this feature request that has already been implemented on AWS with their Aurora RDS.
Since it does not seem that on demand Cloud SQL that auto-scales to zero is coming any time soon, will the following strategy work?
- Have instances of Cloud SQL, a Baby and a Papa. They follow the master/slave replica principle, with twist. The Baby instance is small with few vCPU's and low memory, it always runs, but does so cheaply. However, the Papa instance is expensive with high vCPU and high memory but runs only when needed.
- To begin, only the Baby Cloud SQL instance is running so it is the master that accepts reads/writes. The Papa Cloud SQL instance is not running.
- Since I am using standard app engine that will auto-scale to zero with no traffic, schedule a cron job that checks every 10 min if no app engine instances exists. In this case, the application has no traffic. If this is not the case, the Papa Cloud SQL instance is started. Once started, the Papa instance becomes the master that accepts reads/writes while the Baby instance becomes a slave replica capable of only reads.
- If the cron job detects the app engine has zero instances running, this means there is no traffic. Thus, the Papa Cloud SQL instance is stopped and the Baby Cloud SQL replica is promoted to master and can accept reads/writes.
- In this way, the expensive Papa instance runs on demand. If there is a traffic spike when the Papa instance is stopped or rebooting, the Baby instance will still be able to respond to requests.
This strategy ensures that the expensive Papa Cloud SQL instance only runs with traffic. Is this Baby-Papa dynamic possible on Google Cloud?