Answer the question
In order to leave comments, you need to log in
How to ensure data consistency in a client-server application?
Good evening. I would like to get an answer to one question. Let's say there is some kind of web application where the client communicates with the server via REST (For example, a combination of Spring mvc and angularjs). Suppose some data was sent from the client side to the server for processing and saving in the database, for example. And here is the question. What should the server return as a response on successful processing? Should it return processed data, or just a SUCCESS 200 status? If it returns processed data, then integrity and consistency is guaranteed, but if the amount of data affects the speed of the request, then this is debatable. If it returns SUCCESS, then all the same processing can be done on the client, but consistency is no longer guaranteed. So who can tell me what best practices are applied in such cases? Hope, that my question is clear. Thank you!
Answer the question
In order to leave comments, you need to log in
Data consistency is ensured by the implementation of the ACID guarantee model . If each REST operation is performed within a separate transaction that satisfies the ACID, the data remains consistent between any transactions. Thus, it is enough to return a notification from each REST call that the transaction is committed.
IMHO, in order to achieve 100% success in all 100% operations, it will be hard to find a single correct solution. That is, each of your operations will need to be coordinated with the server, for data consistency, in the context of the requirements for the speed of the application.
In other words, where speed is required - you "bring" data on the client to the desired state of "consistency" with data from the server, but do not download them (and do not generate them), in other places where speed is not so important - feel free to take data from server.
In general:
If the client needs to send data for processing and show already processed data, then obviously it should be returned.
If the client does not need data, but only needs to perform some action, then it sends the data necessary for this action and receives only a status in response.
The case that you are focusing on is when a large amount of raw data is processed and stored on the server, and then displayed in the processed form on the client. Here you need to look at the situation, the client may be weak in terms of performance and Internet speed, or maybe not, respectively, you can wait for the processed data from the server to the server, or you can send already processed data to it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question