事件驱动架构
由事件生产者、渠道和消费者组成,近实时传递事件以便消费方及时响应。
结构与工作原理
按步骤查看箭头所示的流程。
降低生产与消费的时间耦合;投递保证、顺序与重复取决于代理及实现。
预期收益
近实时投递使消费者及时响应,并将生产者与消费者解耦。
权衡
额外消息跳数带来延迟,线上定位延迟原因可能困难。
如果没有合适的使用场景,复杂性带来的开销可能超过收益。
运维与应用指南
综合说明,与有原文摘录支持的条目分开。实际应用前请先验证。
何时使用
适用于响应状态变化的微服务集成、物联网采集分析、电商订单与配送以及高吞吐异步集成。
应用场景
一家中型零售商整合 500 家店的 POS、库存和配送,每秒近实时处理数千条销售及库存事件。通过异步松耦合,避免单个服务故障使订单全面停止。围绕事件代理拆分订单、库存、通知与配送服务,并加入重处理和死信监控。
部署原则
- 按领域边界拆分生产与消费服务
- 按可用性和吞吐要求集中部署托管或自托管代理与路由器
- 有状态 Kafka 代理使用 StatefulSet 和持久卷
- 分别运维死信与重放存储、模式注册表和可观测性存储
- 热路径近实时处理,批处理和分析用独立消费者组。
本地部署
如有数据主权、合规、DDIL 或物理隔离要求,在现场部署代理与 Kubernetes 控制面,结合集中控制和本地运行。仅当具有 AMQP 兼容、监管或超高吞吐等明确理由时自行托管,并承担补丁、容量、备份和监控。
云环境
默认选用托管事件代理与无服务器消费者,利用自动扩缩、按量计费和区域、可用区冗余。仅在特殊需求下切换到自托管,并评估成本、连接和所有权。
Kubernetes
考虑事件触发启动、按负载扩缩和空闲缩至零。有状态代理使用 StatefulSet 与 PersistentVolume,无状态消费者用 Deployment 与 HPA,事件网关和控制面用 CRD 与 Operator。
故障应对
常见故障包括消费滞后与重试风暴、重复处理、死信积压、代理或分区失衡以及模式不一致。执行错误处理及有限重试、死信隔离,以关联和因果 ID 追踪,按规程重处理,并监控容量、积压与延迟。
14 个维度的证据
反映调研时的证据收录情况,请另行判断来源是否准确、是否仍然有效。
定义与概览有证据
由事件生产者、渠道和消费者组成,近实时传递事件以便消费方及时响应。
event producers that generate a stream of events, event consumers that listen for these events, and event channels解决的问题有证据
无需定时刷新或紧耦合即可回应状态变化,支持应用间异步松耦合通信。
allows applications to communicate asynchronously through loosely coupled components关键组件与资源有证据
核心是事件生产者、事件路由器和事件消费者。
Event-driven architectures have three key components: event producers, event routers, and event consumers.数据与资产放置原则有证据
将保存主题和分区状态的 Kafka 代理放在使用持久卷的 StatefulSet 中。
Kafka Brokers, which maintain the state of the topics and partitions also need to be deployed as StatefulSets代表性使用场景有证据
常见用途包括应用集成、数据共享与普及、物联网采集分析和微服务事件化。
The top 4 use cases for event-driven architecture according to a 2021 survey were应用场景示例有证据
电商中,向购物车添加商品等状态变更事件可触发后续订单、配送及通知服务。
an item being placed in a shopping cart on an e-commerce website不适用情形与注意事项有证据
如果没有合适的使用场景,复杂性带来的开销可能超过收益。
the tradeoffs of adopting EDA – primarily overhead from its complexity – are not always worthwhile without the right use case.本地部署:开发、发布与运维有证据
受数据主权、法规、政策与 DDIL 约束时,本地可保留 Kubernetes 控制面,结合集中管理和现场执行。
need the Kubernetes control plane itself to stay on-premises云环境:开发、发布与运维有证据
云中优先托管代理,以减少运维负担、专注应用逻辑;仅在有特殊要求时考虑自托管。
Default to managed brokers to focus on your application logic.Kubernetes:开发、发布与运维有证据
Kubernetes 上由事件触发负载,根据需求扩容,空闲时缩至零。
build, deploy, run, and manage event driven applications故障应对有证据
有限重试后,将失败事件连同原因隔离到死信队列或类似设施,修复原因后再处理。
Set failing events aside after a limited number of attempts – in a dead-letter queue优势有证据
近实时投递使消费者及时响应,并将生产者与消费者解耦。
Events are delivered in near real time, so consumers can respond immediately to events as they occur.不足与权衡有证据
额外消息跳数带来延迟,线上定位延迟原因可能困难。
Additional latency is one of the trade-offs of adopting an event-driven system代表性技术与工具有证据
例如在 Kubernetes 中以 StatefulSet 部署 Kafka 与 ZooKeeper。
Kafka needs Zookeeper to be deployed as a StatefulSets in Kubernetes.更多参考资料 (23)
- Event-Driven Architecture Style - Azure Architecture Center | Microsoft Learn ↗
- Event-Driven Architecture ↗
- 4 event-driven architecture use cases (with examples) ↗
- What Is Event-Driven Architecture? | IBM ↗
- What Is Event-Driven Architecture? Components and Patterns | SAP ↗
- What is event-driven architecture? ↗
- The Complete Guide to Event-Driven Architecture | Solace ↗
- Event-driven architecture for microservices | Red Hat Developer ↗
- Hybrid cloud and Kubernetes: ↗
- Module 9.2: Managed Message Brokers & Event-Driven Kubernetes | KubeDojo ↗
- Hybrid cloud orchestration: Modernizing on-premises infrastructure management with AWS | AWS Architecture Blog ↗
- Deployment Options ↗
- Kong Event Gateway with Kong Operator ↗
- Persistence in Event Driven Architectures ↗
- Designing Multi-Cluster Kubernetes Operators: Seamless Cloud Orchestration Across Hybrid Environments | martinuke0's Blog ↗
- Event-driven architecture for modern applications ↗
- Building for Failure: Hidden dangers in Event-Driven Systems ↗
- Resilient Design Guidance for Event Hubs and Functions - Azure Architecture Center | Microsoft Learn ↗
- The Hidden Failure Modes of Event-Driven Systems - Chris Arjona ↗
- Designing Resilient Event-Driven Systems at Scale - InfoQ ↗
- Reliable Delivery – Concepts – Event Foundation ↗
- Event-Driven Architecture: Value, Complexity, and the Trade-Offs - Westpoint ↗
- Event-Driven Architecture: What You Need to Know – Encore Blog ↗