openskills.info
Course Preview

Database Transactions and Concurrency

Database transactions group operations into atomic units that either fully complete or fully roll back. Concurrency control mechanisms — locks, MVCC, isolation levels — coordinate simultaneous access so that transactions execute correctly without corrupting shared data.

itDatabases and data storage

Database Transactions and Concurrency

Applications rarely change one value in isolation. A purchase reserves stock, records payment, and creates an order. A transfer debits one account and credits another. These steps describe one business action, even when they require several SQL statements.

A transaction groups those statements into one unit of work. The database either commits the unit or rolls it back. A commit accepts the changes. A rollback discards them.

Transactions also control what happens when many sessions work at the same time. That problem is concurrency. Without a concurrency strategy, valid operations can combine into an invalid result.

Imagine two customers buying the last item. Each session reads a quantity of one. Each then subtracts one. Both purchases may appear successful even though only one item existed. Each statement made sense alone. Their interleaving broke the business rule.

The database gives you mechanisms to prevent or detect that outcome. Your job is to choose the right mechanism, keep transactions bounded, and handle conflicts as expected events.

The transaction boundary

A transaction begins before a related set of reads and writes. It ends with either commit or rollback.

The boundary should match the smallest complete business action. If the boundary is too small, partial work can escape. If it is too large, locks and row versions live longer, conflicts become more likely, and recovery costs grow.

Do not hold a database transaction open while a person reviews a screen or while a service waits on a slow external API. Gather external input first. Then start the transaction, validate current database state, make the changes, and finish.

Savepoints provide a finer control point inside a transaction. You can roll back work performed after a savepoint without discarding earlier work. A savepoint does not make that earlier work visible to other transactions. Only the final commit does that.

Continue the course

This section is part of the paid course.

See pricing to subscribe, or log in if you already have access.

Where this skill leads

Relevant careers

See how this topic contributes to broader role-level skill maps.

Sources