Whenever a data pipeline issue is fixed or an enhancement is introduced, managing the movement of changes across environments becomes a crucial part of the development lifecycle.

Without a proper process, controlling and tracking these changes can quickly become challenging.

CI/CD workflows help streamline this process by ensuring consistent, controlled, and reliable deployments across environments.

What is CI/CD?

CI – Continuous Integration: The process of regularly integrating code changes by merging them into managed branches.

CD – Continuous Deployment: The process of deploying scripts (or compiled programs) to the target server or workspace.

CI/CD is a practice where code changes are automatically built and tested whenever developers merge them (CI), and then automatically deployed to staging or production environments (CD). This enables teams to deliver updates faster, more frequently, and with fewer bugs.

What does CI/CD bring to Data Engineering?

Below are the core benefits of maintaining CI/CD workflows:

  1. Automatic integration and deployment
  2. Automatic testing (to some extent)
  3. Same code across multiple environments without code duplication
  4. Rollback management
  5. Controlled promotion with quality gates before deployment

Let’s look at a sample Databricks pipeline with CI/CD enabled.

I’ve developed a sample Databricks project containing a job and a Python file triggered by that job.

The entire project (Databricks Asset Bundle) can be deployed to the Databricks workspace either manually or through CI/CD.

In this demo, we’ll walk through the deployment process using GitHub Actions.

Note: environment secrets to be configured in github secrets for each environment.

Quick explanation for non-databricks readers

The resources folder contains the job definitions that handle orchestration, while the actual transformation logic resides inside the src folder.

The databricks.yml file is the main configuration file for the project. It defines which assets need to be deployed and the target environments, along with their respective environment variables. These variables can be defined directly in this file or maintained in separate files.

The tests folder contains all the unit tests. The pyproject.toml file configures Pytest to discover and run tests, while Ruff is used to enforce code style and maintain code quality.

Demo

Once a PR is raised, the first step (test) in deploy.yml gets triggered and runs the unit tests, while the deployment step is skipped.

Once the PR is approved, the deployment step gets executed. After successful deployment, the developer can merge the PR to ensure the changes are integrated into the target branch.

While promoting to higher environments (by creating and approving PRs), the same code is deployed with the respective environment-specific parameters.

For effective collaboration and change management, adopt the right Git branching strategy along with appropriate approval gates for each environment by defining who is authorized to approve changes.

I’ve written a separate article on Git branching strategies, which is included in the references.

And finally come to the roll-back management.

Roll-back strategy

Ideally, to revert a deployed change, use git revert, create a new PR, and get it approved. This creates a new commit that undoes the changes.

However, there is a quicker approach when the changes have not yet been merged (meaning CI has not happened).

For this, I’ve created another YAML file that deploys the code available in the same branch. If a PR is raised and approved, but an issue is identified after deployment, instead of undoing the changes, we can manually trigger this workflow to redeploy the previous state.

Once the previous state is restored, simply close the PR without merging it.

Note: There is an important caveat when it comes to rollback in data engineering. Once a pipeline is executed one or more times after deployment, the data gets processed, and the state of data objects such as tables may change. Restoring the previous state requires a separate strategy for data recovery and backfilling, which is not covered in this demo.

References

Leave a Reply