What is Database Concurrency Control?
Concurrency control, told as a story about a packer and a driver reaching for the same box at once.
The packer and the driver both reach for the same box at once.If nobody decides who goes first, the two collide.
When two people edit the count at once, one edit gets erased.The rule that stops lost edits is 'concurrency control'.
Concurrency control is rules that stop simultaneous edits from colliding.Lock the box, order the work, or show separate versions.
Concurrency control has four common methods.MVCC lets reads and writes avoid blocking each other.
The more tightly locks guard the data, the longer the next person waits.The locking method and isolation level together set the safety-speed balance.
Concurrency control is the set of rules — locking, ordering, or versioning — that keeps simultaneous edits from colliding.
Concurrency control preserves correctness when multiple transactions run at once, using techniques like pessimistic locking (e.g. two-phase locking), optimistic concurrency control, timestamp ordering, and MVCC (multi-version concurrency control). It's how ACID's Isolation is actually implemented, and the choice of method shapes both isolation level and performance.
When grown-ups say it
- Pessimistic Locking
- Locking the box up front. Two-phase locking is the classic form.
- Optimistic Concurrency Control
- Trying first, checking for conflicts later. Fast when conflicts are rare.
- Timestamp Ordering
- Ordering work by its start time. Honors arrival order.
- MVCC
- Showing each transaction its own snapshot. Reads don't block writes.
- Deadlock
- Both sides stuck waiting on each other's lock. Happens when a wait cycle forms.
- Isolation Level
- The setting for how strictly to guard simultaneous work. Concurrency control methods realize this level. → how much to hide when hands overlap
- ACID
- The four promises a receipt keeps. Concurrency control is what keeps the Isolation promise. → the four promises a receipt keeps
- Consensus
- A story from the SRE field about servers agreeing. When many servers must agree on one value, they use a consensus algorithm. → consensus