50 lines
2.0 KiB
Markdown
50 lines
2.0 KiB
Markdown
---
|
||
title: "Event-Driven Architecture"
|
||
type: concept
|
||
tags:
|
||
- EDA
|
||
- Architecture
|
||
- Cloud
|
||
- Microservices
|
||
last_updated: 2026-04-14
|
||
---
|
||
|
||
## Aliases
|
||
- EDA
|
||
- Event Driven Architecture
|
||
- 事件驱动架构
|
||
|
||
## Definition
|
||
事件驱动架构(EDA)是一种软件架构范式,通过在松耦合的生产者(Producer)和消费者(Consumer)之间传递事件(Event)来实现系统解耦。事件是状态变化或更新的通知,触发异步处理和响应。
|
||
|
||
## Core Components
|
||
- **Event Producer**:事件的产生者,感知状态变化并发布事件
|
||
- **Event Consumer**:事件的订阅者和处理者,响应事件执行相应逻辑
|
||
- **Event Broker**:事件的中介路由器,负责分发和传递事件
|
||
|
||
## Event Broker Types
|
||
- **Event Router**(事件路由器):过滤并路由事件到正确的消费者(SNS / EventBridge)
|
||
- **Event Store**(事件存储):流式存储事件,消费者自行过滤所需事件(SQS / Kinesis)
|
||
|
||
## Key Design Principles
|
||
- **Decoupling**:生产者和消费者完全解耦,独立演进
|
||
- **Scalability**:各组件可独立扩展
|
||
- **Resilience**:局部故障不影响整体系统
|
||
- **Idempotency**:幂等性保证异步重试不产生副作用
|
||
|
||
## Best Practices
|
||
- 稀疏事件(sparse events)适合频繁变化的数据,但消费者可能需要额外查询详情
|
||
- 完整状态事件(full state)包含更多细节,但受 EventBridge 负载大小限制
|
||
- 事件排序需使用 SQS FIFO 或 Kinesis Data Streams
|
||
- EventBridge 最佳实践:每个订阅者使用单一规则、避免为自定义事件使用默认事件总线、使用死信队列处理失败事件
|
||
|
||
## Related Messaging Patterns
|
||
- [[Fan-Out-Pattern]]:扇出模式
|
||
- [[Competing-Consumer-Pattern]]:竞争消费者模式
|
||
- [[Choreography]]:编舞模式
|
||
- [[Orchestration]]:编排模式
|
||
|
||
## Sources
|
||
- [[public-cloud-learning-sessions-opentext-event-driven-architecture-part-1-2024091]]
|
||
- [[public-cloud-learning-sessions-opentext-event-driven-architecture-part-2-2024091]]
|