'If it goes wrong, we will undo it'
It is the sentence that reassures people before an important change, and the one least often honoured. Undoing an application code change is usually easy. Undoing an infrastructure change is not always: a migrated database, a reconfigured network or a replaced certificate do not come back with one click.
That is why, in infrastructure, rollback is designed before the change, not improvised afterwards.
Keeping the old version alive
The safest technique is not to modify what works, but to bring the new version up alongside it:
- The current version keeps serving.
- The new version is created, complete, in parallel.
- It is tested with no real traffic or with a small share.
- Traffic is switched to the new one.
- If something fails, traffic returns to the previous one in seconds, because it is still there.
- Only once the new one is confirmed is the previous one retired.
It costs more for a few hours (there are two versions at once) and saves a great deal when something goes wrong.
When you cannot have two versions
Some changes do not allow parallel running, especially with data. For those:
- A verified backup immediately beforehand, restorable and tested (not an assumption).
- Changes in two stages: first the new is added without removing the old (a column, a field) and only afterwards, once everything uses the new, is the old removed.
- A written window and plan: what gets done, how long it takes, at what point there is no going back and who decides to continue.
The rule
No important change is approved without a written answer to 'how do we roll back, and how long does it take?'. If the answer is 'we cannot', the change needs a different shape.
Rolling back protects you from errors that have already happened. Better still is preventing certain errors from ever being applied.
How we apply it: Automation and IaC.