Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:MaterializeInc Materialize Blue Green Deployment

From Leeroopedia


Knowledge Sources dbt-materialize deploy macros, Materialize ALTER SCHEMA/CLUSTER SWAP documentation, blue-green deployment theory, test_deploy.py integration tests
Domains Deployment Strategy, Zero-Downtime Releases, Database Schema Management
Last Updated 2026-02-08

Overview

Blue-green deployment is a zero-downtime deployment strategy using parallel environments with atomic switchover, specifically leveraging ALTER SCHEMA SWAP and ALTER CLUSTER SWAP for atomic namespace switching.

Description

The Blue-Green Deployment principle provides a strategy for releasing new versions of data models to production without downtime or partial updates. The core idea is to maintain two parallel environments -- the production (blue) environment and the deployment (green) environment -- and atomically swap them once the deployment environment is fully ready.

In the context of a streaming database with materialized views, this principle has specific requirements:

Environment preparation (init):

  • For each production schema, create a corresponding deployment schema (e.g., public becomes public_dbt_deploy).
  • For each production cluster, create a corresponding deployment cluster with identical configuration (size, replication factor, scheduling policy).
  • Copy all grants and default privileges from production to deployment environments.
  • Validate that the user has sufficient permissions (schema ownership, cluster ownership, database create).
  • Validate that production schemas and clusters do not contain sinks (which must be managed separately).

Hydration and readiness (await):

  • After models are built in the deployment environment, all materialized views must hydrate -- that is, catch up to the current state of their upstream sources.
  • A polling mechanism checks replication lag at regular intervals against a configurable threshold.
  • Only when all objects are within the lag threshold is the environment considered ready for promotion.

Atomic promotion (promote):

  • All schema swaps and cluster swaps are executed within a single BEGIN/COMMIT transaction block, ensuring atomicity.
  • ALTER SCHEMA "public" SWAP WITH "public_dbt_deploy" atomically exchanges the two schemas: what was production becomes deployment, and what was deployment becomes production.
  • ALTER CLUSTER "prod" SWAP WITH "prod_dbt_deploy" does the same for clusters.
  • After the swap, sinks that reference objects in the swapped schemas are updated via ALTER SINK ... SET FROM ....
  • A dry run mode logs the swap commands without executing them.
  • A wait mode invokes the await step before promoting.

Cleanup:

  • After promotion, the old deployment environment (which now contains the previous production state) is dropped.
  • DROP SCHEMA IF EXISTS ... CASCADE and DROP CLUSTER IF EXISTS ... CASCADE remove the old environments.

Usage

Apply this principle when:

  • Deploying new or updated dbt models to a production Materialize environment without downtime.
  • Needing atomic cutover of multiple schemas and clusters simultaneously.
  • Implementing CI/CD pipelines for data model changes with rollback capability (before promotion, simply drop the deployment environment).
  • Managing grants and privileges across deployment environments.

Theoretical Basis

The blue-green deployment pattern originates from application deployment practices and is adapted here for database schema management. The key properties are:

  • Atomicity: The swap operation must be all-or-nothing. In Materialize, ALTER SCHEMA SWAP and ALTER CLUSTER SWAP within a transaction provide this guarantee. If any swap fails, the entire transaction rolls back.
  • Isolation: During the swap, other queries see either the old or the new state, never a mix. The transaction isolation of the swap ensures this.
  • Reversibility: Before promotion, the deployment environment can be discarded without affecting production. After promotion, the old production state is in the deployment namespace and can be dropped or retained for rollback.
  • Hydration awareness: Unlike stateless application deployments, a streaming database must ensure that materialized views are fully caught up before swapping. The await mechanism polls replication lag to ensure this readiness condition is met before proceeding with the atomic swap.

The naming convention (_dbt_deploy suffix) is a namespace partitioning strategy that avoids naming collisions while making deployment artifacts easily identifiable.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment