I have a RESTful API with corresponding clients.
If a client request fetches a set of resources (Events) based on a filter, say events taking place between 2015-04-13 – 2015-04-19. If an event which has previously been synced to the client changes time on the server so that it will be outside of the above time range it, the next request will not include the updated event and the client will not know about the change until it makes a request which includes the updated time.
The solutions I’m thinking of are
- Adding simplistic version management by creating a new events with the updated time which refers to the original event whenever an event is updated. When a request is made the server would have to return the latest version of all the events within the time range.
- Adding a new resource (say EventUpdate) which only tracks time changes of an event leaving sort of a “gravestone” where the Event used to be. Whenever a request is made EventUpdates would have to be checked to see if there previously was an event in the requested time range, if so, these Events should also be included in the response.
Right now I’m leaning towards solution 2. since it seems less overkill for what I need right now.
Is there any standard way of solving this kind of synchronization problem?
3
Is there any standard way of solving this kind of synchronization
problem?
I believe not, but I can propose a system redesign.
Make two API methods instead of one:
- Method returning event ids for events currently scheduled for the specified date interval
- Method returning event details together with updated_at timestamp for a given event ids
If a client wants to check or recheck the specified time range, he uses method #1. If he wants to fetch event details, he uses method #2. #2 will return an event by id even if it has shifted its date.
To minimize traffic for method #2 you can use scheme used by HTTP protocol (If-Modified-Since header).
To make a sync on a client, you can make one by one API calls first to recheck specified interval and then to update all events (those you have ids from the previous calls and those, which were returned by method #1 as new).
Does that solve your case?
6