What is a database transaction?
Answer out loud or in your head first, then compare.
Answer
A transaction groups several operations into one whole: either we commit all the changes or we roll them back. An example is a transfer: we take money from one account and add it to another. We don't want to save only half of that operation.
Transactions also have rules about how they see concurrent changes. That's called the isolation level. Wrapping code in a transaction doesn't fix every case where two requests try to take the last free spot. You have to choose the right way of writing or locking. A local PostgreSQL transaction doesn't automatically cover a call to an external API.
Drizzle is a library that helps describe tables and write queries from TypeScript. It's an example of an ORM, i.e. a layer connecting program structures to a relational database. It isn't the database itself and doesn't replace understanding transactions — you still have to choose which operations belong in one.
Why it matters: The basis of correct writes and later questions about concurrency.
Possible follow-ups: Why shouldn't you wait for an AI model while holding a lock in the database?
How did it go? Be honest — “Not yet” puts the question on your review list.
Practise in code
- Find the bugs in a queue consumer — guided self-review
Further reading
- PostgreSQL: Transactions tutorial(opens in a new tab)Accessed 22.10.2026. Committing and rolling back a group of changes.
- Drizzle ORM: Overview(opens in a new tab)Accessed 22.10.2026. Describing tables and accessing the database from TypeScript.