I'm working on a basic syncing algorithm for a user's notes. I've got most of it figured out, but before I start programming it, I want to run it by here to see if it makes sense. Usually I end up not realizing one huge important thing that someone else easily saw that I couldn't. Here's how it works:
I have a table in my database where I insert objects called SyncOperation
. A SyncOperation
is a sort of metadata on the nature of what every device needs to perform to be up to date. Say a user has 2 registered devices, firstDevice
and secondDevice
. firstDevice
creates a new note and pushes it to the server. Now, a SyncOperation
is created with the note's Id, operation type, and processedDeviceList
. I create a SyncOperation
with type "NewNot
e", and I add the originating device ID to that SyncOperation
's processedDeviceList
. So now secondDevice
checks in to the server to see if it needs to make any updates. It makes a query to get all SyncOperations
where secondDeviceId is not in the processedDeviceList
. It finds out its type is NewNote
, so it gets the new note and adds itself to the processedDeviceList
. Now this device is in sync.
When I delete a note, I find the already created SyncOperation
in the table with type "NewNote". I change the type to Delete, remove all devices from processedDevicesList
except for the device that deleted the note. So now when new devices call in to see what they need to update, since their deviceId is not in the processedList
, they'll have to process that SyncOperation
, which tells their device to delete that respective note.
And that's generally how it'd work. Is my solution too complicated? Can it be simplified? Can anyone think of a situation where this wouldn't work? Will this be inefficient on a large scale?