Let's say I have an system running on Kubernetes using rolling updates or AWS ECS using blue/green deployments or any other solution which offers zero-downtime deployments. The key point here is that new and existing version can coexist and they use the same relational database.
We have a table in the database called users
with a field username
which we want to split in the new version into two separate fields: firstname
and lastname
. To do that, we change the service code accordingly and do migration of existing records. This scenario also caters for potential rollbacks. This scenario should also cater for potential rollbacks.
During the deployment we first run the migration then run the rolling update. As far as I understand, this can lead to situation, where the migration is done, but the service with the previous versions is still consuming traffic. That's why we do the migration in a way, that it supports working both with the current version and the new version. We add new fields, but not removing the old one yet. username
field will be removed in a later release.
After deployment is finished, old version gets disabled and only new version is running, saving firstname
and lastname
separatelly. But here we end up in a situation, where if during the transition time a record was stored by the previous version, it will be stored in username
field. These records are not subject of the db migraiton, because they were created after in was launched.
How to overcome that situation? Should the db migration (only the data migration part) be launched after the deployment or maybe there is a gap in the process described?