Case study 01 · Love Eden · United Tech · 2025
Rebuilding the save layer of a game that was already live
Eleven services on one base class, seventeen cloud keys collapsed into one, and every existing player migrated in place on a normal weekly release.
- My role
- Senior Unity Developer. Designed, built and maintained this system.
- Constraint
- Live players, no acceptable data loss, a hard 10-key PlayFab write limit
- Outcome
- 85%+ fewer cloud API calls, save latency down from 500–2000ms to 100–300ms
- Stack
- C#StrangeIoCPlayFabNewtonsoft.JsonUniTask
The problem
Persistence had been written feature by feature. Every system had its own save file, its own JSON settings and its own idea of when to write to the cloud, and a background command uploaded everything every ten seconds for every player whether anything had changed or not. Keys had multiplied: one per character for photos and voice messages, seventeen for the player profile alone, each one its own API call.
Worse, the local and cloud paths used different serializer settings, so a field with a `new()` initializer came back from the cloud as null and overwrote a good default. Nothing crashed. The player just found an emptier game than the one they left. And with no write ordering, a device holding a stale copy could overwrite newer progress from another device.
The game was already live, so there was no migration window and no version of this work where existing players could be asked to start over.
What I built
One generic base class that every save domain derives from, owning load, migration, local persistence, cloud sync, debouncing and disposal. A feature team adding a save domain declares a data type, a file name and a cloud key, and inherits correct behaviour for the rest. Eleven services run on it; nine sync to the cloud.
Local and cloud writes share one serializer configuration, so the two stores cannot drift apart by construction rather than by discipline. Keys were consolidated hard: the profile's seventeen became one, per-character photo and voice keys became one each with an in-memory cache giving O(1) state checks instead of string work on every read, and story progress moved to a compact format at roughly 250 bytes per character.
Cloud sync now activates on provider login instead of on a timer, and only for players who have actually linked an account. Guests stay local-only and cost nothing.
Two guards sit in front of every upload. An integrity guard refuses to write a payload that looks like a fresh instance when the service is known to have held real content. A version envelope carries a write counter and the identity of the install that produced the copy, so the newer copy always wins and a stale device is refused rather than allowed to overwrite.
Before and after
| Before | After | |
|---|---|---|
| Save frequency | Every 10 seconds, all players | Provider login, once per session |
| Player profile keys | 17 separate keys | 1 consolidated key |
| API calls per save | 17+ separate calls | 1–8 batched calls |
| Save latency | 500–2000 ms | 100–300 ms |
The envelope nearly sank it. Nine synced services plus nine per-service envelope keys came to eighteen keys per write request, and PlayFab allows ten. Every write was rejected, but reads have no such limit, so everything still loaded and nothing looked broken. Collapsing the envelope into one account-level key brought it to exactly ten. That budget is now full, which is a documented constraint for the next engineer rather than a surprise.
Decisions and trade-offs
A generic base class every domain inherits
instead of an interface each feature implements
An interface would have let eleven teams write eleven slightly different cloud sync implementations, which is the problem I was there to remove. Inheritance is the heavier coupling, and it was the point: correctness lives in one file.
Refuse the upload when the cloud copy is newer
instead of forcing the write through by bumping the counter past the cloud's
An earlier version of the fix did exactly that, and I removed it in review. In a genuine conflict, forcing the write destroys the other device's data with no evidence ours is the better copy. Refusing preserves the cloud, the next fetch updates the device, and no lock forms.
Do not pull the cloud copy when local data already exists
instead of restoring from cloud whenever cloud data is present
Only the login-time batch upload writes progress to the cloud, so the local copy can never be older than the cloud copy. Fetching would overwrite newer local progress with an older cloud one. The rule follows from the invariant, not from intuition.
A partial fetch counts as failure
instead of treating any restored service as success
Success is what triggers clearing local story saves. Under the old rule, one service out of eight restoring was enough to wipe story progress.
Type names excluded from the serialized payload
instead of Newtonsoft's type handling for polymorphic data
Type name handling breaks under IL2CPP on iOS once the linker has had its way. Saves that work in the editor and fail on device are the worst possible bug to find late.
Result
Because every service records a write counter and a writer identity, a save incident is now diagnosable from the device alone. That is how one "my whole session vanished" report turned out to affect every player who had ever reinstalled the app: identity is generated per install, so a reinstall looked like a second device writing concurrently and uploads were refused indefinitely while local saving carried on looking normal. Affected devices recover by themselves on the fixed build, with no migration and no support action.
Every existing player was migrated in place, on a normal weekly release, without a reset.
What I would change
A cloud save replaces the whole payload rather than merging fields, so one account on two devices running different app versions can lose a field the older build does not know about. The mitigation only helps if it is already in the build doing the damaging write, which means shipping it protects future fields and not current ones. That is worth knowing before designing a schema, not after.
This describes architecture and the reasoning behind it. No employer source code is reproduced here.
Building something that has to stay up after launch?