The concurrent update problem is something that can happen when multiple database sessions are permitted to update the same data at the same time – which is why it’s called theconcurrent update problem. Whenever a database user connects to the database, a new session is created. Even if the same user connects to the database several times, a separate session is created each time the user connects to the database.
Let’s use an example of a credit card company that issues credit cards to customers and, of course, sends the customers bills and collects payments for the credit card statements.
Let’s say that there is a user X, who works in the accounts receivable department of the credit card company. And, let’s also say that there is a customer B who uses the credit card issued by that company, and he has an unpaid balance of $2,200. Customer B has sent in a payment of $800 for his credit card balance for the month of March, and user X has to process the payment by updating customer B’s total balance due to subtract $800.
But, at that same exact moment, user Y, who works in the billing department is about to update customer B’s balance, because the month of April has just passed and customer B has spent $500 just in the month of April. This means that user Y needs to add $500 to the unpaid balance for customer B.
Here is the sequence of events that take place which lead to the concurrency update problem:
So, from that sequence of events, the balance in the database for customer B is now $2,700. But, the balance should actually be $2,200 – $800 + $500 = $1,900. The real problem here is that the update made by User X has been overwritten by User Y.
This problem could have been avoided with by applying locks, which you can read more about here:Database locking.
Would you like to thankProgrammerInterview.com for being a helpful free resource?Then why not tell a friend about us, orsimply add a link to this page from your webpage using the HTML below.
Link to this page:
Please bookmark with social media, your votes are noticed and appreciated: