Feature flags that change stored data

Persistence Senior Swift 5.0+ iOS 17+ Reviewed By Alok Singh

Pick the fix

What is the safe rollout?

Options
Hint 1 of 1

What happens if the flag turns off?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Ship readers for both formats first, then let the flag enable writing the new format; keep reading it if the flag turns off

Correct. Every state stays readable.

Why not the others?
  • B Flip the flag on for everyone, then fix decode crashes. Users get stuck with data their app can't read.
  • C Gate reading and writing on the flag. Turning the flag off would hide data already written in the new format.
  • D Delete local data whenever the flag changes. Users lose data.

30-second answer

Separate reading from writing. First ship a version that can read both old and new formats. Only after that version is widely adopted, let the flag turn on writing the new format. Make turning the flag off safe: the app must still read data written in the new format. Remove the old path only once no supported version can produce it.

Practise saying it · 45 s. No recording, just a timer

Explain how you roll out a data format change behind a flag.

Say your answer out loud, then check which of these points you covered:

  • Expand: read both
  • Then write new
  • Flag off stays safe
  • Contract later

Deep dive

This is the expand-and-contract pattern.

Version every stored record or file.

Data synced across devices may be read by an older app version.

Monitor decode failures by format version.

Common mistakes

  • Gating both reading and writing on the flag.
  • Assuming turning the flag off undoes stored data.

Senior take & follow-ups

Seniors treat flags as reversible, and stored data as not.

Follow-up questions

Think of your answer first, then open the hint.

  1. What if a user has two devices on different versions?

    Show hint

    The older device must tolerate or ignore the new format.

  2. When can you delete the old reader?

    Show hint

    When no supported version or stored data needs it.

Suggest a fix if something here is wrong or out of date.