Skip to content
AB

Designing Stable Health Sync Identities Across Android Devices

Prevent duplicate history by deriving server identity from semantic data instead of installation-local rows.

Ashish BhakhandPublished

Room primary keys are local implementation details. After reinstall or on a second phone, the same historical health fact can receive another local identity.

For imported event records, preserve the platform record ID and source where it is stable. For derived daily snapshots, construct a semantic key:

Code
user + local day + domain + metric + identity version

Hash or convert that key into the server's required identifier and enforce uniqueness there.

Identity and merge policy are separate. Two uploads may refer to the same daily snapshot but contain different freshness. Decide whether the newest source update replaces the old value, fields merge, or the server recomputes from events.

Version identity formats. Changing the coordinate set without a version can silently collide with old records.

Keep source provenance for diagnostics without exposing device identifiers broadly. Logs can use the identity version and a safe hash.

Test reinstall, second-device import, overlapping history windows, concurrent uploads, and an upgraded identity algorithm. The correct key is the one that represents the business fact across installations.

← Back to all writing