事件驱动 CQRS 与事件存储架构
Architecture
CQRS 架构图,结合独立的命令和查询 API 与事件总线进行异步读模型同步,包括从领域事件构建反规范化视图的投影器。该模板演示了完整的 CQRS+ES 技术栈,写入通过领域验证,读取从优化的物化视图提供服务。适合读写工作负载具有根本不同扩展需求的高吞吐量系统。
Architecture
事件溯源架构图,所有状态变更存储为不可变的领域事件序列,读取投影从事件流构建,快照优化用于快速聚合加载。该模板展示事件溯源如何通过保留每次状态转换的完整历史来消除数据丢失。对于需要完整审计跟踪、时间查询和事件重放能力的系统至关重要。
Command { # Command Side
n1: circle label:"User Command"
n2: rectangle label:"Validate Command"
n3: rectangle label:"Load Aggregate"
n4: rectangle label:"Apply Business Rules"
n5: rectangle label:"Emit Domain Events"
n1.handle(right) -> n2.handle(left)
n2.handle(right) -> n3.handle(left) [label="Valid"]
n3.handle(right) -> n4.handle(left) [label="Current State"]
n4.handle(right) -> n5.handle(left) [label="State Change"]
n5.handle(bottom) -> EventStore.n6.handle(top) [label="Append"]
}
EventStore { # Event Store
n6: rectangle label:"Append Event to Stream"
n7: rectangle label:"Assign Sequence Number"
n8: rectangle label:"Persist Immutable Event"
n9: rectangle label:"Publish to Projections"
n10: rectangle label:"Snapshot Manager"
n6.handle(right) -> n7.handle(left)
n7.handle(right) -> n8.handle(left) [label="Write-Ahead Log"]
n8.handle(right) -> n9.handle(left) [label="Notify"]
n9.handle(bottom) -> Projections.n11.handle(top) [label="Event Stream"]
n10.handle(top) -> Command.n3.handle(bottom) [label="Fast Load"]
}
Projections { # Read Projections
n11: rectangle label:"Event Handler"
n12: rectangle label:"Build Read Model"
n13: rectangle label:"Update Materialized View"
n14: rectangle label:"Serve Query"
n15: circle label:"Query Response"
n11.handle(right) -> n12.handle(left) [label="Transform"]
n12.handle(right) -> n13.handle(left) [label="Upsert"]
n13.handle(right) -> n14.handle(left) [label="Ready"]
n14.handle(right) -> n15.handle(left)
}
Replay { # Event Replay
n16: rectangle label:"Replay from Offset"
n17: rectangle label:"Rebuild Projection"
n18: rectangle label:"Verify Consistency"
n16.handle(right) -> n17.handle(left) [label="Historical Events"]
n17.handle(right) -> n18.handle(left) [label="Rebuilt"]
n18.handle(top) -> Projections.n13.handle(bottom) [label="Replace View"]
}
Traditional CRUD systems overwrite state on every update, losing the history of how the current state was reached. Event sourcing preserves every state change as an immutable event, enabling full audit trails, temporal queries, debugging by replaying events, and the ability to rebuild read models from scratch.
Traditional CRUD with audit tables captures changes but cannot rebuild state. Change Data Capture provides similar benefits without changing application code. This template shows the full event sourcing architecture with projections and replay.
| Template Name | 事件驱动事件溯源架构 |
| Category | Architecture |
| Steps | 6 workflow steps |
| Format | FlowZap Code (.fz file) |
Architecture
CQRS 架构图,结合独立的命令和查询 API 与事件总线进行异步读模型同步,包括从领域事件构建反规范化视图的投影器。该模板演示了完整的 CQRS+ES 技术栈,写入通过领域验证,读取从优化的物化视图提供服务。适合读写工作负载具有根本不同扩展需求的高吞吐量系统。
Architecture
DDD 限界上下文架构图,订单、客户、物流和计费上下文通过防腐层、共享内核和定义集成关系的上下文映射连接。该模板可视化战略 DDD 模式,将复杂领域分解为通过明确定义的集成事件通信的自治限界上下文。对于将领域驱动设计应用于大规模企业系统的架构师至关重要。
Architecture
微服务 API 网关架构图,展示请求路由、JWT 身份验证、速率限制、服务发现以及跨分布式后端服务的响应聚合。该模板模拟微服务生态系统中所有客户端流量的入口点,在请求到达内部服务之前执行安全策略。适合设计具有集中式横切关注点的可扩展 API 基础设施的平台工程师。
Architecture
每服务独立数据库架构图,每个微服务拥有其专用数据存储,通过 Kafka 进行事件驱动同步以实现跨服务数据一致性。该模板展示了微服务数据隔离的核心原则,展示 PostgreSQL 和 MongoDB 如何在多语言持久化策略中共存。对于在保持最终一致性的同时强制服务自治的架构师至关重要。