title: Client-server synchronization over REST
body: <p>This question is about what I think is a very common problem in Android / iOS development but I haven't found any "standard" solution yet.</p>
  
  <p>Let's say we have a fairly normal REST API. The server database contains (among others) the tables <code>countries</code> and <code>towns</code> with a 1:N relationship.</p>
  
  <p>The client (mobile app) wants to maintain a local snapshot of these two tables. So that when it's offline, it can do queries that would be normally done over REST, e.g.: "get a list of Austrian towns with population >= 100"?</p>
  
  <p>How to approach this?</p>
  
  <p>First problem: consistency. The client should have a snapshot of the two tables. If the client downloads updates of the <code>towns</code> table and goes offline, some town may reference a country that's not in the local copy of the <code>countries</code> table.</p>
  
  <p>Second problem: the client should only download the new / deleted / changed rows. Ditch the REST and use some custom RPC call like <code>get_updates_since(...)</code>?</p>
  
  <p>Third problem: how should local changes to the client's copy of the database (possibly made offline) be synchronized with the server? Custom RPC calls?</p>