Isolation levels and the anomalies they prevent
Isolation is the I in ACID, and the letter databases quietly weaken by default for speed. Senior interviews ask which races your design is exposed to and how you'd stop each one.
A shared whiteboard
An office plans the week on one big whiteboard that people read and write all day. There are four ways to work with it:
- read whatever is there, even a line someone is halfway through writing, which they may rub out → read uncommitted
- read only finished lines, but from the live board each time, so two glances can disagree → read committed
- take a photo when you start and work only from the photo: everything fits together, but it's an old picture → snapshot isolation, which some databases call repeatable read
- let one person plan at a time, or have a referee make sure the result is as if they did → serializable
The trouble case: two people each photograph the board, both see room 3 free at 2 pm, and both write their meeting in. Each was right on their own photo. Together, they double-booked the room: write skew. In database terms, the whiteboard is the database and each person working from it is a transaction.