What is Isolation
-
In terms of DB, Isolation means concurrently executing
transactions are isolated from each
other
Example:
Two clients simultaneously incrementing a counter that is stored in a database. Each client needs to read the current value, add 1, and write the new value back (assuming there is no increment operation built into the database). The counter should have increased from 42 to 44, because two increments happened, but it actually only went to 43 because of the race condition.
Isolation Levels
-
Defines how much 1 transaction must be isolated from other on concurrent
transactions
1. Read Committed
-
Transactions running at the read committed isolation level prevents
dirty reads. Only those transaction are
visible those are commited
Transactions running at the read committed isolation level prevents dirty Writes by delaying the second write until the first writes transaction has committed
2. Snapshot Isolation (also called multi version concurrency control (MVCC))
-
Snapshot isolation is a solution to
Read Skew problem. Read
Read Skew first. Now how database can
ensure Alice to see correct account balances?
- Database must keep committed version of object(snapshot) and display this version until new data is not committed. Once commit succeeds ie 400$ in Account-1 & 600$ in Account-2, then DB should show most recent commit.
- MVCC: Instead of keeping 2 copies(as in Snapshot isolation), MVCC keeps multiple copies