AlgoViz

Concurrency control

medium 27 min

Concurrency control keeps data right when many transactions use it at once.

Where it shows up

The same pattern appears across everyday software.

  • PostgreSQL

    Its manual says that with MVCC reading never blocks writing and writing never blocks reading. Deadlocks are detected and one transaction is aborted.

  • Job tables

    Several workers take rows with FOR UPDATE SKIP LOCKED. Django offers the same as select_for_update with skip_locked.

  • Web APIs

    ETag and If-Match let a server refuse a change that is based on an old copy. RFC 9110 names the lost update problem as a reason.

  • SQLAlchemy

    A version counter column is added to the WHERE clause of updates. If no row matches, a StaleDataError is raised.

  • SQL Server

    Locks rows, pages, tables and more, with intent locks above them. Snapshot isolation uses row versions and must be allowed for the database.

  • SQLite

    One writer at a time for the whole file. For small programs that is the simplest concurrency control there is.