dbt vs Airflow: Which data tool is best for your organization?

Last Updated:

August 29, 2023

August 29, 2023

Noel Gomez
Linkedin

Datacoves Co-founder | 15+ Data Platform Expert.
Solving enterprise data challenges quickly with dbt & Airflow.

Working with data involves bridging the gap between raw data collection and deciphering meaningful insights. Data transformation is at the heart of this process, and a variety of tools are available to facilitate this. Two have risen to prominence: dbt (Data Build Tool) and Apache Airflow. While both are celebrated for their prowess in facilitating data transformations, they have their distinct methodologies and specialties. Let's dive deeper into the nuances, strengths, and challenges that each tool brings to the table.

If you are a data professional trying to navigate the complex landscape of data orchestration tools or an organization looking to optimize its data operations and workflows, then this article is for you. It's essential to understand that when it comes to choosing between dbt and Airflow, it's not necessarily an 'either-or' decision. In many scenarios, pairing both tools can significantly elevate their potential, further optimizing data transformation workflows. 

What is Apache Airflow?

Airflow is a popular open-source tool that let's you author, schedule, and monitor data pipelines. It can be used to orchestrate and monitor complex workflows.

How does Airflow work?

Imagine a scenario where you have a series of tasks: Task A, Task B, and Task C. These tasks need to be executed in sequence every day at a specific time. Airflow enables you to programmatically define the sequence of steps as well as what each step does. With Airflow you can also monitor the execution of each step and get alerts when something fails.

Sample job with 3 tasks

What sets Airflow apart?

Airflow provides flexibility, which means you can script the logic of each task directly within the tool. However, this flexibility might be both a blessing and a curse. Just because you can code everything within Airflow, it doesn't mean that you should. Overly complicated workflows and incorporating too much logic within Airflow can make it difficult to manage and debug. Ensure that when you're using Airflow, it's the right tool for the specific task you're tackling. For example, it is far more efficient to transform data within a data warehouse than to move data to the Airflow server, perform the transformation, and write the data back to the warehouse. 

At the heart of Apache Airflow's appeal is its flexibility when it comes to customizing each step in a workflow. Unlike other tools that may only let you schedule and order tasks, Airflow offers users the ability to define the code behind each task. This means you aren't just deciding the "what" and the "when" of your tasks, but also the"how". Whether it's extracting and loading data from sources, defining transformations, or integrating with other platforms, Airflow lets you tailor each step to your exact requirements. This granularity makes it a powerful ally for those looking to have granular control over their data workflows, ensuring that each step is executed precisely as intended.

While Airflow is powerful, it's important to strike a balance. You should use Airflow primarily as an orchestrator. If mature tools exist for specific tasks, consider integrating them into your workflow and allow Airflow to handle scheduling and coordination. Let specialized tools abstract away complexity. One example is leveraging a tool like Fivetran or Airbyte to perform data extraction from SaaS applications rather than building all the logic within Airflow.

Preferred Airflow use cases

As stated above, Airflow can be used for many things, but we suggest these use cases.

  • Data Extraction and Loading: Airflow can be used to trigger an external tool for data extraction and loading. In cases where tools don't exist, Airflow can be used to call Python scripts or frameworks like dlt to perform data loading.
  • Data Transformation Coordination: Organize, execute, and monitor data pipelines across the entire ELT process. Once data is loaded, trigger a tool like dbt Core to handle the transformation steps in the right sequence and with the appropriate parallelism directly in the data warehouse.
  • ML Workflow Coordination: Trigger and orchestrate machine learning pipelines, ensuring each component from data preprocessing to model refreshes run in sequence after data transformation.
  • Automated Reporting: Initiate generation of various data reports or data extraction to reporting tools, ensuring stakeholders always have access to the latest insights.
  • System Maintenance and Monitoring: Schedule regular backups, send alerts in case of system anomalies, and manage the storage of logs, to ensure your data-driven applications run smoothly.
