title: SQL Database Blue / Green deployments
body: <p>I am dealing with the infrastructure for a new project. It is a standard Laravel stack = PHP, SQL server, and Nginx. For the PHP + Nginx part, we are using Kubernetes cluster - so scaling and blue/green deployments are taken care of.</p>
  
  <p>When it comes to the database I am a bit unsure. We don't want to use Kubernetes for SQL, so the current idea is to go for Google Cloud SQL managed service (Are the competitors better for blue/green deployment of SQL?). The question is can it sync the data between old and new versions of the database nodes?</p>
  
  <p>Let's say that we have 3 active Pods and at least 2 active database nodes (and a load balancer).</p>
  
  <p>So the standard deployment should look like this:</p>
  
  <ol>
  <li>Pod with the new code is created.</li>
  <li>New database node is created with current data.</li>
  <li>The new Pod gets new environment variables to connect to the new database.</li>
  <li>Database migrations are run on the new database node.</li>
  <li>Health check for the new Pod is run, if it passes Pod starts to receive traffic.</li>
  <li>One of the old Pods is taken offline.</li>
  </ol>
  
  <p>It should keep doing this iteration until all of the Pods and Database nodes are replaced.</p>
  
  <p>The question is can this work with the database? Let's imagine there is a user on the website that is using the last OLD database node to write some data and when switched to the NEW database node the data are simply not there until the last database node is upgraded. Can they be synced behind the scenes? Does Google Cloud SQL managed service provide that?</p>
  
  <p>Or is there a completely different and better solution to this problem?</p>
  
  <p>Thank you!</p>