What’s a reliable way to sync offline edits across multiple devices?

0
0
Asked By VelvetOrbit42 On

I'm building a personal media tracker with clients on Linux and Android, plus an always-online server that acts as a backup and synchronization point. Each client should work offline and sync whenever a connection becomes available.

My current design stores an edit timestamp for every field, along with a version number for each record and another version for the database. During synchronization, each device would send records with newer versions, then compare incoming field timestamps with its own and keep the most recent value.

However, I'm concerned that device clocks can drift or be temporarily incorrect. Is relying on epoch timestamps safe for resolving conflicts in a personal application, or should I use logical clocks, operation logs, or another approach?

3 Answers

Answered By MildCedar7 On

For a personal tracker, clock drift may be small most of the time because phones and computers regularly synchronize their clocks, but wall-clock time still isn’t guaranteed to be correct. A clock can be off by seconds or minutes, especially when a device has been offline, so timestamps alone can incorrectly decide which edit wins.

A safer approach is to give every device its own ID and track a local counter for each change. Exchange changes using those counters, and use the device ID only as a deterministic tie-breaker when two edits are otherwise incomparable. That way every device reaches the same result without trusting its system clock.

Answered By CopperLynx31 On

Content hashes can help determine whether two records or media files are actually identical, but they don’t establish which conflicting edit happened later. They’re useful alongside synchronization metadata, not as a replacement for it.

For a more advanced design, look into logical clocks, hybrid logical clocks, or CRDTs. They’re designed for this kind of offline, multi-device conflict resolution, although a per-device operation log is probably simpler and more than sufficient for a personal media tracker.

Answered By QuietMaple88 On

An append-only operation log is a good fit here. Each device records operations such as “set rating” or “mark as watched” and numbers its own operations 1, 2, 3, and so on. During synchronization, devices exchange operations the other side hasn’t seen, then apply them according to your conflict rules.

This works offline and avoids repeatedly comparing complete database snapshots. You’ll still need to decide what happens when two devices edit the same field, but that rule can be deterministic—for example, choose the operation with the higher logical counter and use the device ID to break ties.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.