Transaction: A sequence of database operations treated as an atomic unit — either all succeed or all are rolled back. Transactions follow ACID properties (Atomicity, Consistency, Isolation, Durability). A database transaction groups several operations into one unit: either all of them succeed, or none do. If anything fails halfway, the database rolls back to the state before the transaction started.
Creating an order with its order lines, deducting stock and recording a payment are typical examples. Without a transaction, a crash halfway could leave an order without lines, or stock deducted for an order that does not exist.
What should you keep in mind with Transaction?
In Laravel, wrap related writes in DB::transaction(function () { ... }); an exception inside rolls everything back. Keep transactions short, because they hold locks that make other requests wait. Do not call external services, such as sending emails or charging a card, inside a transaction. Do those after the commit, so a rollback cannot undo the database while the email was already sent.