r/learnprogramming • u/qellyree • Sep 29 '26
Solved How do I sync a media tracker's database across multiple devices that update offline?
Hi, I'm building a personal media tracker, and I've been trying to figure out how to sync my databases. I plan to have multiple clients: one for my Linux machine, one for my Android phone, and a server that's just an always-online node so I can back everything up in one place. The catch is that I want the tracker to work offline and only sync when I'm connected.
My idea is to store a timestamp (in epoch time) for the last edit of each field, plus a version number for each entry and one for the whole database. When two databases sync, each one checks the other's database version and sends over every entry with a higher version number. Then each database goes through the incoming changes, compares each field's timestamp against its own, and keeps the most recent edit.
The problem is that I've heard epoch time isn't reliable across devices because each device's clock can drift. Does that mean I can't use timestamps to compare edits, or is the drift small enough that I'll never notice it? If the drift is significant, what else could I use?
(Sorry if this is a dumb question or if my explanation isn't very clear.)
3
u/Stainlessray Sep 30 '26
Content aware hashing and epoch time should be fine for comparing versions if the versions are indexed.
If you are scanning media across multiple devices that may be on/off during any given operation you pretty much need to treat everything as individual.
Matchmaking by name or content won't cut it. You need name, hash, content, hash, timestamp.
Same name? Check content. Same content? Check name. Same both? Check index time.