Skip to main content

Transactional Database: Definition, Examples, and Uses

18 min read

Transactional Database: Definition, Examples, and Uses cover

When you order food for delivery a lot happens in less than a second. The app creates the order and charges the customer's wallet, reserves the last two portions of biryani at the restaurant and assigns a delivery partner. If the payment goes through, but the order record is never saved, the customer is charged for food they never receive. If two customers reach for the last piece at the same time, one of them is going to leave unhappy.

That's what a transactional database stops from happening. It makes sure that each group of related changes is fully carried out or not at all, even if thousands of users are writing at once. This guide covers what a transactional database is, how it works, the ACID properties behind it, the architecture, popular systems, and the design practices and challenges of running one.

What Is a Transactional Database?​

A transactional database is a database that is designed to reliably record and update data through transactions. Transactions are sets of operations that either succeed or fail as a group. These databases deal with the daily writes behind applications: placing orders, moving money, booking seats, and updating inventory. They are often called OLTP (online transaction processing) databases.

It is designed for many small, fast operations. It stays correct even when many people are doing things at the same time. One checkout might only affect a few rows, but the database might be handling thousands of checkouts a second. And each one has to leave the data in a consistent state.

Two comparisons come up often. Transactional vs. analytical is a question of workload, while transactional vs. relational is a question of data model, and the two are not opposites. Most transactional databases are relational, such as PostgreSQL and MySQL, but some NoSQL databases, like MongoDB, also provide multi-document ACID transactions.

AspectTransactional (OLTP) databaseAnalytical (OLAP) database
Main jobRecord and update live business dataAnalyze large amounts of historical data
Typical queryRead or write a few rows by keyScan and aggregate millions of rows
Storage layoutRow-orientedUsually column-oriented
UsersApplications and servicesAnalysts, BI tools, data scientists
Data freshnessCurrent, changes every secondLoaded or replicated from source systems
ExamplesPostgreSQL, MySQL, Oracle, SQL ServerSnowflake, BigQuery, ClickHouse, Trino on Apache Iceberg

Most companies need both though. The application runs on the transactional database and its data is copied into an analytical system, usually a data warehouse or data lake, where reporting queries won't slow down the app.

How Does a Transactional Database Work?​

Transactional databases work by wrapping related changes within a transaction. Until they are complete, the changes are invisible to everyone else, at which point they are logged and success is confirmed. Checkout is a great way to see the steps for food delivery.

Food delivery checkout transaction: begin, run statements in isolation, write to the WAL, commit or roll back, flush data pages later

sql
BEGIN;
INSERT INTO orders (order_id, customer_id, restaurant_id, total)
VALUES (98231, 5512, 77, 420.00);
UPDATE wallets
SET balance = balance - 420.00
WHERE customer_id = 5512 AND balance >= 420.00;
UPDATE menu_stock
SET portions_left = portions_left - 2
WHERE item_id = 3104 AND portions_left >= 2;
COMMIT;
  1. The transaction starts. The application starts a transaction and the database assigns it an ID and a consistent view of the data.
  2. Each statement executes in isolation. The order insert, wallet update and stock update are applied, but other sessions cannot see them until commit. Row locks or multi-version concurrency control (MVCC) stop two checkouts from taking the same last portions.
  3. The changes are written to the log first. The database writes the changes to a write-ahead log (WAL), which is sometimes referred to as a redo log or transaction log, on durable storage before it can confirm anything.
  4. The transaction commits or rolls back. If all steps are successful, COMMIT makes all three changes visible at once. If there is not enough money in the wallet or the stock is gone, the matching UPDATE changes zero rows, so the application checks the row count and issues a ROLLBACK and the database rolls back all the changes made in that transaction.
  5. Data pages are updated later. The changed rows are kept in memory, and are flushed to the data files in the background. If the server crashes before that happens, the database replays the log on restart so no committed order is ever lost.

That log has a second purpose. Change data capture (CDC) tools read every committed insert, update and delete to stream it into other systems. This is how transactional data typically makes its way to a data warehouse or data lake without slowing down the application.

Key Characteristics of Transactional Databases​

