Trending
Oracle delivered 300,000 GPUs in Q1 FY2027 Your startup is growing but is it actually viable? Property Tax: The Value Driver that AI Data Centers Overlook Hanger to Acquire Numotion in Cash Transaction to Create “Hanger Numotion” Under Patient Square Capital Open standards, closed ecosystems: Is cellular IoT repeating an old telecom mistake? Snapchat launches Plans for organizing events with friends UK telcos lament planning rules, says 5G coverage is being stifled Restoring the Human Connection with AI-Enhanced EHR Workflows The Extinction Risk Preference Cascade: Quotes Study finds AI linked to surges in government complaints Anthropic report says AI model solved CAPTCHAs to upload malware Virgin Media O2 owners consider £600m cost cuts – report DeepSeek launches V4.1-Flash with 1M-token context HelmGuard Raises $7.3M Seed Round | Forus Raises $150M at a $3B Valuation Gemini gets a dedicated app for Windows 10 and 11

How Databases Keep Their Sanity with Concurrency Control

Imagine a bank account with $100. Let’s assume that two separate withdrawal requests of $10 each arrive at the same moment. However, after the two withdrawals are made, the account still ends up $90..

On a purely technical level, both withdrawal requests completed successfully. There was no error. But the account balance is wrong.

The remaining balance should have been $80.. On its own, both transactions were correct. Each read the correct balance and performed the correct calculations.

And yet, there is a bug. The reason for this bug was the overlap between the two transactions.. You might think this type of overlap is a rare condition.

However, this is not true. Overlapping transactions are more or less the normal condition in which databases operate. At any given point in time, multiple processes are trying to write something to a database, often on the same set of records.

It just takes two of them to collide with each other inside a window of a few milliseconds for these types of bugs to show up.. So how do we handle such bugs?. This is what we are going to try to answer in this article.

Here’s what we will cover:. How does data get corrupted due to multiple transactions?. 4 ways the data gets corrupted.

Different ways to handle data conflicts. Block everyone up front (Pessimistic Locking). Gamble and check afterwards (Optimistic Locking).

How databases stopped making readers and writers wait for each other?. Picking the right level of data protection with isolation levels. Strict without slow: the idea that made the safest setting usable.

Summary

 

Join the conversation

Your email address will not be published. Required fields are marked *