CoursesBackend engineering from first request to production

Puzzle 12 · 13 of 18

Can two releases share one schema?

Change the shape of stored data while an older reader is still running.

All puzzles in this course

The problem

The save route used to accept just a name. Version two wants a label on every bookmark. Some version-one clients still write only the name. When is it safe to require the label?

See it

Can two releases share one schema? Expand Backfill Switch writers Enforce

Scroll sideways to see the full diagram.

  1. Add a field old code can ignore.

    Step 1 of 4
  2. Populate existing rows.

    Step 2 of 4
  3. Retire writers that omit the field.

    Step 3 of 4
  4. Check the data before requiring it.

    Step 4 of 4

The building block

Start with a nullable label column. Old readers selecting the name keep working. Backfill existing rows and deploy writers that populate the new field. While an old writer still runs it can create another missing label. Verify the backfill after old writers retire before enforcing the new rule. Test rollback of the application against the expanded database. Take a backup and read sample rows from an independent restored copy. A successful image rollback cannot reconstruct a dropped column.

Practice a mixed-version rollout

At noon the new label field is optional. The backfill copies river into its label. At 12:01 an old writer inserts hill and supplies no label. Counting missing labels now returns one, even though the earlier job reported success. Let new writers fill the label while old readers still request only the existing fields. Once old writers are gone, run the catch-up pass, count missing labels again, and then enforce the rule. Keep the compatibility window open until rolling back to the previous application is no longer required.

Try it

Run the browser experiment

Optional local lab

Run the migration and snapshot exercise. Add an old-style insert after the backfill. Demonstrate the missing label and restore a sample into a separate database.

Open the local exercise files

Check yourself

A backfill finished but an old writer still runs. What can happen?

Not quite. The backfill touched only the rows present at the time. Re-read that part ↑

Right. An additive migration gives old and new application versions a period of compatibility.

Which observation should precede requiring every label?

Not quite. A still-active old writer can introduce new gaps. Re-read that part ↑

Right. A still-active old writer can introduce new gaps.

Which exercise tests recovery of previously stored values?

Not quite. A program rollback alone does not restore data. Re-read that part ↑

Right. A program rollback alone does not restore data.

Sources

What you now know

An additive migration gives old and new application versions a period of compatibility.