Handling concurrency in rest api