Airflow DAG with EL, T, and Activation

Airflow benefits

  • Job Management: Set up of workflows and dependencies between tasks in a simple way with a built-in scheduler that handles synchronization of tasks
  • Retry mechanism: It is common to retry some parts, or the whole data pipeline when a task fails. Airflow provides a robust retry mechanism in case of failures that ensure resilience and fault tolerance.
  • Alerting: When something goes wrong, you should know. Airflow helps you by sending alerts to other tools such as email, Slack, or MS Teams
  • Monitoring: The Airflow UI enables you to monitor your workflows
  • Scalability: Airflow can be deployed on scalable infrastructure like Kubernetes. This allows the platform to scale up when more resources are needed and scale down when they are not needed. Combined this helps companies process many tasks quickly without having to pay for a lot of infrastructure that is typically idle
  • Community: Airflow has an active open-source project and there is robust support both on GitHub and Slack. There are also many resources to learn and maintain Airflow.

Airflow challenges

  • Programming Language: Airflow is a Python tool and as such the out of the box experience requires knowing Python to create the Airflow jobs
  • Learning curve: creating workflows as code in Python can be complex and understanding Airflow's concepts like DAGs, operators, and tasks can require time and effort to master
  • Production Deployment: Airflow offers scalability, but setting up a robust infrastructure requires an understanding of technologies like Kubernetes and the host of challenges that come with tuning them
  • Maintenance: Upgrading Airflow and Kubernetes comes with a cost and, like the initial setup, can be challenging for those who don’t work on complex platforms on a regular basis
  • Debugging: identifying root issues in a complex Airflow environment can be challenging. Just knowing where to start requires experience
  • Cost of Ownership: While Airflow is open-source and therefore “free” to use, the complexity of initial setup and ongoing support can be very costly and time consuming.
  • Development experience: To test jobs, developers will need to create a local Airflow environment using tools like Docker which adds complexity and delays to the process

What is dbt?

dbt Core is an open-source framework that leverages templated SQL to perform data transformations. Developed by dbt Labs, it specializes in transforming, testing, and documenting data. While it's firmly grounded in SQL, it infuses software engineering principles into the realm of analytics, promoting best practices like version control and DataOps.

How does dbt work?

Imagine you have a raw data set and you need to transform it for analytical purposes. dbt allows you to create transformation scripts using SQL which is enhanced with Jinja templating for dynamic execution. Once created, these scripts, called "models" in dbt, can be run to create or replace tables and views in your data warehouse. Each transformation can be executed sequentially and when possible, in parallel, ensuring your data is processed properly.

What sets It apart?

Unlike some traditional ETL tools which might abstract SQL into drag-and-drop interfaces, dbt embraces SQL as the lingua franca of data transformation. This makes it exceptionally powerful for those well-acquainted with SQL. But dbt goes a step further: by infusing Jinja, it introduces dynamic scripting, conditional logic, and reusable macros. Moreover, dbt's commitment to idempotency ensures that your data transformations are consistent and repeatable, promoting reliability.

Lastly, dbt emphasizes the importance of testing and documentation for data transformations. dbt facilitates the capture of data descriptions, data lineage, data quality tests, and other metadata about the data and it can generate a rich web-based documentation site. dbt's metadata can also be pushed to other tools such a specialized data catalog or data observability tools. While dbt is a transformative tool, it's essential to understand its position in the data stack. It excels at the "T" in ELT (Extract, Load, Transform) but requires complementary tools for extraction and loading.

Preferred dbt Core use cases

  • Data Transformation for Analytics: Utilize dbt to transform and aggregate data in a manner that's ready for analytical tools, BI platforms, and ML models.
  • SQL-based Workflow Creation: Design and execute SQL workflows with modular components, using the Jinja templating engine for dynamic script generation.
  • Data Validation and Testing: Employ dbt's pre-defined data tests for ensuring data quality and reliability in transformation tasks.
  • Documentation and Lineage: Use dbt's built-in capabilities for auto-generating documentation and establishing clear data lineage, simplifying impact analysis and debugging.
  • Version Control and DataOps: Promote best practices in data operations by utilizing dbt's version control and environment management features, ensuring transformations are consistent and properly tested before deploying to production.

