What is Database Transaction?

Turkish: Veritabanı İşlemi (Transaction)

A database transaction groups reads and writes into one unit of work that either commits completely or rolls back safely.

What is Database Transaction?

A database transaction treats several database steps as one unit of work. If every step succeeds, COMMIT makes the changes permanent. If any step fails, ROLLBACK undoes the changes. This prevents half-created orders, missing stock updates, or inconsistent balances.

How It Works

In a payment flow, a transaction may approve the order, write the payment record, reduce inventory, and enqueue an accounting event. If the inventory step fails, the previous writes are rolled back. The database manages this behavior with locks, isolation levels, and write-ahead logging.

ACID Properties

ACID defines transaction behavior through four properties:

  • Atomicity: The operation happens completely or not at all.
  • Consistency: The database stays within valid rules.
  • Isolation: Concurrent transactions see each other in controlled ways.
  • Durability: Committed data survives failures.

Design Tradeoffs

If a transaction scope is too wide, it can cause locks, waiting, and throughput problems. If it is too narrow, a business rule may be split across unsafe steps. A connection pool is also affected by long transactions because open transactions hold database connections. In SQL systems, transaction boundaries should match both the business rule and the database cost.