DEV Community

Overpush
Overpush

Posted on

Ship Flutter fixes safely: staged rollouts and one-command rollback

Pushing a fix to production is scary. Pushing a fix to every user at once is scarier. If the fix has its own bug, you've just made things worse for everyone.

Web teams solved this years ago with canary releases and instant rollbacks. Mobile apps usually can't: once a build is in the store, it's out. With over-the-air (OTA) updates for Flutter, you can work the same way web teams do.

Here's the workflow I use with OverPush, a code push service for Flutter.

1. Start small: release to 10%

overpush patch android --rollout-percent 10
overpush patch ios --rollout-percent 10
Enter fullscreen mode Exit fullscreen mode

Only 10% of devices get the update. The same devices stay in the 10% over time, so when you go to 50%, the first group keeps the update and new devices join.

2. Watch the numbers

The dashboard shows, for each patch:

  • how many devices downloaded it
  • how many are running it
  • how many failed, and why

Give it an hour or a day, depending on how many users you have.

3. Go wider

Patch numbers count up per release, so if this is patch 4:

overpush patches rollout 4 --percent 50
overpush patches rollout 4 --percent 100
Enter fullscreen mode Exit fullscreen mode

Devices see the new percentage the next time they open the app.

4. Something's wrong? Pull it back

If the patch is bad and the original release code was fine:

overpush patches revoke 4 --reason "checkout total wrong"
Enter fullscreen mode Exit fullscreen mode

On their next launch, devices delete the patch and run the release's own code again.

If patch 4 is bad but patch 3 was fine:

overpush patches rollback --to 3
Enter fullscreen mode Exit fullscreen mode

This serves patch 3's code again, so devices that already took patch 4 move off it.

5. What if the patch crashes the app on startup?

You don't have to do anything. If an update stops the app from starting, the phone goes back to the store version on its own, even offline. Then revoke the patch so no other device tries it.

Cheat sheet

Situation Command
Try a fix on a few users first --rollout-percent 5
Fix looks good, go wider patches rollout N --percent 100
Patch is bad, release code is fine patches revoke N
Patch is bad, previous patch was fine patches rollback --to N
Patch crashes on startup Nothing: devices roll back by themselves

All of these also work from the dashboard: open the release, then ⋮ on the patch.

Try it

How do you ship hotfixes today? Curious to hear what other Flutter teams do.

Top comments (2)

Collapse
 
lycore profile image
Lycore Development •

A stable rollout cohort makes comparisons much easier, but download and startup success would only be my first gate. I would also compare a critical flow such as checkout completion by patch and base release before widening, since a patch can start perfectly and still break the business path. How do you handle a rollback after the patch has changed locally persisted data that the previous code cannot read?

Collapse
 
overpush_dev profile image
Overpush •

Great points, both of them.

On the business-flow gate: agreed, "it starts" is only the first check. The app can read which patch it's running, so you can tag your analytics with it and compare checkout completion for the patch vs the base release:

final int? patch = await OverPush.currentPatchNumber(); // null = the store build
analytics.setUserProperty(name: 'overpush_patch', value: '${patch ?? 0}');
Enter fullscreen mode Exit fullscreen mode

OverPush.crashTags() gives the same thing for Sentry / Crashlytics. Since the rollout cohort is stable, the 10% group stays comparable while you watch it.

On rollback and persisted data: rollback restores code, not data. Once a patch has written something to disk, going back can't undo that write, so the patch itself has to be rollback-safe. What I recommend:

  • Treat local storage changes like a database migration: expand first, contract later. The patch writes the new field or key next to the old one, and the old code keeps reading the old one.
  • Keep a schema version in what you persist, and make readers tolerant of fields they don't know.
  • Don't delete or rewrite the old format until the patch has been at 100% for a while. Do that cleanup in a later patch, or in the next store release.
  • If a change can't be made backward compatible (a format the old code would crash on), ship it in a store release, not a patch.

In short: a patch that only adds data is safe to roll back. A patch that rewrites data needs a plan for the old code reading it.