liveBook · Manning

Atomicity

As explained in Data Pipelines with Apache Airflow, Second Edition

An atomic transaction is an indivisible database transaction whose operations either all take effect or have no effect.

Atomicity means treating related operations as an indivisible unit: everything completes successfully, or nothing changes. In Airflow, an atomic task either produces its proper result or fails without leaving misleading partial state. section 3.7.1

A task that calculates user statistics, writes them to a file, and then sends an email is non-atomic. If the email service fails, the task is marked failed even though the statistics file already exists. Separate calculation from notification so each task reports its own outcome. section 3.7.1

Design atomic Airflow work by considering both task boundaries and operational dependencies:

  • Split independent operations when a failure in one should not invalidate the result of another. section 3.7.1
  • Keep tightly coupled steps together when one operation requires state created immediately by another, such as authentication followed by an API request. section 3.7.1
  • Wrap multi-statement database changes in a transaction so deletion and replacement either both succeed or neither does. section 13.6

Replacing interval-specific database rows

A data pipeline can delete existing rows for an Airflow execution date and insert the refreshed DataFrame rows inside one database transaction. If either operation fails, the transaction leaves no incomplete replacement behind. section 13.6

How Data Pipelines with Apache Airflow, Second Edition covers it

How deep it goes
Defines all-or-nothing behavior, demonstrates task decomposition, and applies transactions without detailing database isolation internals.
Examples
Uses user statistics and email delivery, API authentication, and pandas database replacement as concrete cases.
What it assumes
Teaches the database meaning of atomic transactions before applying the idea to Airflow task design.
What you can do after
Apply it via Airflow by separating independent work and wrapping related database changes in transactions.
How it connects
Connects atomicity with Airflow tasks, task dependencies, idempotency, database transactions, and backfilling.

Also explained in

Compare how 13 books explain atomicity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Pipelines with Apache Airflow, Second Edition. The section links point to the parts of the book it draws on.