Due to the nature of the work transactional databases do, they have a series of common characteristics.

  • High concurrency. Thousands of users read and write at the same time, and the database coordinates them so that nobody overwrites anybody else's changes.
  • Short, frequent operations. The vast majority of transactions touch just a handful of rows and run in milliseconds, while analytical queries can scan billions of rows.
  • Row-oriented storage. Rows are stored together on disk, so reading or updating a complete record (like a single order) is fast.
  • Strong consistency. Constraints, foreign keys and transactions ensure that the data is always valid, meaning that a payment can never refer to an order that doesn't exist.
  • Normalized schemas. For example, you might have a customers, orders and order_items table. This way you don't have to duplicate the data and it is easier to update.
  • Indexed lookup paths. B-tree indexes on primary keys and common filters let the database find a row among millions, in just a few page reads.
  • Durability and recovery. Write-ahead logging, backups, and replication are used to protect committed data against crashes and hardware failures.
  • Low latency. Applications expect answers in milliseconds because a slow database means a slow checkout page.

ACID Properties in Transactional Databases​

ACID stands for atomicity, consistency, isolation and durability. These four properties, called ACID properties, are guaranteed by a transactional database for each transaction.

Atomicity means that it is all or nothing. In the checkout example, the order insert, the wallet charge, and the stock update either all commit or all roll back. We never charge a customer for an order that has not been placed.

Consistency means that all transactions leave the database in a valid state. Things like CHECK (balance >= 0), foreign keys and unique keys are enforced on each commit. So if a transaction would result in a negative wallet balance, it is rejected.

Isolation means that concurrent transactions do not have unexpected influences on one another. If two customers try to buy the last two portions at the same time, isolation makes sure that only one of them will succeed. SQL provides four standard isolation levels, each trading some protection for more concurrency:

Isolation levelDirty readsNon-repeatable readsPhantom reads
Read uncommittedPossiblePossiblePossible
Read committedPreventedPossiblePossible
Repeatable readPreventedPreventedPossible in the SQL standard
SerializablePreventedPreventedPrevented

Defaults vary across systems. The default isolation level in PostgreSQL is read committed and in MySQL with InnoDB it is repeatable read. So the same application code can behave slightly differently under heavy concurrency depending on the database underneath it.

Durability means that once a transaction commits, it stays committed even if the server crashes a moment later. Databases do this by flushing the write-ahead log to disk before acknowledging the commit, and many also replicate the log to standby servers.

Types of Database Transactions​

There are a few different types of transactions, depending on how they are initiated, the number of systems they affect and their duration.

  • Implicit transactions (autocommit). Most databases (by default) treat every statement as its own transaction. A single UPDATE executes and commits immediately.
  • Explicit transactions. The application encloses a few statements between BEGIN and COMMIT, like in the checkout example. This is the normal choice when more than one change must succeed together.
  • Read-only transactions. These only read data, for example to create an order summary page. Declaring the transaction read-only allows some databases to avoid locking work and send the query to a replica.
  • Savepoints and nested transactions. A SAVEPOINT is a point in a transaction which you can roll back to without losing all of the transaction. If applying a coupon fails, checkout can roll back to the savepoint and continue without the discount.
  • Distributed transactions. If a business action touches multiple databases, a protocol (e.g., 2PC) coordinates the commits across the databases. It gets the job done, but it's slow and brittle, which is why so many teams shy away from it.
  • Sagas (long-running business transactions). Microservice architectures usually decompose a large workflow (e.g., order, payment and delivery assignment) into a chain of local transactions. If a step fails, instead of rolling back a single database transaction, the saga runs compensating actions like issuing a refund.

Transactional Database Architecture​

Under the hood, most transactional databases follow a similar architecture, even when the products look very different from the outside.

Transactional database architecture: client connections and pooler, query processing, transaction manager, buffer pool, write-ahead log, storage engine and replicas

  • Client connections. Applications connect over the network, most typically through a connection pooler such as PgBouncer or the pool built into the application framework. Pooling is important because it is costly to create a new database connection for every request.
  • Query processing. The parser checks the SQL, the planner/optimizer determines the cheapest way to run it (e.g. using the index on customer_id instead of scanning the whole orders table), and the executor executes the plan.
  • Transaction manager. This component provides transaction identifiers, tracks active transactions, and enforces isolation by locks, MVCC, or both. MVCC allows readers to see a snapshot of committed data and does not block writers, which is a big part of why databases like PostgreSQL and MySQL handle mixed read and write traffic well.
  • Buffer pool. Commonly used data pages are stored in memory for fast access. Reads are served from the buffer pool when the page is already there, and go to disk only when it is not. Writes modify the pages in memory first.
  • Write-ahead log. All modifications are logged and flushed to disk before a commit is acknowledged. The log is the single source of truth for crash recovery, replication and change data capture.
  • Storage engine and data files. Data files hold tables and indexes. Indexes are typically B-trees. Background processes write dirty pages from the buffer pool to these files and clean up old versions of rows.
  • Replicas. Most production deployments stream the log to one or more replicas, which provide failover if the primary goes down, and can serve read-only queries to take load off it.

