What could be possible alternative solution to implement Idempotency and also handle race condition.
For ex. consider a request to add a customer to System Of Record. The customer detail will have email id as key attribute. And suppose there is API to create customer.
Consider a situation, due to duplicate requests from Client, on a time T1, two requests could land on server to create customer for same email id for ex "xyz@abc.com".
Request 1,Time T1, Email ID "xyz@abc.com" Request 2,Time T1, Email ID "xyz@abc.com"
I was looking for approaches how distributed systems handle Idempotency and Race Condition on a REST API call? I understand there are different approaches like,
- DB Constraint
- Distributed Lock
DB Constraint on column email id, would easily solve this. Also an option of distributed lock or using no-sql approach to check email id in cache before putting record to store is a possibility.
What are other scalable approaches, considering distributed nature?
Why want to avoid constraint is, it has impact on indexing, performance and scale.