dbt benefits

  • Common knowledge: Since dbt uses SQL and Jinja for data transformation. Many data analysts and data engineers can leverage their existing SQL knowledge
  • Modularity: In dbt each transformation is composed of small steps that are SQL select statements which transform raw data into an analysis-friendly structure. This modularity simplifies understanding, debugging and enable reusability
  • Tests: The ability to add tests to transformation scripts ensure that data is accurate and reliable without needing to introduce additional tools into the data platform
  • Documentation: dbt has an auto-generated website that exposes descriptions, lineage, and other information about a transformation workflow. This makes it easier to maintain the project over time. It also allows consumers of the data to find and understand data before use
  • Debugging: dbt’s data lineage simplifies debugging when issues occur
  • Impact Analysis: By leveraging dbt’s lineage information, we can pinpoint the effects when there's a delay in a data source. This also provides insight into which sources contribute to a specific data product, like an executive dashboard.
  • Open-source: dbt Core is open-source so there is no vendor lock-in
  • Packages and libraries: Thanks to a large community there are many dbt packages, which are pre-defined pieces of reusable functionality, that anyone can reuse in their dbt project. There are also many dbt Python libraries available which extend the functionality of dbt
  • Metadata consumption: dbt produces metadata files that can be consumed by downstream tools like data catalogs and observability tools. This open format is quickly becoming the de-facto standard for sharing information about data across data platforms
  • Community: dbt has a strong and growing community that has over 50k members on Slack alone. There are also a lot of resources making it simpler to find help and there are many examples from others solving similar data problems
dbt Lineage Graph

dbt challenges

  • Data transformation only: As mentioned above, it is the “T” in the ELT pipeline. This means that other parts of the data value chain such as extracting from other applications, loading a data warehouse, or sending the data to downstream processes like marketing automation are not part of dbt and need to be solved with the help of other tools
  • Macros: dbt macros are reusable dynamic code that are a powerful feature, but may be hard to read, debug, and test for analysts who are only accustomed to SQL

Common misconception: dbt means dbt Cloud

A common misunderstanding within the data community is that dbt = dbt Cloud. When people say dbt they are referring to dbt Core. dbt Cloud is a commercial offering by dbt Labs and it is built upon dbt Core. It provides additional functionalities to the open source framework; these include a scheduler for automating dbt runs, alongside hosting, monitoring, and an integrated development environment (IDE). This means that you can use the open source dbt Core framework without paying for dbt Cloud, however, you will not get the added features dbt Cloud offers such as the scheduler. If you are using dbt Core you will eventually need an orchestrator such as Airflow to get the job done. For more information, check out our article where we cover the differences between dbt cloud vs dbt core.

The scheduler: Automating dbt runs

As mentioned above, one of the key features of dbt Cloud is its scheduler which allows teams to automate their dbt runs at specified intervals. This functionality ensures that data transformations are executed regularly, maintaining the freshness and reliability of data models. However, it's important to note that dbt Cloud's scheduler only handles the scheduling of dbt jobs, i.e., your transformation jobs. You will still need an orchestrator to manage your Extract and Load (EL) processes and anything after Transform (T), such as visualization.

Managed dbt Core paired with managed Airflow  

At Datacoves we solve the deployment and infrastructure problems for you so you can focus on data, not infrastructure. A managed Visual Studio Code editor gives developers the best dbt experience with bundled libraries and extensions that improve efficiency. Orchestration of the whole data pipeline is done with Datacoves’ managed Airflow that also offers a simplified YAML based Airflow job configuration to integrate Extract and Load with Transform. Datacoves has best practices and accelerators built in so companies can get a robust data platform up and running in minutes instead of months. To learn more, check out our product page.

