Architecture for data layer that uses both localStorage and a REST remote server
- by Zack
Anybody has any ideas or references on how to implement a data persistence layer that uses both a localStorage and a REST remote storage:
The data of a certain client is stored with localStorage (using an ember-data indexedDB adapter). The locally stored data is synced with the remote server (using ember-data RESTadapter).
The server gathers all data from clients. Using mathematical sets notation:
Server = Client1 ? Client2 ? ... ? ClientN
where, in general, a record may not be unique to a certain client.
Here are some scenarios:
A client creates a record. The id of the record can not set on the client, since it may conflict with a record stored on the server. Therefore a newly created record needs to be committed to the server - receive the id - create the record in localStorage.
A record is updated on the server, and as a consequence the data in localStorage and in the server go out of sync. Only the server knows that, so the architecture needs to implement a push architecture (?)
Would you use 2 stores (one for localStorage, one for REST) and sync between them, or use a hybrid indexedDB/REST adapter and write the sync code within the adapter?
Can you see any way to avoid implementing push (Web Sockets, ...)?