Data Structures19 sections · 729 units
Open in Course

Application: Database Snapshots

Point-in-time queries

Databases use persistence for:

Snapshots: Query database state at a past time MVCC (Multi-Version Concurrency Control): Each transaction sees a consistent snapshot

class MVCCDatabase:
    versions: persistent B-tree

    function beginTransaction()
        return current version number

    function read(txn, key)
        return versions.get(txn, key)

    function write(txn, key, value)
        // Creates new version, doesn't affect txn's reads
        versions.set(key, value)

You never block writers when reading. Each transaction sees the version from its start time.

PostgreSQL, MySQL InnoDB, and many others use MVCC with persistent structures.