Transactional Databases as Sources

Understand ACID transactions, isolation levels, replication and how to extract from production databases safely, including change data capture basics.

Intermediate · about 5 hours · difficulty 3/5

Learn first: SQL Fundamentals

Most business data starts life in an OLTP database such as PostgreSQL or MySQL behind an app. You will extract from these systems constantly, so you need to know how they work and how not to hurt them.

Transactions and ACID

  • Atomicity: all or nothing. Consistency: constraints hold. Isolation: concurrent transactions do not see each other's half-done work. Durability: committed data survives crashes.
  • Isolation levels (read committed, repeatable read, serializable) decide what anomalies you can see. A long extraction query may see a different snapshot from a short one.

Extracting safely

  • Never run heavy analytical queries on the primary database serving customers. Use a read replica.
  • Extract in chunks by primary key or updated_at rather than one giant query.
  • Coordinate with backend teams about indexes on the columns you filter by.

Ways to extract changes

  • Full snapshot: simple, fine for small tables.
  • Incremental by timestamp: needs a reliable updated_at and misses hard deletes.
  • Change data capture (CDC): read the database's write-ahead log (PostgreSQL WAL, MySQL binlog) to capture every insert, update and delete in order. Tools like Debezium do this. Covered more in the ingestion section.

Schema changes

Application teams add and rename columns without telling you. Build extractors that detect schema drift and alert rather than silently dropping data.

Pitfalls

  • Locking a production table with a long-running query during peak hours (say, a sale day).
  • Trusting updated_at when the app does not always set it.

You are ready to move on when you can explain to a backend engineer how you will extract their orders table every hour without affecting the app, and how you will capture deletes.

Key concepts

  • ACID properties
  • Isolation levels
  • Read replicas
  • Snapshot vs incremental extraction
  • Write-ahead log and binlog
  • Hard deletes and soft deletes
  • Schema drift

Mini project

Run PostgreSQL in Docker with an orders table. Write an incremental extractor based on updated_at, then simulate an update, an insert and a hard delete. Document which changes your extractor caught and which it missed.

Check yourself

Why does timestamp-based incremental extraction miss hard deletes, and what are two ways to handle them?

Free resources