---
title: 'Database Transactions Explained'
source: 'https://youtube.com/watch?v=tPjfFlT-BEw'
video_id: 'tPjfFlT-BEw'
date: 2026-08-04
duration_sec: 63
---

# Database Transactions Explained

> Source: [Database Transactions Explained](https://youtube.com/watch?v=tPjfFlT-BEw)

## Summary

This video explains the concept of database transactions, focusing on the problem they solve and the underlying mechanism of the write-ahead log (WAL). It uses a simple example of transferring money between accounts to illustrate the need for atomicity and how WAL ensures data integrity even after a crash.

### Key Points

- **The Problem: Inconsistent Transfers** [00:01] — Moving $500 between accounts involves two writes: subtract from Alice, add to Bob. If the server crashes between them, Alice loses $500 with no record, leaving the database inconsistent.
- **Solution: Transactions as Atomic Units** [00:27] — Wrapping both writes in a single transaction makes them an atomic unit: either both happen or neither. This ensures consistency.
- **Mechanism: Write-Ahead Log (WAL)** [00:40] — Before modifying data on disk, the database writes intended changes to a write-ahead log. On restart after a crash, the log is used to redo committed transactions and undo uncommitted ones, preventing half-written data.

### Conclusion

Transactions, powered by write-ahead logging, are essential for maintaining data integrity in databases, ensuring that operations are atomic and recoverable even in the event of a crash.

## Transcript

you respond? We'll start with the problem. So, you're moving $500 between bank accounts. You subtract from Alice's account, and you add to Bob's. You would run those two rights one after another, but your server crashes in between. Now,
Alice is down $500, and there's no record of where it went. The money just vanished, and your database has no idea that anything is wrong. This is why transactions exist. You wrap both rights in a single transaction, and the
database will treat them as a single atomic unit. Meaning either both happen, between. But, the real answer your interviewer wants is how, and the mechanism is what's called a write-ahead log, or WAL. Before the database touches
any data on disk, it writes the intended changes to this log first. Then, if the server crashes mid-transaction, the database uses that log on restart, flushed to disk yet, and undoing work from transactions that never committed.
The data on disk is never left half-written. Learn more at half-written. Learn more at hellointerview.com.
