I don't think there is a silver bullet, but the pattern you are looking for is caching. In past projects, I copied items from the server to the local storage (SQLite or flat file) and maintained metadata about records for updating / uploading / cleaning based on simple rules. This is not a simple problem and ends up with a lot of code.
Consistency: in your example, either make sure that you first load the country table, or make two atomic operations β for example, make copies of the βnewβ tables and replace only your cached versions if both copies are completed successfully (doubles storage).
Download only new / deleted / changed: yes, this requires client / server integration - check all entries (with GMT), ask for metadata from the server and go through local metadata that will decide what to do. (UUID hints for strings are useful).
Synchronize local changes: Yes, more client / server integration. See paragraph above.
Handling all exceptions and edge cases is challenging. Take a look at the issues with iCloud syncing CoreData . This may not be a fair comparison, as Apple is trying to solve this problem for a fully distributed database, but nonetheless interesting to read.
source share