i\'m designing a client-server system via web broswser and i have this problem:
ID: 646195 • Letter: I
Question
i'm designing a client-server system via web broswser and i have this problem: I send the data to the client via JSON, then the javascript view shows the stuff. Then the user takes actions and commands are sent back to the server. Usual stuff, the problem is what if the view's data is corrupted or old? One solution i thought is making a hash via SHA1 or some other algorithm of the full objects in the client's model, but JSON data is not ordered, also this adds delays to the system. How do google docs manages this kind of thing? Also, sending ALL THE DATA, every time the model is updated doesn't make sense, but how do i keep consistency by only sending changes? I think the whole problem is just one.
Explanation / Answer
In most cases, I would probably do it like this:
Store an initial state plus all changes made since that state (all timestamped).
Poll only for changes since the last timestamp retrieved.
If someone posts an update, send the last-seen timestamp with it. If there have been updates since then, deal with that accordingly. (See below)
Periodically, calculate the state of the data at a given time.
When you load the state fresh, only load the last-calculated state plus changes made since that.
When I say "deal with that accordingly," I mean that it very much depends on the case. If I can safely make the second update and send the missing update back to the client, I will do. But sometimes you will want to inform the user of a double update and allow them to make the decision what to do next.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.