# Apache Beam

Apache Beam 是一个开源、统一的编程模型，用于定义批处理和流式的数据并行处理管道，同时还包含让开发者编写此类管道的软件开发工具包，以及在 [Apache Flink](https://www.edgepedia.org/zh/apache-flink)、[Apache Spark](https://www.edgepedia.org/zh/apache-spark) 和 [Google Cloud Dataflow](https://www.edgepedia.org/zh/google-cloud-dataflow) 等分布式处理后端上执行这些管道的运行器<sup>[1](https://beam.apache.org/get-started/beam-overview/)</sup>。用 Beam SDK 编写的管道只需表达一次业务逻辑，原则上便可在任何受支持的执行引擎上原样运行，无论是开源运行器，还是 Google Cloud Dataflow、Amazon Kinesis Data Analytics 这类托管云服务<sup>[2](https://beam.apache.org/about/)</sup>。该项目起源于 Google，其 Cloud Dataflow SDK 于 2016 年 1 月捐赠给 Apache 软件基金会；该项目于 2017 年 1 月成为该基金会的顶级项目<sup>[3](https://cloud.google.com/blog/products/gcp/cloud-dataflow-20-sdk-goes-ga)</sup>。

| 关键事实 | 详情 |
|---|---|
| 是什么 | 一个开源、统一的模型，用于定义批处理和流式的数据并行处理管道<sup>[1](https://beam.apache.org/get-started/beam-overview/)</sup> |
| 起源 | Google Cloud Dataflow SDK 于 2016 年 1 月捐赠给 Apache 软件基金会；董事会跟踪的项目成立于 2016-12-20<sup>[3](https://cloud.google.com/blog/products/gcp/cloud-dataflow-20-sdk-goes-ga)</sup><sup> • </sup><sup>[4](https://apache.org/foundation/board/minutes/Beam.html)</sup> |
| 首个版本 | 0.1.0-incubating，2016 年 6 月 15 日，包含 Java SDK 以及面向 Apache Flink、Apache Spark 和 Google Cloud Dataflow 的运行器<sup>[5](https://beam.apache.org/blog/first-release/)</sup> |
| 顶级项目 | Apache 软件基金会于 2017 年 1 月 10 日宣布<sup>[6](https://news.apache.org/foundation/entry/the-apache-software-foundation-announces)</sup> |
| SDK | Java、Python、Go、SQL、TypeScript 和 Scala（通过 Scio），以及 2.52 版引入的 YAML 配置接口<sup>[2](https://beam.apache.org/about/)</sup><sup> • </sup><sup>[7](https://beam.apache.org/documentation/programming-guide/)</sup> |
| 运行器 | Apache Flink、Apache Spark、Google Cloud Dataflow 和本地 Prism 运行器等，完整列表见能力矩阵<sup>[1](https://beam.apache.org/get-started/beam-overview/)</sup><sup> • </sup><sup>[8](https://beam.apache.org/documentation/runners/capability-matrix/)</sup> |
| 当前版本 | 2.77.0，发布于 2026-10-07<sup>[9](https://beam.apache.org/get-started/downloads/)</sup> |
| 社区 | 截至 2026 年 6 月董事会报告，有 102 名提交者和 26 名项目管理委员会成员<sup>[4](https://apache.org/foundation/board/minutes/Beam.html)</sup> |

## Beam 模型

该模型围绕一小组抽象概念展开<sup>[10](https://beam.apache.org/documentation/basics/)</sup>：

- **Pipeline（管道）**，用户构建的变换图，用于定义所需的数据处理操作。
- **PCollection**，管道所处理的数据集或数据流。PCollection 要么是*有界的*，即大小已知且固定的数据集，适合批处理管道；要么是*无界的*，即随时间不断增长、元素一到达便进行处理的数据集，需要流处理管道。两种类型可以在同一管道中共存<sup>[10](https://beam.apache.org/documentation/basics/)</sup>。
- **PTransform**，应用于零个或多个 PCollection、并产生零个或多个 PCollection 的数据处理操作<sup>[10](https://beam.apache.org/documentation/basics/)</sup>。
- **聚合**，即从一个或多个输入元素计算出一个值；以及**用户定义函数**，让用户代码可以配置变换<sup>[10](https://beam.apache.org/documentation/basics/)</sup>。
- **Schema（模式）**，PCollection 的语言无关类型定义<sup>[10](https://beam.apache.org/documentation/basics/)</sup>。

PCollection 是为大到无法装入单台机器内存的数据而设计的；其元素以统一并行方式处理，而非逐个处理<sup>[10](https://beam.apache.org/documentation/basics/)</sup>。就流处理语义而言，该模型处理窗口（事件时间窗口、水位线和迟到数据）、触发器，以及状态与定时器；能力矩阵围绕四个问题来组织运行器的支持情况：计算出什么结果、在事件时间的何处、在处理时间的何时，以及结果的细化之间如何关联<sup>[8](https://beam.apache.org/documentation/runners/capability-matrix/)</sup>。用户代码有特定的契约：SDK 不是线程安全的，因此创建自有线程的用户代码必须自行提供同步；同时建议做到幂等，因为该模型不保证用户代码可能被调用或重试多少次<sup>[7](https://beam.apache.org/documentation/programming-guide/)</sup>。

## 历史

Apache Beam 由 Google 的多项内部技术发展而来，包括 [MapReduce](https://www.edgepedia.org/zh/mapreduce)、FlumeJava 和 MillWheel；它是那些在 Google 内部支撑其大多数大规模数据处理管道的 SDK 的开源后继者<sup>[11](https://opensource.google/projects/apachebeam?authuser=531)</sup>。2016 年 5 月，Google 资深工程师 Tyler Akidau（[泰勒·阿基道](https://www.edgepedia.org/zh/tyler-akidau)）描述了与 data Artisans、Cloudera、Talend 等公司合作做出的决定：将 Cloud Dataflow SDK 和运行器迁入 Apache Beam 孵化器，目标是打造一个可跨多种运行时平台移植、同时支持流处理和批处理的数据并行处理模型<sup>[12](https://cloud.google.com/blog/products/gcp/why-apache-beam-a-google-perspective)</sup>。

首个版本 0.1.0-incubating 于 2016 年 6 月 15 日发布，包含 Java SDK 以及三个运行器：Apache Flink、Apache Spark 和 Google Cloud Dataflow<sup>[5](https://beam.apache.org/blog/first-release/)</sup>。Apache 软件基金会于 2017 年 1 月 10 日宣布 Beam 毕业成为顶级项目，当时该项目已包含 Java 和 Python SDK，以及面向 Apache Apex、Apache Flink、Apache Spark 和 Google Cloud Dataflow 的运行器<sup>[6](https://news.apache.org/foundation/entry/the-apache-software-foundation-announces)</sup>。Apache 董事会会议纪要记录该项目成立日期为 2016-12-20<sup>[4](https://apache.org/foundation/board/minutes/Beam.html)</sup>。

## SDK 与多语言管道

Beam 的 SDK 在各语言之间呈现同一套编程模型：Java、Python、Go、SQL 和 [TypeScript](https://www.edgepedia.org/zh/typescript)，并可通过 Scio 使用 Scala 接口<sup>[2](https://beam.apache.org/about/)</sup>。多语言能力让团队成员可以用不同语言编写变换，并在同一个管道中一起使用；运行时，Beam 运行器会在单个作业中执行来自两种 SDK（例如 Java 和 Python）的变换<sup>[7](https://beam.apache.org/documentation/programming-guide/)</sup>。

语言支持随每个版本演进。截至 Beam 2.75.0，项目支持 Python 3.10 至 Python 3.14<sup>[13](https://beam.incubator.apache.org/roadmap/)</sup>。YAML 接口自 Beam 2.52 起受支持，目前仍在积极开发中，它让用户可以在配置文件中而非代码中指定管道<sup>[7](https://beam.apache.org/documentation/programming-guide/)</sup>。

## 可移植性框架

早期大多数运行器只支持 Java SDK，因为每种 SDK 与运行器的组合都需要双方做大量工作，而大多数运行器又是用 Java 编写的<sup>[14](https://beam.apache.org/roadmap/portability/)</sup>。可移植性框架通过引入定义明确、语言中立的数据结构和协议解决了这一问题，这些协议称为可移植性 API，构建在 protobuf 和 gRPC 之上<sup>[14](https://beam.apache.org/roadmap/portability/)</sup>。

该框架通过若干契约来分离关注点<sup>[14](https://beam.apache.org/roadmap/portability/)</sup>：

- **Runner API（运行器 API）**，以语言中立的形式表示管道，每个变换都将其执行环境指定为 Docker 容器镜像，从而支持自定义容器。
- **SDK harness（SDK 执行框架）**，由每个 SDK 提供的程序，在运行器之外单独执行用户代码，通过 Fn API 通信；Fn API 是管理任务和传输数据的执行期契约。
- **Provision API 与 Artifact API**，用于获取暂存文件、管道选项和环境信息。

有了可移植的管道执行能力，Flink 和 Spark 运行器默认就能运行来自非 Java SDK 的管道；Flink 运行器可以在批处理和流处理两种模式下运行 Python 管道，而 Spark 在批处理模式下支持 Python<sup>[14](https://beam.apache.org/roadmap/portability/)</sup>。

## 运行器

运行器将 Beam 管道转换为分布式处理后端的 API。概览中提到的受支持后端包括 Apache Flink、Apache Spark 和 Google Cloud Dataflow<sup>[1](https://beam.apache.org/get-started/beam-overview/)</sup>。能力矩阵列出的运行器包括 Google Cloud Dataflow、本地运行器 Prism、Apache Flink、FlareDB、两个 Apache Spark 运行器（分别基于 RDD/DStream 和基于 Structured Streaming）、Hazelcast Jet、实验性的 [Kafka Streams](https://www.edgepedia.org/zh/kafka-streams) 运行器、Twister2 以及 Python 直接运行器 FnRunner；矩阵还表明对各概念的支持程度不尽相同：例如，侧输入在 Dataflow、Prism 和 Flink 上标记为完全支持，在 Spark 运行器上为部分支持，在 FlareDB 和 Python 直接运行器上则不支持<sup>[8](https://beam.apache.org/documentation/runners/capability-matrix/)</sup>。

由于每个运行器的能力各不相同，它们对模型核心概念的实现完整度也有差异<sup>[15](https://cwiki.apache.org/confluence/download/attachments/165227720/Documentation.pdf?api=v2)</sup>，因此 Beam 文档建议用户在选择后端时参考该矩阵。

## 性能与采用

抽象是有可度量代价的。2019 年一项针对 Apache Beam 作为 Apache Spark Streaming、Apache Flink 和 Apache Apex 抽象层的基准研究发现了显著的性能损失：查询执行时间波动很大，与不经过抽象层开发的查询相比，最多慢了 58 倍<sup>[16](https://arxiv.org/abs/1907.08302)</sup>。一份 Beam Summit 演示报告称，Beam 的 Spark 运行器比原生 Apache Spark 慢约十倍<sup>[17](https://apache.googlesource.com/beam/%2Bshow/refs/heads/master/website/www/site/content/en/blog/apache-beam-flink-and-kubernetes.md)</sup>；后来的一项微服务基准测试发现，无论何种用例，使用 Apache Beam 作为抽象层都会带来显著更高的资源需求<sup>[18](https://arxiv.org/abs/2303.11088)</sup>。

作为交换，Beam 适合那些可分解为独立数据束的高度并行任务、ETL 作业和数据集成工作<sup>[1](https://beam.apache.org/get-started/beam-overview/)</sup>。它也可作为其他系统的基础：[TensorFlow Extended](https://www.edgepedia.org/zh/tensorflow-extended) 和 [Apache Hop](https://www.edgepedia.org/zh/apache-hop) 都构建在 Beam 之上<sup>[2](https://beam.apache.org/about/)</sup>；Beam 自己的基准测试套件针对 Dataflow、Spark 和 Flink 运行器运行，用于检测 Beam 各版本的性能回归<sup>[19](https://beamsummit.org/slides/2022/Benchmarks.pdf)</sup>。

## 近期发展

Beam 遵循带例外的语义化版本规范，分别用主版本、次版本和补丁版本递增来表示不兼容变更、新功能和缺陷修复<sup>[9](https://beam.apache.org/get-started/downloads/)</sup>。发布节奏大约每两个月一次：从 2026 年 1 月的 2.71.0 到 2026 年 10 月的 2.77.0<sup>[9](https://beam.apache.org/get-started/downloads/)</sup>。近期版本增加了对 Flink 2.0 的支持（2.72.0）、Java SDK 的 Spark 4 运行器支持（2.74.0）、完整的 [Apache Iceberg](https://www.edgepedia.org/zh/apache-iceberg) 批处理与流处理变更日志（CDC）源以及 Dataflow 流处理运行器中的 [OpenTelemetry](https://www.edgepedia.org/zh/opentelemetry) 跟踪传播（2.76.0），还有 BigQuery、Solace 和 ClickHouse I/O 的改进以及 Java Spark Structured Streaming 批处理模式下的有状态 ParDo（2.77.0）<sup>[20](https://github.com/apache/beam/releases)</sup>。一篇 2026 年的项目博客描述了项目十周年之际、在 2.68.0 到 2.75.0 之间对代码库进行的现代化工作，包括大规模包升级以及使 API 与新语言标准对齐<sup>[21](https://beam.apache.org/blog/)</sup>。

## References

1. [Apache Beam Overview](https://beam.apache.org/get-started/beam-overview/)
2. [About Apache Beam](https://beam.apache.org/about/)
3. [Cloud Dataflow 2.0 SDK goes GA, Google Cloud Blog, June 5, 2017](https://cloud.google.com/blog/products/gcp/cloud-dataflow-20-sdk-goes-ga)
4. [Board history: Beam, Apache Software Foundation](https://apache.org/foundation/board/minutes/Beam.html)
5. [The first release of Apache Beam! (2016/06/15)](https://beam.apache.org/blog/first-release/)
6. [The Apache Software Foundation Announces Apache Beam as a Top-Level Project (January 10, 2017)](https://news.apache.org/foundation/entry/the-apache-software-foundation-announces)
7. [Beam Programming Guide](https://beam.apache.org/documentation/programming-guide/)
8. [Beam Capability Matrix](https://beam.apache.org/documentation/runners/capability-matrix/)
9. [Beam Releases](https://beam.apache.org/get-started/downloads/)
10. [Basics of the Beam model](https://beam.apache.org/documentation/basics/)
11. [Apache Beam, Google Open Source Projects](https://opensource.google/projects/apachebeam?authuser=531)
12. [Why Apache Beam? A Google Perspective, Google Cloud Blog, May 3, 2016](https://cloud.google.com/blog/products/gcp/why-apache-beam-a-google-perspective)
13. [Apache Beam Roadmap Highlights](https://beam.incubator.apache.org/roadmap/)
14. [Portability Framework Roadmap](https://beam.apache.org/roadmap/portability/)
15. [Apache Beam Documentation (Confluence PDF)](https://cwiki.apache.org/confluence/download/attachments/165227720/Documentation.pdf?api=v2)
16. [Quantitative Impact Evaluation of an Abstraction Layer for Data Stream Processing Systems, arXiv:1907.08302](https://arxiv.org/abs/1907.08302)
17. [Apache Beam, Flink, and Kubernetes (beam website source)](https://apache.googlesource.com/beam/%2Bshow/refs/heads/master/website/www/site/content/en/blog/apache-beam-flink-and-kubernetes.md)
18. [Benchmarking scalability of stream processing frameworks deployed as microservices in the cloud, arXiv:2303.11088](https://arxiv.org/abs/2303.11088)
19. [Introduction to the benchmarks in Apache Beam, Beam Summit 2022](https://beamsummit.org/slides/2022/Benchmarks.pdf)
20. [Releases, apache/beam on GitHub](https://github.com/apache/beam/releases)
21. [Apache Beam blog](https://beam.apache.org/blog/)

---
*Initially written Oct 26, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Databases and data systems

Copyright 2026 Edgepedia

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

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

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