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
- database — A program that stores data in an organised way and answers questions about it, such as PostgreSQL.
- idempotent consumer — A message or webhook handler that produces the same result whether it sees a message once or several times.
- relational database — A database that stores data in tables and links rows in one table to rows in another through shared key values.
- invariant — A rule that must always hold for an object or system, such as a count never being negative.
- ACID — The four guarantees of a database transaction: atomicity, consistency, isolation and durability.
- transactional outbox — Saving an event into an outbox table in the same database transaction as the business change, then having a separate worker publish it.
- Kafka transaction — A group of writes, possibly across several partitions and topics, that Kafka makes visible all together on commit or not at all on abort.
- dev/prod parity — Keeping development, staging and production as similar as possible in timing, people and tools.
- stateless process — A process that keeps nothing it needs between requests in its own memory or disk, so it can be restarted or replaced at any moment.
- unit of work — A pattern that collects the changes made during one business operation and commits them together, or not at all.
- SaveChanges — The DbContext method that writes all tracked inserts, updates and deletes to the database in one transaction.
- atomicity — The property that a group of changes happens completely or not at all, with no half-finished state ever visible.
- IndexedDB — The browser's built-in asynchronous, transactional database for storing large amounts of structured data, including files and binary data.
- object store — The IndexedDB equivalent of a table: a named collection of records, each found by its key.
- persistence context — The set of entities JPA is currently tracking in a unit of work, whose changes it writes to the database automatically.
- service layer — The layer of an application that holds use cases and business rules, sitting between controllers and repositories.
- connection pool — A set of already open database connections that a program reuses instead of opening a new one for each request.
- BEGIN — The SQL statement that starts a transaction, so the following statements form one unit.
- COMMIT — The SQL statement that ends a transaction and makes all its changes permanent and visible to others.
- ROLLBACK — The SQL statement that ends a transaction by undoing every change made since it began.
- isolation level — A setting that controls how much concurrent transactions can see of each other's changes and how they may interleave.
- database commit — The moment a database transaction's changes become permanent and visible, after which the write is acknowledged.
- saga — A sequence of local transactions across services, where each failed step is undone by a compensating action.
- test isolation — The property that each test sets up everything it needs and leaves nothing behind, so tests pass in any order.
Taught in
- The REST Constraints — Modern API Architecture: REST, GraphQL & gRPC
- Actions That Do Not Fit CRUD — Modern API Architecture: REST, GraphQL & gRPC
- Event-Driven Architecture And Queues — Modern API Architecture: REST, GraphQL & gRPC
- Managed Relational Databases (RDS) — Cloud Infrastructure & Hyperscaler Architecture
- When to Pick Which Database — Cloud Infrastructure & Hyperscaler Architecture
- The Payment That Was Charged Twice — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Acknowledged Is Not Always Safe — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- The Error Storm That Fixes Itself — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- The Retry That Overtook — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Two Copies Of One Service — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Stuck On One Record — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Allowed To Read, Refused Anyway — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Seventy One Percent — Confluent Apache Kafka Certifications (CCDAK and CCAAK) Exam Prep
- Build, Release, Run And Processes — DevOps & Site Reliability Engineering
- Disposability, Dev Prod Parity And Logs — DevOps & Site Reliability Engineering
- Querying, Change Tracking, and Saving Data — Modern .NET Core, C# & Enterprise Microservices
- The Repository Pattern — Modern .NET Core, C# & Enterprise Microservices
- IndexedDB In Practice: Object Stores, Indexes And Transactions — Frontend Architecture & Web Platform
- Database Access & Migrations: ORM & Data Layers — Production Full-Stack Engineering
- Asynchronous Event Processing: Outbox Pattern & Queues — Production Full-Stack Engineering
- Full-Stack System Verification: Capstone Integration — Production Full-Stack Engineering
- Persistence With JPA And Hibernate — Modern Java: Virtual Threads & High-Throughput Services
- Spring Data Repositories — Modern Java: Virtual Threads & High-Throughput Services
- Tying It All Together — Modern Java: Virtual Threads & High-Throughput Services
- Dual Writes And Why They Lose Data — Apache Kafka & Event Streaming
- The Transactional Outbox — Apache Kafka & Event Streaming
- Close Phase & Signal Dispatch: Sockets & Teardown — Node.js Internals & Backend Services
- Routing & Middleware: Path Parsing & Async Context — Node.js Internals & Backend Services
- Why Tables And Relations Beat Files — PostgreSQL, Indexing & Relational Data Modeling
- Keys, Constraints And Referential Integrity — PostgreSQL, Indexing & Relational Data Modeling
- Transactions And ACID Properties — PostgreSQL, Indexing & Relational Data Modeling
- Isolation Levels And The Lost Update — PostgreSQL, Indexing & Relational Data Modeling
- What A Design Is For, And How To Run A Design Discussion — Scalable System Design & Distributed Architecture
- The Storage Decision: Relational Versus Document — Scalable System Design & Distributed Architecture
- The Storage Decision: Key Value, Search And Blob — Scalable System Design & Distributed Architecture
- Cache Invalidation And The Three Hard Cases — Scalable System Design & Distributed Architecture
- Idempotency, And Exactly Once As A Fiction — Scalable System Design & Distributed Architecture
- Monolith Versus Services: The Honest Trade Offs — Scalable System Design & Distributed Architecture
- Worked Design One: Ticket Booking, Correctness First — Scalable System Design & Distributed Architecture
- Worked Design One: Scaling The Ticket Booking System — Scalable System Design & Distributed Architecture
- Testing With Real Databases — Automated Testing, TDD & Quality Engineering
References
- PostgreSQL docs: Transactions
- Transactions (EF Core)
- SQLite: transaction
- Spring Framework: Transaction Management
- Spring Framework: Using @Transactional
- MongoDB manual: Transactions