Airflow DAG in YAML format

Managing the deployment and infrastructure of dbt Core and Airflow is a not so hidden cost of choosing open source, however, at Datacoves we solve the deployment and infrastructure problems for you so you can focus on data, not infrastructure. A managed Visual Studio Code editor gives developers the best dbt experience with bundled libraries and extensions that improve efficiency. Orchestration of the whole data pipeline is done with Datacoves’ managed Airflow that also offers a simplified YAML based Airflow job configuration to integrate Extract and Load with Transform. Datacoves has best practices and accelerators built in so companies can get a robust data platform up and running in minutes instead of months. To learn more, check out our product page.

Airflow vs dbt: Which one should you choose?

When looking at the strengths of each tool, it’s clear that the decision isn’t an either-or solution, but they each have a place in your data platform. Analyzing the strengths of each reveals that Airflow should be leveraged for the end-to-end orchestration of the data journey and dbt should be focused on data transformation, documentation, and data quality. This holds true if you are adopting dbt through dbt Cloud. dbt Core does not come with a scheduler, so you will eventually need an orchestrator such as Airflow to automate your transformations as well as other steps in your data pipeline. If you implement dbt with dbt Cloud, you will be able to schedule your transformations but will still need an orchestrator to handle the other steps in your pipeline. You can also check out other dbt alternatives.

The following table shows a high-level summary.

dbt vs Airflow: Which tool to adopt first for your data platform?

By now you can see that each tool has its place in an end-to-end data solution, but if you came to this article because you need to choose one to integrate, then here is the summary.

If you're orchestrating complex workflows, especially if they involve various tasks and processes, Apache Airflow should be your starting point as it gives you unparalleled flexibility and granular control over scheduling and monitoring.

An organization starting out with basic requirements may be fine starting with dbt Core, but when end-to-end orchestration is needed, Airflow will need to play a role.

If your primary focus is data transformation and you're looking to apply software development best practices to your analytics, dbt is the right answer. Here is the key takeaway: these tools are not rivals, but allies. While one might be the starting point based on immediate needs, having both in your arsenal unlocks the full potential of your data operations.

dbt vs Airflow: Better together

While Airflow and dbt are designed to assist data teams in deriving valuable insights, they each excel at unique stages of the workflow. For a holistic data pipeline approach, it's best to integrate both. Use tools such as Airbyte or Fivetran for data extraction and loading and trigger them through Airflow. Once your data is prepped, let Airflow guide dbt in its transformation and validation, readying it for downstream consumption. Post-transformation, Airflow can efficiently distribute data to a range of tools, executing tasks like data feeds to BI platforms, refreshing ML models, or initiating marketing automation processes.

However, a challenge arises when integrating dbt with Airflow: the intricacies of deploying and maintaining the combined infrastructure isn't trivial and can be resource-intensive if not approached correctly. But is there a way to harness the strengths of both Airflow and dbt without getting bogged down in the setup and ongoing maintenance? Yes!

Conclusion

Both Apache Airflow and dbt have firmly established themselves as indispensable tools in the data engineering landscape, each bringing their unique strengths and capabilities to the table. While Apache Airflow has emerged as the premier orchestrator, ensuring that tasks and workflows are scheduled and executed with precision, dbt stands out for its ability to streamline and enhance the data transformation process. The choice is not about picking one over the other, but about understanding how they can be integrated to provide a comprehensive solution.

It's vital to approach the integration and maintenance of these platforms pragmatically. Solutions like Datacoves offer a seamless experience, reducing the complexity of infrastructure management and allowing teams to focus on what truly matters: extracting value from their data. In the end, it's about harnessing the right tools, in the right way, to chart the path from raw data to actionable intelligence. See if Datacoves dbt pricing is right for your organization.

Author:

Noel Gomez

Looking for an enterprise data platform?

Book a Demo

Table of Contents