# Apache Samza

**Apache Samza** 是一个分布式流处理框架，用于构建处理实时数据流的有状态应用，最初由 LinkedIn 开发，以 [Apache Kafka](https://www.edgepedia.org/zh/apache-kafka) 为消息传递基础构建<sup>[1](https://engineering.linkedin.com/data-streams/apache-samza-linkedins-real-time-stream-processing-framework)</sup><sup> • </sup><sup>[2](http://samza.apache.org)</sup>。它提供基于回调的处理 API、托管的本地状态和容错执行，可以运行在 Hadoop YARN、Kubernetes 上，也可以作为独立库使用<sup>[2](http://samza.apache.org)</sup><sup> • </sup><sup>[3](https://github.com/apache/samza)</sup>。

| 关键事实 | 详情 |
|---|---|
| 起源 | 2012 至 2013 年间由 LinkedIn 开始开发；2013 年 9 月 16 日作为 Apache 孵化器项目开源<sup>[1](https://engineering.linkedin.com/data-streams/apache-samza-linkedins-real-time-stream-processing-framework)</sup><sup> • </sup><sup>[4](https://www.linkedin.com/blog/engineering/data-streaming-processing/moving-faster-data-streams-rise-samza-linkedin)</sup> |
| ASF 状态 | 据 LinkedIn 称于 2014 年成为 Apache 顶级项目；ASF 董事会于 2015 年 1 月 21 日正式设立 Apache Samza 项目<sup>[5](https://www.linkedin.com/blog/engineering/open-source/samza-1-0-stream-processing-at-massive-scale)</sup><sup> • </sup><sup>[6](https://apache.org/foundation/board/minutes/Samza.html)</sup> |
| 最新版本 | 1.8.0，2023 年 1 月 17 日发布；更早的版本包括 1.7.0（2022 年 4 月 4 日）、1.6.0（2021 年 1 月 28 日）和 1.5.1（2020 年 8 月 28 日）<sup>[2](http://samza.apache.org)</sup><sup> • </sup><sup>[7](https://release-catalog-test.apache.org/samza/index.html)</sup> |
| 架构 | 三层：流层（Kafka）、执行层（YARN）和处理层（Samza API）；流层和执行层均可插拔替换<sup>[8](https://samza.incubator.apache.org/learn/documentation/0.13/introduction/architecture)</sup> |
| 状态管理 | 通过 RocksDB 维护本地状态，容错方式是将每次写入复制到基于 Kafka 的变更日志，并对状态进行增量检查点<sup>[9](https://blogsarchive.apache.org/samza/entry/announcing-the-release-of-apache1)</sup><sup> • </sup><sup>[5](https://www.linkedin.com/blog/engineering/open-source/samza-1-0-stream-processing-at-massive-scale)</sup> |
| 性能 | 根据 0.13.0 版本说明，在配备 SSD 的单机上峰值达每秒 110 万个事件；在 Samza 1.0 时报告单机每秒 120 万条消息<sup>[9](https://blogsarchive.apache.org/samza/entry/announcing-the-release-of-apache1)</sup><sup> • </sup><sup>[5](https://www.linkedin.com/blog/engineering/open-source/samza-1-0-stream-processing-at-massive-scale)</sup> |
| API | 底层 API、Streams DSL、Samza SQL 和 Apache Beam API；同一份代码可处理批数据和流数据<sup>[2](http://samza.apache.org)</sup> |
| 社区（2026 年） | 31 名提交者和 17 名 PMC 成员；项目在 2026 年董事会报告中被标记为休眠状态；2025 年 7 月 16 日一项终止项目的董事会决议被搁置<sup>[10](https://whimsy.apache.org/board/minutes/Samza.html)</sup> |

## 历史

Samza 脱胎于 LinkedIn 向实时数据架构的迁移。到 2012 年，LinkedIn 已将 Kafka 标准化为所有追踪数据的传输通道，每天有数 TB 数据流入 Kafka，而消费这些消息的应用都面临同样的问题：检查点、管理本地状态、处理故障以及扩展处理能力。Apache Samza 正是为直接解决这些问题而构建的<sup>[5](https://www.linkedin.com/blog/engineering/open-source/samza-1-0-stream-processing-at-massive-scale)</sup>。

LinkedIn 于 2013 年 9 月 16 日宣布 Samza 开源，同时它进入 Apache 软件基金会孵化器<sup>[1](https://engineering.linkedin.com/data-streams/apache-samza-linkedins-real-time-stream-processing-framework)</sup>。团队最初由克里斯·里科米尼领导，他于 2012 年在[杰伊·克雷普斯](https://www.edgepedia.org/zh/jay-kreps)手下开始该项目，后来的贡献者包括[马丁·克莱普曼](https://www.edgepedia.org/zh/martin-kleppmann)、钦迈·索曼、雅各布·霍曼和潘毅<sup>[11](https://materializedview.io/p/from-samza-to-flink-a-decade-of-stream)</sup>。到 2015 年 1 月，该框架已在 LinkedIn 投入生产，运行在多个数据中心的数百台机器上，其最大的作业在高峰流量时每秒处理超过 1,000,000 条消息<sup>[12](https://www.linkedin.com/blog/engineering/open-source/apache-samza-linkedins-stream-processing-engine)</sup>。LinkedIn 称 Samza 于 2014 年成为 Apache 顶级项目；而 ASF 董事会设立 Apache Samza 项目的决议日期为 2015 年 1 月 21 日<sup>[5](https://www.linkedin.com/blog/engineering/open-source/samza-1-0-stream-processing-at-massive-scale)</sup><sup> • </sup><sup>[6](https://apache.org/foundation/board/minutes/Samza.html)</sup>。

2018 年 11 月 27 日发布的 1.0 版本，是 2017 年易用性改进之后的里程碑。它引入了丰富的高层 API、基于事件时间的处理、与 [Apache Beam](https://www.edgepedia.org/zh/apache-beam) 的集成、Samza SQL、无需 YARN 即可运行的独立模式，以及新的测试框架。彼时 LinkedIn 已有超过 3,000 个 Samza 应用在生产中运行，用于异常检测、欺诈预防、性能监控、通知和实时分析，Slack、TripAdvisor、eBay 和 [Optimizely](https://www.edgepedia.org/zh/optimizely) 等其他公司也已采用<sup>[5](https://www.linkedin.com/blog/engineering/open-source/samza-1-0-stream-processing-at-massive-scale)</sup>。此后的版本节奏放缓：2020 年 8 月的 1.5.1、2021 年 1 月的 1.6.0、2022 年 4 月的 1.7.0 和 2023 年 1 月的 1.8.0<sup>[2](http://samza.apache.org)</sup>。Samza 1.8.0 增加了管道排空功能，项目实现了 JDK 11 运行时兼容，并继续推进完全弹性支持（SEP-32）<sup>[6](https://apache.org/foundation/board/minutes/Samza.html)</sup>。

## 架构

Samza 按三层组织，每层都有开箱即用的支持：流层（Kafka）、执行层（YARN）和处理层（Samza API）。这与 Hadoop 的模式如出一辙——YARN 提供执行、HDFS 提供存储、[MapReduce](https://www.edgepedia.org/zh/mapreduce) 提供处理 API。流层和执行层均可插拔替换，开发者可以换用其他实现<sup>[8](https://samza.incubator.apache.org/learn/documentation/0.13/introduction/architecture)</sup>。

流模型是该框架最具决定性的设计选择。在 Samza 中，流是分区的、分区内有序的、可重放的、多订阅者的、无损的消息序列，流不仅是输入和输出，还充当隔离各处理阶段的缓冲区。一个作业可以停止消费数分钟甚至数小时——比如在一次糟糕的部署期间——而不会阻塞上游作业。正是这种隔离使 Samza 适合大型部署，在这类部署中，作业由不同团队编写、拥有和运维，服务水平协议各不相同。代价是消息要写入磁盘，设计者接受这一成本，因为持久化存储能提供高吞吐和几乎无限的空间<sup>[13](https://samza.incubator.apache.org/learn/documentation/0.12/comparisons/introduction.html)</sup>。

在最初的 YARN 部署模式下，Samza 客户端请求 YARN ResourceManager 启动作业；YARN 分配 Samza ApplicationMaster，后者再申请容器来运行承载用户 StreamTask 代码的 SamzaContainer。输入和输出流经 Kafka 消息代理，后者通常与 YARN NodeManager 部署在一起<sup>[8](https://samza.incubator.apache.org/learn/documentation/0.13/introduction/architecture)</sup>。作业通过将工作拆分为任务来扩展，每个任务消费输入分区的一个子集，多阶段管道则通过中间 Kafka 主题对数据重新分区<sup>[5](https://www.linkedin.com/blog/engineering/open-source/samza-1-0-stream-processing-at-massive-scale)</sup><sup> • </sup><sup>[8](https://samza.incubator.apache.org/learn/documentation/0.13/introduction/architecture)</sup>。

## 状态与容错

大多数有用的流处理都是有状态的：按用户统计事件数、在窗口上连接两个流，或用数据库记录丰富事件。Samza 将状态保存在每个节点本地的键值存储中，默认是 RocksDB，因此读取不经过网络。这对吞吐量至关重要：Kafka 每节点每秒处理 100,000 到 500,000 条消息，而对远程键值存储的查询通常只有每秒 1,000 到 5,000 次请求，慢了大约两个数量级<sup>[13](https://samza.incubator.apache.org/learn/documentation/0.12/comparisons/introduction.html)</sup>。

状态的[容错](https://www.edgepedia.org/zh/fault-tolerance)采用变更日志机制。对任务本地存储的每次写入都会复制到基于 Kafka 的变更日志流，故障后通过重放该日志恢复任务状态；ASF 项目文档描述每个任务运行一个变更日志捕获服务，在已知位置记录增量变更。采用增量检查点而非完整快照，正是 Samza 能够扩展到状态极大的应用的原因——每个分区可达数十 GB 量级<sup>[5](https://www.linkedin.com/blog/engineering/open-source/samza-1-0-stream-processing-at-massive-scale)</sup><sup> • </sup><sup>[9](https://blogsarchive.apache.org/samza/entry/announcing-the-release-of-apache1)</sup><sup> • </sup><sup>[3](https://github.com/apache/samza)</sup>。当机器发生故障时，Samza 与 YARN 协作将任务透明地迁移到另一台机器<sup>[3](https://github.com/apache/samza)</sup>。

## API 与集成

Samza 提供多种编程接口：一个形式上类似 MapReduce 的底层回调 API、一个 Streams DSL、Samza SQL 和 Apache Beam API<sup>[2](http://samza.apache.org)</sup><sup> • </sup><sup>[3](https://github.com/apache/samza)</sup>。Beam runner 在 Samza 应用内执行 Beam 管道，可部署到 YARN 集群或带 Zookeeper 的 Samza 独立集群；这两个系统被认为适合大规模有状态流处理作业。Beam 项目自 Beam 2.74.0 起停止了 Samza runner<sup>[14](https://beam.incubator.apache.org/documentation/runners/samza/)</sup>。

输入输出模型是可插拔的。除 Kafka 外，Samza 还可与 HDFS、AWS Kinesis、Azure Event Hubs、键值存储和 [Elasticsearch](https://www.edgepedia.org/zh/elasticsearch) 集成，项目在 0.13.0 版本说明中将 DynamoDB Streams 和 ElastiCache 列为支持的源和汇<sup>[2](http://samza.apache.org)</sup><sup> • </sup><sup>[9](https://blogsarchive.apache.org/samza/entry/announcing-the-release-of-apache1)</sup>。

## 性能与采用

项目公布的性能数据集中在有状态处理上。0.13.0 版本说明报告，一个使用 RocksDB 存储的有状态应用在配备 SSD 的单机上扩展到每秒 110 万个事件；Samza 1.0 公告援引增量检查点和主机亲和性的成果，称单机峰值达每秒 120 万条消息<sup>[9](https://blogsarchive.apache.org/samza/entry/announcing-the-release-of-apache1)</sup><sup> • </sup><sup>[5](https://www.linkedin.com/blog/engineering/open-source/samza-1-0-stream-processing-at-massive-scale)</sup>。LinkedIn 工程师在 2017 年的一篇 VLDB 论文中将 Samza 描述为用于有状态、可扩展流处理的分布式系统，应用无需修改代码即可改变行为，这与流行的 Lambda 架构不同<sup>[15](https://www.vldb.org/pvldb/vol10/p1634-noghabi.pdf)</sup>。

比较文献指出了其典型的权衡。2021 年的一份大数据框架综述将 Samza 的优势列为强大的实时处理能力和简便的多订阅者消息传递，缺点包括仅支持 JVM 语言、不支持精确一次语义、不支持极低延迟<sup>[16](https://www.astesj.com/publications/ASTESJ_060447.pdf)</sup>。2015 年伯克利的一份技术报告指出，由于 Samza 将每个输入都写入磁盘，其整体响应时间比 Storm 慢<sup>[17](https://digicoll.lib.berkeley.edu/record/137953/files/EECS-2015-135.pdf)</sup>。这些特性直接源于上文所述的持久化、可重放流模型。

## 项目现状

2023 年之后项目活动减少。截至 2024 年的季度董事会报告称项目健康，但显示一个季度仅有 3 次提交和 3 名贡献者；从 2025 年起，多个季度未提交报告，2025 年 7 月一项终止 Apache Samza 项目并将其移入 Attic 的董事会决议被搁置而非通过<sup>[10](https://whimsy.apache.org/board/minutes/Samza.html)</sup>。最近加入的提交者是谢卡尔·夏尔马，于 2024 年 4 月 21 日加入；最近加入的 PMC 成员是巴拉特·库马拉苏布拉马尼安，于 2020 年 2 月 13 日加入；成员规模为 31 名提交者和 17 名 PMC 成员。2026 年 1 月和 4 月的报告将项目状态列为休眠，同时指出 Samza 仍在为包括 LinkedIn 在内的多家公司的关键流处理负载提供支持，并且 2025 年 11 月和 2026 年 2 月举办了关于 Kafka、Samza 和 Flink 的社区聚会<sup>[10](https://whimsy.apache.org/board/minutes/Samza.html)</sup>。

## References

1. [Chris Riccomini (2013). Apache Samza: LinkedIn's Real-time Stream Processing Framework. LinkedIn Engineering.](https://engineering.linkedin.com/data-streams/apache-samza-linkedins-real-time-stream-processing-framework)
2. [Apache Samza project website](http://samza.apache.org)
3. [apache/samza repository README, GitHub](https://github.com/apache/samza)
4. [Moving faster with data streams: The rise of Samza at LinkedIn](https://www.linkedin.com/blog/engineering/data-streaming-processing/moving-faster-data-streams-rise-samza-linkedin)
5. [Jagadish Venkatraman (2018). Samza 1.0: Stream Processing at Massive Scale. LinkedIn Engineering.](https://www.linkedin.com/blog/engineering/open-source/samza-1-0-stream-processing-at-massive-scale)
6. [Board history: Samza, Apache Software Foundation](https://apache.org/foundation/board/minutes/Samza.html)
7. [Apache Release Catalog: Apache Samza](https://release-catalog-test.apache.org/samza/index.html)
8. [Samza Architecture documentation (0.13), Apache Samza incubator site](https://samza.incubator.apache.org/learn/documentation/0.13/introduction/architecture)
9. [Announcing the release of Apache Samza 0.13.0, Apache Blog archive (2017)](https://blogsarchive.apache.org/samza/entry/announcing-the-release-of-apache1)
10. [Board Meeting Minutes: Samza, Apache Whimsy](https://whimsy.apache.org/board/minutes/Samza.html)
11. [Chris (2024). From Samza to Flink: A Decade of Stream Processing. materializedview.io](https://materializedview.io/p/from-samza-to-flink-a-decade-of-stream)
12. [Navina Ramesh (2015). Apache Samza: LinkedIn's Stream Processing engine. LinkedIn Engineering.](https://www.linkedin.com/blog/engineering/open-source/apache-samza-linkedins-stream-processing-engine)
13. [Samza Comparison Introduction (0.12), Apache Samza incubator site](https://samza.incubator.apache.org/learn/documentation/0.12/comparisons/introduction.html)
14. [Using the Apache Samza Runner, Apache Beam documentation](https://beam.incubator.apache.org/documentation/runners/samza/)
15. [Noghabi et al. (2017). Samza: Stateful Scalable Stream Processing at LinkedIn. PVLDB 10(12).](https://www.vldb.org/pvldb/vol10/p1634-noghabi.pdf)
16. [Aslan et al. (2021). A Comparative Analysis of Big Data Frameworks. ASTESJ 6(4).](https://www.astesj.com/publications/ASTESJ_060447.pdf)
17. [EECS-2015-135 (2015). Section 6.3 Apache Samza. UC Berkeley technical report.](https://digicoll.lib.berkeley.edu/record/137953/files/EECS-2015-135.pdf)

---
*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-samza

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