Transactional Database Examples​

Most of the apps people use on a daily basis have transactional databases behind them. Here are a few common examples to give an idea of the range of workloads they handle.

  • Payments and banking. In a UPI payment, the bank debits the sender's account and writes the corresponding ledger entry in one transaction, and after each one the books have to balance to the paisa.
  • E-commerce and food delivery. Checkout, inventory, coupons, and wallet balances all update together like the example used throughout this guide.
  • Ticketing and reservation. Airline, train, cinema and hotel booking systems use isolation to prevent two people ending up with the same seat or room, even when a popular show opens for booking and thousands of users click at the same time.
  • Inventory and supply chain. Warehouses record every pick, pack and shipment, so stock levels are accurate across locations and orders are never promised against stock that's already gone.
  • Healthcare systems. Patient records, prescriptions and appointment schedules must all be updated accurately and be auditable. A dropped write can have real consequences.
  • SaaS apps. In almost every SaaS product, user accounts, subscriptions, permissions, and billing records sit in a transactional database like PostgreSQL or MySQL.
  • Gaming. Transactions are used for in-game purchases, virtual currency and item trades so players can't double spend coins by sending two requests at the same time.

The transactional database market ranges from decades-old relational systems to distributed databases built for global scale. The table below covers the systems teams choose most often.

DatabaseTypeKnown for
PostgreSQLOpen-source relationalStrong standards support, MVCC, rich extensions such as PostGIS and pgvector
MySQLOpen-source relationalInnoDB engine, simple replication, huge web and SaaS adoption
MariaDBOpen-source relationalMySQL fork with its own storage engines and features
Oracle DatabaseCommercial relationalEnterprise features, Real Application Clusters, deep tooling
Microsoft SQL ServerCommercial relationalTight integration with the Microsoft and Azure ecosystem
MongoDBDocument (NoSQL)Flexible JSON documents with multi-document ACID transactions
Amazon AuroraManaged relational (MySQL and PostgreSQL compatible)Cloud-native storage layer, fast failover, read replicas
Google Cloud SpannerDistributed SQLGlobal consistency across regions using synchronized clocks
CockroachDBDistributed SQLPostgreSQL wire compatibility, serializable isolation by default
YugabyteDB, TiDBDistributed SQLHorizontal scaling with PostgreSQL or MySQL compatibility

PostgreSQL or MySQL are the sensible defaults for most new applications. A managed version such as Amazon RDS, Aurora, Google Cloud SQL or Azure Database takes away most of the operational work. Distributed SQL databases earn their added complexity when a single primary can no longer keep up with writes, or when data has to live in several regions at once.

Transactional Database Performance and Scalability​

A transactional database usually performs well right up until the day it does not, and that day tends to arrive during a sale, a product launch, or the evening dinner rush. Knowing the levers ahead of time makes that day much calmer.

  • Indexing. Most slow queries come down to a missing or unused index. An index on orders (customer_id, created_at) turns "show my recent orders" from a full table scan into a few page reads. Too many indexes slow down writes, though, so each one should earn its place.
  • Query tuning. EXPLAIN ANALYZE shows how the database actually ran a query. Rewriting a query to avoid SELECT *, fixing an N+1 pattern in the application, or adding a LIMIT often helps more than any hardware upgrade.
  • Connection pooling. Each connection uses memory on the server, and PostgreSQL in particular starts a separate process per connection. A pooler keeps a small set of connections busy instead of thousands sitting idle.
  • Vertical scaling. Moving to a larger machine with more CPU, memory, and faster storage is the simplest fix, and modern servers can take a single primary surprisingly far.
  • Read replicas. Sending read-only traffic, such as order history pages, to replicas frees the primary for writes. Replicas lag slightly behind, so anything that must read its own write should still go to the primary.
  • Partitioning. Splitting a large table by date or region, such as monthly partitions of orders, keeps indexes smaller and makes it cheap to drop old data.
  • Sharding and distributed SQL. When writes outgrow a single primary, data can be split across several databases by a shard key such as restaurant_id, either manually or by a distributed SQL database that handles it automatically.
  • Offloading analytics. Heavy reporting queries compete with checkouts for CPU and I/O. Replicating data into an analytical system, for example by streaming CDC changes into Apache Iceberg tables with a tool such as OLake Go, lets analysts run large queries without touching the production database.

