MVCC
A database technique that keeps more than one version of a row so a query can read the right one for its view of the data. An ordinary read can often proceed while another transaction updates that row.
Also known as: многоверсионность
What MVCC does
Multi-version concurrency control (MVCC) lets a database serve readers and writers at the same time. Suppose a report is reading orders while a checkout transaction marks one as paid. Rather than waiting for the update, the report can read the earlier version of that order without seeing the checkout's uncommitted change.
How the database picks a version
An update creates a new logical version of a row and leaves the previous version available to readers that still need it. A snapshot gives the database the information it needs to decide which versions a query can see. It is not a copy of the database. For example, a transaction that was still in progress when the snapshot was taken does not become visible to that snapshot just because it commits later. A transaction can also see changes it made itself before the query, even without committing.
Example: two reads in PostgreSQL
Say order 42 starts with the status new:
| Step | Session | Action |
|---|---|---|
| 1 | A | Begins a transaction and runs SELECT status FROM orders WHERE id = 42. It gets new. |
| 2 | B | Changes the status to paid but leaves the transaction open. An ordinary read in A can still return new without waiting for B. |
| 3 | B | Commits. |
| 4 | A | Runs the same query again. What it sees depends on the isolation level. |
At READ COMMITTED, the second read after B's commit takes a fresh snapshot and returns paid. At REPEATABLE READ, A keeps the snapshot established by its first read and still gets new.
Storage costs and locking
Engines keep version history in different ways. PostgreSQL leaves old row versions in the table until they can be reclaimed. MySQL's InnoDB uses undo records to reconstruct older versions. In both designs, a long-lived snapshot can keep old versions around after updates commit. In PostgreSQL, for example, VACUUM cannot reclaim a row version that an active snapshot might still need. On a frequently updated table, this can contribute to table bloat.
MVCC does not mean the database is lock-free. Two updates to the same row can still contend, and SELECT ... FOR UPDATE explicitly requests row locks. Nor does keeping a stable snapshot make execution serializable: transactions that update different rows can still violate a rule that spans those rows at some isolation levels.
Interview angle
If you're asked whether a second SELECT sees a concurrent update, name the engine and isolation level before answering. Then work through two questions: When did the reader take its snapshot, and was the other transaction committed at that point? If the query is a locking read, account for its locking behavior as well.