I thought a bit about the staging and whether a simple flag about changed records really is a sufficient idea. Such a flag is like the archive attribute of files. For a backup utility doing an incremental backup this attribute is sufficient to decide this file has changed and therefore needs to be backed up. The backup software has the same problem deciding when to reset that flag, it doesn't matter much, if you reset this flag before the backup (or sync) or afterwards - both moments have their pros and cons - in both cases you will not want any modifications of the file (or record) during the backup (or sync). So you could lock the file (record). But that may block any software working with the file (or record), which is bad.
I rather not want to interrupt any software working on the files or data, so I thought about how it could be acceptable software continues to work while I do a snapshot (in both backup or sync case you could call the fetching of changed data a snapshot). How about using a numeric field called "increment", all operations (insert, update, delete) will increment this field.
Say since last sync a record was inserted and updated twice, it will then have an increment value of 3. I copy this record with increment=3 into the staging area and can later reset it to 0, then further updates can increment it again. So it's like 0 is no change and any number >0 means the count of changes. Actually it's not of much interest how many changes there were, we just take the current state anyway and only do one update in the sync target, but now comes the benefit: If we don't simply reset the increment to 0 but decrement the field by the increment we copied to the staging data, most probably the result will be 0, but if there was any further change of the data during syncing, the increment will be decremented to some value >0, which simply is the number of changes after the snapshot, so that change will go into the next sync and will not be forgotten.
So this is better than both a time stamp and a flag. A time stamp would also allow you to see which updates where after the last snapshot, but you'd need to maintain a snapshot time stamp to compare with and the increment number already is indicating how many versions it's ahead of the sync target database.
I hope you haven't begun to change all your application code to set a flag only, you could now increment an integer field instead to have this benefit. It allows to let a snapshot take a while and not lock anything, so syncing can be done in normal, shared mode without risking to skip and forget any update.
Bye, Olaf.