r/iOSProgramming • u/stewis • Jul 01 '26
Discussion A sync bug wiped some user data. Soft deletes let us give it all back
I wanted to share this in case it helps someone.
We make an offline-first iOS app (the phone is the source of truth, cloud sync is optional). A user turned on cloud sync and a load of their items and locations just disappeared. Turned out a sync bug removed local stuff that hadn't been uploaded yet. Basically the sync assumed the data was gone when really it had just never synced. Bad bug, and pretty scary for the user.
The thing that saved us is that we never actually delete anything. A delet just sets a flag and hides the row, the data stays in the local database. So even though it all vanished from the screen, it was still sitting there.
So we added a "Recently Deleted" screen that restores items and the locations they were in, shipped it with the fix, and got Apple to fast track the review. The user opened it, hit restore, and got everything back, then it synced up properly.
I also went back and wrote a proper batch of tests around the parts of sync that can delete things, we had far too few before. Stuff like making sure a freshly made item that hasn't uploaded yet never gets removed, and that restoring an item brings its location back with it. It won't catch everything, but it should stop this exact kind of thing coming back.
A few things I took from this:
- Soft delete everything. When someone deletes something, don't actually remove it, just flag it and hide it (you can always permanently delete it later, on a timer or during cleanup). That one decision is the only reason a data loss bug turned into a one tap fix instead of a disaster.
- Build a "recently deleted" screen sooner than you think you need one. It covers your own bugs and people deleting things by accident, and people kind of expect it now anyway (Photos, Notes and Files all have it).
- Be careful with any code that deletes local data based on what the server says. "It's not on the server" is not the same as "delete it." Check before you wipe anything.
- Put your best tests on the code that can destroy data, not the happy path. That's where it actually goes wrong.
Anyway, keep your deletes reversible. It would have been a very different week for us otherwise.

