Video in progress

In which situations does a plain rollback not help, and what do you do then?

When the new version left a trace that cannot be undone: a migration that breaks the DB schema, messages in the new format sitting in a queue, data with a new structure written to the cache. In that case rolling the code back creates a new problem, and you have to do a forward fix.

📖 Answer

A rollback restores only the code, not the data. A few real cases:

  • 1.5.0 changed the status column from VARCHAR to INT. If 1.4.0 comes back, it expects a string and fails on every request.
  • 1.5.0 wrote a Kafka event with a new field, and the consumers were updated too. If you roll the consumer back, it cannot read the new-format messages left in the queue.
  • An object in Redis was serialized with the new class structure, and the old code cannot deserialize it.
  • Requests went to the payment provider through the new API, and the callbacks arrive at the new endpoint.

Prevention:

  • migrations should be additive only (expand/contract), with the breaking step in a later release;
  • message and cache formats should be backward compatible (a new field is optional, and an old reader ignores an unknown field);
  • new behavior goes behind a feature flag, so if there is a problem it is turned off without a deploy.

If you end up in such a situation anyway: first stop the damage (a feature flag, cutting traffic), then ship a quick forward fix, a version that can read the old format too. It is worth putting "if we revert this, what breaks?" into the checklist before every release.