# Apache Airflow

**Apache Airflow** 是一个开源平台，用于将工作流定义为有向无环图（DAG），并进行调度和编排，支持类 cron 的定时调度和功能丰富的 Web 界面。<sup>[1](https://link.springer.com/chapter/10.1007/979-8-8688-0602-5_12)</sup><sup> • </sup><sup>[2](https://dmtn-025.lsst.io/)</sup> 它最初由 Airbnb 开发，现已成为主流的开源工作流编排器，在 2025 年 Airflow 3.0 发布时，月下载量超过 3000 万次，有 8 万家组织在使用。<sup>[3](https://ijctjournal.org/wp-content/uploads/2022/05/Survey-of-Cloud-Native-Workflow-Orchestration-with-Apache-Airflow.pdf)</sup><sup> • </sup><sup>[4](https://airflow.apache.org/blog/airflow-three-point-oh-is-here/)</sup>

| 关键事实 | 详情 |
|---|---|
| 功能 | 将工作流定义为 Python 任务组成的有向无环图，进行调度和编排，支持类 cron 的定时调度和功能丰富的 Web 界面<sup>[1](https://link.springer.com/chapter/10.1007/979-8-8688-0602-5_12)</sup><sup> • </sup><sup>[2](https://dmtn-025.lsst.io/)</sup> |
| 数据模型 | 任务通常交换控制流元数据而非批量数据；通过预构建的 Hook 提供与 Amazon S3、Google Cloud、HDFS 等系统的集成<sup>[5](https://cicoe-pilot.org/publications/2019-wms-exploration.pdf)</sup> |
| 执行器 | 本地（单机）、Celery（消息队列工作进程）、Kubernetes（每个任务一个 Pod）<sup>[6](https://api-depositonce.tu-berlin.de/server/api/core/bitstreams/aac06601-38d9-4e2c-be7e-f09c8f9c5e7b/content)</sup> |
| 采用情况 | 月下载量超过 3000 万次，8 万家组织，3000 多名贡献者<sup>[4](https://airflow.apache.org/blog/airflow-three-point-oh-is-here/)</sup><sup> • </sup><sup>[7](https://spectrum.ieee.org/apache-airflow-3-programmatic-workflows)</sup> |
| 生产规模 | Shopify：超过 1 万个 DAG，每天超过 15 万次运行；Etsy：单实例单执行日期超过 3.2 万个任务<sup>[8](https://shopify.engineering/lessons-learned-apache-airflow-scale)</sup><sup> • </sup><sup>[9](https://medium.com/apache-airflow/configuring-the-kubernetesexecutor-to-hum-at-etsy-94c2924e9526)</sup> |
| Airflow 3.0（2025） | 任务执行接口/任务 SDK 客户端-服务器分离、DAG 版本控制、调度器管理的回填、基于 FastAPI 的 API 服务器、事件驱动调度<sup>[4](https://airflow.apache.org/blog/airflow-three-point-oh-is-here/)</sup> |
| 安全模型 | 任务子进程永不直接访问元数据数据库；工作进程持有短期凭证并与执行 API 通信<sup>[10](https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/overview.html)</sup> |

## 概述

一个业务工作流，例如“提取订单、转换、加载到仓库、然后发送报告邮件”，被写成一个 DAG：每个步骤是一个声明了依赖关系的任务，调度器按依赖顺序和计划触发任务。Springer 出版的一本书中的一章将该平台描述为将工作流定义为 DAG 并进行调度和编排的工具，支持与数据存储和处理系统的广泛集成。<sup>[1](https://link.springer.com/chapter/10.1007/979-8-8688-0602-5_12)</sup>

两个设计要点塑造了建立在其上的一切。第一，任务通常交换控制流元数据而非批量数据。<sup>[5](https://cicoe-pilot.org/publications/2019-wms-exploration.pdf)</sup> 第二，Rubin 天文台/LSST 的一项调查指出 Airflow 的两大优势是动态工作流生成（“配置即代码”）和功能丰富的 Web 用户界面，同时指出由于它是为 ETL 编写的，尚不清楚它在多大程度上适合面向 HPC 的环境。<sup>[2](https://dmtn-025.lsst.io/)</sup>

## 历史与治理

Airflow 始于 Airbnb，该公司用更丰富的调度器、Web 界面和算子库对 Python-DAG 方法进行了推广；此后它成为主流的开源编排器，而 Prefect、Dagster 和 Temporal 则针对其编程和运维模型中为人所感知的弱点。<sup>[3](https://ijctjournal.org/wp-content/uploads/2022/05/Survey-of-Cloud-Native-Workflow-Orchestration-with-Apache-Airflow.pdf)</sup> 开发活动非常活跃：项目贡献者 Koka 告诉 IEEE Spectrum，下载量从 2.0 版本时每月几百到一千次增长到平均每月 3500 万到 4000 万次，社区有 3000 多名贡献者。<sup>[7](https://spectrum.ieee.org/apache-airflow-3-programmatic-workflows)</sup> 项目自身的公告称 3.0 发布时月下载量超过 3000 万次；两个数字不同，此处均予报道。<sup>[4](https://airflow.apache.org/blog/airflow-three-point-oh-is-here/)</sup>

## 架构与工作原理

当前文档对组件的描述如下。*调度器*负责触发计划的工作流并将任务提交给执行器；执行器是调度器的一个配置属性，而非独立组件，运行在调度器进程内。*Dag 处理器*从 Dag 包中解析 Dag 文件并将其序列化到元数据数据库，通常是 [PostgreSQL](https://www.edgepedia.org/zh/postgresql) 或 MySQL，存储任务、Dag 和变量的状态。<sup>[10](https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/overview.html)</sup> 较早的一项调查描述了一个五组件视图，其中 Web 服务器暴露 UI 和 REST API，日志存储层与调度器、执行器和数据库并列。<sup>[3](https://ijctjournal.org/wp-content/uploads/2022/05/Survey-of-Cloud-Native-Workflow-Orchestration-with-Apache-Airflow.pdf)</sup> 一本教科书的处理则增加了触发器（Triggerer）和 API 服务器/元存储，协调解析、调度、排队和运行任务。<sup>[11](https://www.manning.com/preview/data-pipelines-with-apache-airflow-second-edition/chapter-1)</sup>

扩展性主要受任务执行方式的限制：由于任务实例不共享池，且它们之间不会重用任何东西，并发运行 N 个任务实例需要 N 个子进程，外加任务自身代码创建的任何额外进程。工作进程的规模规划必须为峰值并发任务实例留出预算。<sup>[10](https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/overview.html)</sup> Airflow 可以在单机上运行，但设计为在分布式环境中扩展，各组件运行在不同机器上，具有不同的安全边界。<sup>[10](https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/overview.html)</sup>

## 执行器与部署

- **LocalExecutor** 在同一台机器内并行运行任务，适合小规模部署。
- **CeleryExecutor** 使用消息队列将任务分发到多个工作进程，适合较大的分布式系统。
- **KubernetesExecutor** 在各自的 [Kubernetes](https://www.edgepedia.org/zh/kubernetes) Pod 中启动每个任务，按工作负载动态扩展。

权衡是具体的。KubernetesExecutor 每个任务有约 2 到 5 秒的 Pod 创建延迟，加上冷节点上的镜像拉取时间，该调查建议在偏好严格容器隔离时用于大约 100 到 500 个 DAG 的中等规模部署。<sup>[3](https://ijctjournal.org/wp-content/uploads/2022/05/Survey-of-Cloud-Native-Workflow-Orchestration-with-Apache-Airflow.pdf)</sup> 一个在 Kubernetes 上运行 Airflow 的团队发现，Pod 启动等待时间有时超过任务本身的运行时间，而且长时间运行的任务在集群缩容期间 Pod 被驱逐时会失败；在切换到使用固定工作节点的 CeleryExecutor 后，dbt 作业的平均运行时间显著下降，因为任务不再等待 Pod 启动，KEDA 自动扩缩器通过官方 Helm chart 根据 Airflow 数据库中运行中和排队中的任务来扩展 Celery 工作进程。<sup>[12](https://medium.com/apache-airflow/what-we-learned-after-running-airflow-on-kubernetes-for-2-years-0537b157acfd)</sup> Grab 使用基于内存和 CPU 参数的水平 Pod 自动扩缩器加上 EKS 集群自动扩缩器来扩展工作进程。<sup>[13](https://engineering.grab.com/the-journey-of-deploying-apache-airflow-at-Grab)</sup> 为实现高可用性，Adyen 运行三个 Celery 工作进程、三个调度器和三个 Web 服务器，由 NGINX 和 Keepalived 作为前端，使 Web 流量始终到达存活的 Web 服务器。<sup>[14](https://www.adyen.com/knowledge-hub/apache-airflow-at-adyen)</sup> 托管产品也存在；[Amazon MWAA](https://www.edgepedia.org/zh/amazon-mwaa) 被一个在 AWS 上运行的团队评估过。<sup>[15](https://engineering.freeagent.com/2025/05/29/decoding-data-orchestration-tools-comparing-prefect-dagster-airflow-and-mage/)</sup>

## 关键特性

**调度与回填。** 调度器支持类 cron 的计划，回填可重新运行过去的区间。在 Airflow 3 中，回填是由调度器管理的一等公民，可通过 UI 或 API 触发，并可在运行中途暂停，不同于 Airflow 2 中回填由 CLI 触发且在 UI 中不可见。<sup>[16](https://www.astronomer.io/blog/intro-to-airflow-3/)</sup>

**数据感知调度。** Airflow 3 用资产（asset）取代了 Airflow 2.4 引入的数据集（dataset），这是一个扩展的数据感知调度模型，DAG 通过 @asset 装饰的函数定义。<sup>[16](https://www.astronomer.io/blog/intro-to-airflow-3/)</sup> Airflow 3 还增加了事件驱动调度，用于响应 Airflow 外部的事件和数据资产更新。<sup>[4](https://airflow.apache.org/blog/airflow-three-point-oh-is-here/)</sup>

**算子生态系统。** Airflow 是模块化的，提供许多预构建的接口（Hook）来连接常见云和数据库系统，如 [Amazon S3](https://www.edgepedia.org/zh/amazon-s3)、Google Cloud 和 HDFS。<sup>[5](https://cicoe-pilot.org/publications/2019-wms-exploration.pdf)</sup> 在 2025 年 Airflow 现状调查的大型企业用户中，64.4% 报告使用 BashOperator 和 PythonOperator，16.2% 使用 KubernetesPodOperator，30.4% 编写自定义算子和 Hook。<sup>[17](https://www.astronomer.io/images/state-of-airflow/The-State-of-Airflow-2025.pdf)</sup>

## 数据一览

- 3.0 发布时月下载量超过 3000 万次，8 万家组织，较 2020 年的 2.5 万家组织有所增长；超过 30% 的用户将 Airflow 应用于 MLOps，10% 用于 GenAI 工作流。<sup>[4](https://airflow.apache.org/blog/airflow-three-point-oh-is-here/)</sup>
- 2025 年 Airflow 现状调查（N=4,889）报告推荐率超过 90%；员工超过 5 万人的公司中，超过 20% 运行 20 个或更多生产 Airflow 实例，而中型企业为 13.0%，小型企业为 5.4%。<sup>[17](https://www.astronomer.io/images/state-of-airflow/The-State-of-Airflow-2025.pdf)</sup>
- Shopify 在其最大的环境中运行了超过 1 万个 DAG，平均超过 400 个并发任务，每天超过 15 万次运行。<sup>[8](https://shopify.engineering/lessons-learned-apache-airflow-scale)</sup>
- Etsy 在单个生产实例上任意执行日期运行超过 3.2 万个任务，此前从七个 LocalExecutor 虚拟机实例迁移而来。<sup>[9](https://medium.com/apache-airflow/configuring-the-kubernetesexecutor-to-hum-at-etsy-94c2924e9526)</sup>
- Grab 运营着近 20 个 Airflow 实例，每个实例每天调度 1000 到 6 万个作业。<sup>[13](https://engineering.grab.com/the-journey-of-deploying-apache-airflow-at-Grab)</sup>
- 一个团队报告生产中有超过 300 个 DAG，平均每天执行超过 5000 个任务，超过八个月没有发生一次事故。<sup>[12](https://medium.com/apache-airflow/what-we-learned-after-running-airflow-on-kubernetes-for-2-years-0537b157acfd)</sup>

## 与其他编排器的比较

一项比较研究认为，Airflow 提供成熟的、基于 DAG 的任务调度，具有深入的 UI 支持和调度策略，而 Dagster 支持动态的、数据感知的流水线执行、实时内省和类型检查的任务管理。<sup>[18](https://www.informatica.si/index.php/informatica/article/download/9498/5172)</sup> 一份从业者比较将 Airflow 的优势归于类 cron 的调度、回填和复杂依赖窗口，Prefect 归于混合执行模型——敏感任务在本地运行而控制平面托管，Dagster 归于以资产为中心的并行性。<sup>[19](https://branchboston.com/apache-airflow-vs-prefect-vs-dagster-modern-data-orchestration-compared/)</sup> Prefect 自己的比较将 Airflow 描述为一个围绕静态 DAG 构建的遗留平台，带有框架特定的算子，其集中式调度器架构造成性能瓶颈；这是供应商的定性描述，应如此看待。<sup>[20](https://www.prefect.io/compare/airflow)</sup> 尽管如此，从业者仍将 Airflow 描述为历史悠久、社区庞大的行业标准。<sup>[15](https://engineering.freeagent.com/2025/05/29/decoding-data-orchestration-tools-comparing-prefect-dagster-airflow-and-mage/)</sup> 研究工作也将其作为基线：sAirflow 项目在遗留工作流调度器中采用无服务器计算，并考察了 AWS MWAA；在阿里巴巴的暖系统基准测试中，sAirflow 表现与 Airflow 相似，同时将货币成本减半，在高度并行的冷系统工作流上，它可在数秒内扩展到 125 个工作进程，将完工时间缩短至原来的七分之一到二分之一。<sup>[21](https://dl.acm.org/doi/10.1007/978-3-031-69577-3_18)</sup>

## 最新发展

Airflow 3.0 于 2025 年发布，项目称其为历史上最大的版本；2.0 于 2020 年发布，2.10 于 2024 年第四季度发布，其间按季度发布。<sup>[4](https://airflow.apache.org/blog/airflow-three-point-oh-is-here/)</sup> 主要变化：

- **任务执行接口与任务 SDK（AIP-72）。** 被称为 Airflow 历史上最重要的客户端-服务器架构转变之一，支持多云部署和多语言支持，计划在 Python SDK 之后推出 Golang 任务 SDK。<sup>[4](https://airflow.apache.org/blog/airflow-three-point-oh-is-here/)</sup>
- **DAG 版本控制（AIP-65、AIP-66）。** 年度调查中需求最高的功能：DAG 运行基于启动时的版本完成，即使运行中途上传了新版本，版本在 UI 中维护。<sup>[4](https://airflow.apache.org/blog/airflow-three-point-oh-is-here/)</sup><sup> • </sup><sup>[16](https://www.astronomer.io/blog/intro-to-airflow-3/)</sup>
- **调度器管理的回填和事件驱动调度**，以及在 REST API 和基于 FastAPI 的内部 UI API（AIP-84）上重写的 UI，由新的 API 服务器提供服务。<sup>[4](https://airflow.apache.org/blog/airflow-three-point-oh-is-here/)</sup>
- **边缘执行器（Edge Executor，AIP-69）** 作为在边缘设备上运行流水线的提供者包，以及一个新的 'airflowctl' CLI 提供者，使用 API 进行远程访问（AIP-81）。<sup>[4](https://airflow.apache.org/blog/airflow-three-point-oh-is-here/)</sup>
- **安全重构。** 工作进程不再直接写入元数据数据库；任务调用 API 服务器来接收和报告作业状态，减少漏洞并支持在任何地方运行任务。<sup>[16](https://www.astronomer.io/blog/intro-to-airflow-3/)</sup>

## 运维、故障模式与实践中的安全

**元数据膨胀。** Shopify 确定了 28 天的元数据保留策略，通过 PythonOperator 中的 ORM 查询从 DagRuns、TaskInstances、Logs 和 TaskRetries 等表中删除历史行，因为累积的元数据拖慢了 Web 界面并使升级迁移耗时数小时。权衡是，依赖持久作业历史的功能，如长时间运行的回填，在其环境中不受支持。<sup>[8](https://shopify.engineering/lessons-learned-apache-airflow-scale)</sup>

**调度器死锁。** Etsy 出于内部专业知识选择 MySQL 而非社区推荐的 Postgres 加 pgbouncer 方案，但在默认配置下遇到了反复的锁定问题和偶发的死锁。将 AIRFLOW__CORE__MAX_NUM_RENDERED_TI_FIELDS_PER_TASK 从其默认值 30 设为 0，避免了调度器对 rendered_task_instance_fields 表的删除操作——该操作已知会导致死锁；整体调优将任务间平均延迟从超过 10 分钟降至略低于 12 秒。<sup>[9](https://medium.com/apache-airflow/configuring-the-kubernetesexecutor-to-hum-at-etsy-94c2924e9526)</sup>

**工作进程内存。** Celery 工作进程因内存不足而死亡，直到一个团队调整了 worker_max_tasks_per_child 和 worker_max_memory_per_child；KubernetesPodOperator 用于需要运行时隔离和按任务资源请求的自定义作业。<sup>[12](https://medium.com/apache-airflow/what-we-learned-after-running-airflow-on-kubernetes-for-2-years-0537b157acfd)</sup> 一项针对 Celery 部署的实证研究中，该部署在两个调度器上运行 35 个 DAG，配有由 HPA 扩缩的 10 到 40 个工作进程 Pod，将平均队列深度保持在十秒以内，但在缩容期间出现了对 RabbitMQ 的连接风暴和僵尸工作进程 Pod 的积累。<sup>[3](https://ijctjournal.org/wp-content/uploads/2022/05/Survey-of-Cloud-Native-Workflow-Orchestration-with-Apache-Airflow.pdf)</sup>

**增长压力。** OpenAI 在 2025 年 Airflow 峰会上的演讲报告了基础设施故障干扰日常流水线、调度器/元数据数据库/文件 I/O 的压力、工具对用户迭代来说太慢，以及 Airflow 成为业务关键系统的速度快于团队成长的速度。<sup>[22](https://airflowsummit.org/slides/2025/scaling-airflow-at-openai.pdf)</sup> Shopify 另外遇到了文件访问缓慢、对 DAG 能力的控制不足、不规则的流量水平以及工作负载之间的资源争用。<sup>[8](https://shopify.engineering/lessons-learned-apache-airflow-scale)</sup>

**安全态势。** 3.x 设计在信任域之间划分了边界：只有工作进程存储任务的短期凭证并与执行 API 通信，因此元数据数据库永远不会被运行任务代码的子进程以任何语言直接访问。将 Dag 处理器与调度器分离确保调度器无法访问 Dag 包，也无法执行 Dag 作者提供的代码，而 API 服务器只能执行由部署管理员安装为包或插件的代码。<sup>[10](https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/overview.html)</sup>

## References

1. [Orchestrating Data Engineering Pipelines using Apache Airflow, Springer chapter](https://link.springer.com/chapter/10.1007/979-8-8688-0602-5_12)
2. [DMTN-025: A survey of workflow management systems, Rubin Observatory/LSST](https://dmtn-025.lsst.io/)
3. [Survey of Cloud-Native Workflow Orchestration with Apache Airflow, IJCT](https://ijctjournal.org/wp-content/uploads/2022/05/Survey-of-Cloud-Native-Workflow-Orchestration-with-Apache-Airflow.pdf)
4. [Apache Airflow® 3 is Generally Available!, Apache Airflow project](https://airflow.apache.org/blog/airflow-three-point-oh-is-here/)
5. [Exploration of Workflow Management Systems](https://cicoe-pilot.org/publications/2019-wms-exploration.pdf)
6. [Differences in Workflow Systems: A Use-Case Driven Comparison, TU Berlin](https://api-depositonce.tu-berlin.de/server/api/core/bitstreams/aac06601-38d9-4e2c-be7e-f09c8f9c5e7b/content)
7. [Apache Airflow: From Stagnation to Millions of Downloads, IEEE Spectrum](https://spectrum.ieee.org/apache-airflow-3-programmatic-workflows)
8. [Lessons Learned From Running Apache Airflow at Scale, Shopify Engineering](https://shopify.engineering/lessons-learned-apache-airflow-scale)
9. [Configuring the KubernetesExecutor to Hum at Etsy, Apache Airflow Medium](https://medium.com/apache-airflow/configuring-the-kubernetesexecutor-to-hum-at-etsy-94c2924e9526)
10. [Architecture Overview, Apache Airflow Documentation](https://airflow.apache.org/docs/apache-airflow/stable/core-concepts/overview.html)
11. [Data Pipelines with Apache Airflow, Second Edition, Manning](https://www.manning.com/preview/data-pipelines-with-apache-airflow-second-edition/chapter-1)
12. [What we learned after running Airflow on Kubernetes for 2 years, Apache Airflow Medium](https://medium.com/apache-airflow/what-we-learned-after-running-airflow-on-kubernetes-for-2-years-0537b157acfd)
13. [The Journey of Deploying Apache Airflow at Grab, Grab Engineering](https://engineering.grab.com/the-journey-of-deploying-apache-airflow-at-Grab)
14. [Apache Airflow at Adyen: journey to reliability, Adyen](https://www.adyen.com/knowledge-hub/apache-airflow-at-adyen)
15. [Decoding Data Orchestration Tools, FreeAgent Engineering](https://engineering.freeagent.com/2025/05/29/decoding-data-orchestration-tools-comparing-prefect-dagster-airflow-and-mage/)
16. [Introducing Apache Airflow 3, Astronomer](https://www.astronomer.io/blog/intro-to-airflow-3/)
17. [The State of Airflow 2025, Astronomer](https://www.astronomer.io/images/state-of-airflow/The-State-of-Airflow-2025.pdf)
18. [Comparative article on orchestration frameworks, Informatica](https://www.informatica.si/index.php/informatica/article/download/9498/5172)
19. [Apache Airflow vs Prefect vs Dagster, Branch Boston](https://branchboston.com/apache-airflow-vs-prefect-vs-dagster-modern-data-orchestration-compared/)
20. [Prefect vs Airflow, Prefect](https://www.prefect.io/compare/airflow)
21. [sAirflow: Adopting Serverless in a Legacy Workflow Scheduler, Euro-Par 2024](https://dl.acm.org/doi/10.1007/978-3-031-69577-3_18)
22. [Airflow Journey at OpenAI, Airflow Summit 2025 slides](https://airflowsummit.org/slides/2025/scaling-airflow-at-openai.pdf)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Free and open-source software

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/apache-airflow

English original: https://www.edgepedia.org/apache-airflow