Transactional Database Design Best Practices​

Good transactional database design is mostly about keeping transactions small, data valid, and the schema easy to change later.

  • Keep transactions short. Open the transaction, make the changes, and commit. Never wait for a user, an external API call, or a payment gateway response while holding locks, because every other checkout touching those rows will wait too.
  • Let the database enforce the rules. Primary keys, foreign keys, NOT NULL, UNIQUE, and CHECK constraints catch bad data that application code will eventually miss.
  • Normalize first, denormalize with a reason. Start with a normalized schema to avoid duplicate data, and only copy values into other tables when a measured performance problem calls for it.
  • Pick the right isolation level. Read committed is fine for most work. Use serializable, or explicit row locks with SELECT ... FOR UPDATE, for operations like seat booking where a race condition costs money.
  • Make writes idempotent. Network retries happen. An idempotency key on the orders table stops a double tap on the "Place order" button from creating two orders.
  • Index for real query patterns. Look at the queries the application actually runs, add indexes that match them, and remove indexes nobody uses.
  • Use exact numeric types for money. Store amounts as NUMERIC or as integers in the smallest unit, such as paise, never as floating-point numbers.
  • Plan schema changes carefully. Add columns as nullable first, backfill in batches, and avoid long table locks on busy tables. Tools such as gh-ost or pg_repack help with large changes.
  • Keep analytics off the primary. Route reporting to replicas or, better, replicate data into a separate analytical store so a large report never slows down checkout.

Common Transactional Database Challenges​

As traffic increases, even well-designed transactional databases suffer from a familiar set of problems.

  • Lock contention and deadlocks. If many transactions update the same hot rows, e.g., stock count for a popular dish, they get queued behind each other. If two transactions each hold a lock that the other needs, the database detects a deadlock and cancels one of them. Short transactions and a consistent order of updating rows reduce both problems.
  • Write scaling limits. A traditional setup still only has one primary that all writes go to. Read replicas help with reads. Once that headroom is exhausted the options are a bigger machine, sharding, or a move to distributed SQL. None of them is free.
  • Bloat and upkeep. MVCC retains old row versions until they are cleaned up. If autovacuum lags in PostgreSQL, tables and indexes can grow larger than necessary, and queries can slow down.
  • Replication delay. Replicas apply changes a little later than the primary. The customer may not see their order if they check their order history right after placing an order and the order history page reads from a lagging replica.
  • Schema migrations on live systems. Adding an index or changing a column type on a table with hundreds of millions of rows can lock it for minutes, which is not an option for an app that never sleeps.
  • Analytics on production. Often, teams will start by running reports off the transactional database. As data grows, those queries fight with customer traffic and eventually cause outages. The usual fix is to move analysis to a separate system, often fed by CDC.
  • Backup and high availability. Point-in-time recovery, backup testing and failover all require constant attention. A backup that has never been restored is only a hope that it will work.

Conclusion​

A transactional database is the system of record for almost every application, from food delivery checkouts and bank transfers to seat bookings and SaaS billing. Its job is narrow but hard: take a steady stream of small writes from many users at once and keep each of them correct. This is enabled by ACID transactions, write-ahead logging, MVCC, and careful indexing. As traffic grows, replicas, partitioning, and distributed SQL help it scale.

The teams that do best with their transactional databases keep their transactions short, use constraints to protect their data, and move the heavy analytics somewhere else. That last step is where many data platforms start.

OLake Go reads the change log of transactional databases such as PostgreSQL, MySQL, MongoDB, and Oracle and replicates every committed change into Apache Iceberg tables, so analysts can query fresh data without adding load to production. OLake Fusion then keeps those Iceberg tables fast with compaction, delete-file cleanup, and metadata trimming.

Next steps

Related posts