2

I have an API in which we expect a emailID and a certain deal data. The case is we want to keep the dealId and contactId(email) to be unique. Creating a deal requires data insertion in multiple tables.

data is first inserted in tb_contact_email. Then , it is inserted in tb_deals , tb_contacts and tb_contact_details

If two deal creation hits come simultaneously from the same contact , the second hit is able to ascertain that tb_contact_email record exists. However,the second hit is not able to find the record in tb_deals because the first call is still in the process.

We cannot ignore the second hit because we expect to create a note related to that deal from the second hit. How to handle this architecture problem.

6

That's what database transactions were invented for. All modifications during a transaction are either written to the database at once on commit, or none are written in case they would conflict with a parallel transaction. If your transaction fails due to a conflict, you will need to retry the operation from the start using the new consistent database state.

0

[bold emphasis mine]

data is first inserted in tb_contact_email. Then , it is inserted in tb_deals , tb_contacts and tb_contact_details

That right there is your whole problem. The data shouldn't be first inserted here and then inserted there. It should be inserted here and there at the same time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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