Javascript – How to handle parallel requests, different response time and atomicity of transactions

client-serverdesignjavascripttransaction

I have a table of data and I can create , update and delete rows. I have apis to do these operations. The following steps happen

  1. I create a row and send a create request to server.
  2. I update some values in the row and send an update request before the response of create has come.
  3. In server since the create row has not completed, the update cannot continue.

How do I handle this situation? Should I make an update request only after success of create? Should I queue the request on server?

If the create fails, should I remove the rows on client? or should I retry the request? Need help on how to deal with this. Thanks

Best Answer

Well, the simplest solutions would be either sequence the operations on the client-side, by waiting for the creation to return before sending the update, or send both operations in a single command so they can be sequenced on the server side.

It's hard to recommend specific approached because you haven't really told us much about your requirements, i.e. do you have performance requirements that are not met if you wait for the creation response before sending the update?

If the create fails, should I remove the rows on client? or should I retry the request?

Again this depends on your requirements and the reason for the failure. If the failure was due to a network timeout then retrying might make sense, but if it was due to invalid data than retrying would be pointless...

Related Topic