dbt: Atomic swap

“atomic swap” usually means performing a schema rename (or object-level rename) in a way that:

  • โœ… Happens instantly (or appears instantaneous to consumers),
  • โœ… Is all-or-nothing (no partial state),
  • โœ… Minimizes downtime and removes risk of inconsistent data.

๐Ÿ” What exactly is swapped?

In most databases (like BigQuery, Snowflake, Redshift), the “atomic swap” is done by renaming schemas or tables:

StepExample
Active schemaanalytics_prod
New build schemaanalytics_prod__temp
Swap actionRename analytics_prod โ†’ analytics_prod__backup Rename analytics_prod__temp โ†’ analytics_prod
ResultAll consumers now point to the new version, instantly

๐Ÿง  Why is it called โ€œatomicโ€?

The term “atomic” comes from database theory, meaning an operation that is:

  • Atomic: not interruptible and not partially applied.
  • Think like a light switch: either it’s ON or it’s OFF โ€” no in-between.

This guarantees that no query ever sees an incomplete transition.


๐Ÿ” Alternative meanings in other systems

In some systems, atomic swaps might be:

  • Switching views instead of schemas (CREATE OR REPLACE VIEW),
  • Swapping pointers (e.g. symbolic links),
  • Or even changing permissions or routing logic.

But in dbt blue-green deployment, it typically means:
๐Ÿ‘‰ Rename the temporary schema to the production schema name.


Leave a Reply

Your email address will not be published. Required fields are marked *