Built a microservice which will update column value each time when it is called.

Application stack - Spring boot ,hibernate and mySQL database.

Currently we have listed following approaches in case of concurrency scenarios

  1. Creating a column of datatype timestamp ,assuming the customer holds this timestamp value in request while calling the service . Every call to Update micro service will validate the timestamp present in db with the timestamp present in request if it matches will update else it wont update the database.
  2. Using optimistic locks when updating the database.

Which of the above mentioned approaches would be encouraged for this update micro-service . Any other best practices to solve concurrency ? please do correct me if the above mentioned approaches is not correct/efficient?

  • Whichever, depending on your use case.
    – Telastyn
    Sep 9, 2017 at 14:35
  • 1
    There isn't enough information here about your application's specific requirements to make your question answerable. Normally you just let the database take care of concurrency. Sep 9, 2017 at 15:58
  • Try to be clear about the problem you want to avoid. If you spell out that problem for us, it will help you get clear on the question, and help us answer.
    – joshp
    Sep 9, 2017 at 18:33
  • What microservices have to do with concurrency?
    – Laiv
    Sep 16, 2017 at 19:59

1 Answer 1


the trouble with timestamps is that clients are unlikely to agree on the time.

You are best going with a version number. Instead of saying "i want to update the object" the client should say "i want to update version 4 of the object".

Your service can then check the current version on the database (locking the record) and return a fail if the version doesn't match, or updating if it does.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.