transaction

A group of database changes that succeed or fail together, so the data is never left half-updated.

In more detail

A transaction starts with BEGIN and ends with COMMIT, which makes its changes permanent, or ROLLBACK, which discards them. Nobody else ever sees half of a transaction's changes, and if a process dies before committing, the database rolls them back. Keep each transaction short and wrapped around one business action.

Examples

In AWS: A group of database changes that either all happen or none do, so the data is never left half-updated.
The outbox pattern saves the business row and the event row in one transaction.
In the browser: Every IndexedDB read and write runs inside a transaction opened with a mode, readonly or readwrite, and a list of stores. If any request fails or you call abort(), all changes in it are rolled back; it commits automatically when no requests are left.
Spring: @Transactional on a service method wraps it in one transaction.
In this course: Wrapping each test in a transaction that is rolled back at the end is a cheap way to give tests independent data. It cannot test code that commits its own transactions; use a fresh schema or database for those.

Related terms

Taught in

References

Certification courses