事件驱动 CQRS 与事件存储架构
Architecture
CQRS 架构图,结合独立的命令和查询 API 与事件总线进行异步读模型同步,包括从领域事件构建反规范化视图的投影器。该模板演示了完整的 CQRS+ES 技术栈,写入通过领域验证,读取从优化的物化视图提供服务。适合读写工作负载具有根本不同扩展需求的高吞吐量系统。
Architecture
CQRS 物化视图架构图,多个投影器构建特定用途的读模型:订单摘要、客户仪表板、分析立方体和搜索索引,全部由单一事件流提供。该模板展示如何从相同的写入事件创建多个优化的查询视图,每个视图针对特定用例定制,读取延迟低于毫秒级。适合需要从单一数据源进行多样化查询模式的系统。
WriteModel { # Write Model
n1: circle label:"Incoming Command"
n2: rectangle label:"Command Handler"
n3: rectangle label:"Validate Against Aggregate"
n4: rectangle label:"Persist to Write Store"
n5: rectangle label:"Emit Domain Event"
n1.handle(right) -> n2.handle(left)
n2.handle(right) -> n3.handle(left)
n3.handle(right) -> n4.handle(left) [label="Normalized"]
n4.handle(right) -> n5.handle(left) [label="After Commit"]
n5.handle(bottom) -> EventBus.n6.handle(top) [label="Publish"]
}
EventBus { # Event Bus
n6: rectangle label:"Route Event"
n7: rectangle label:"Guarantee Ordering"
n8: rectangle label:"Deliver to Projectors"
n6.handle(right) -> n7.handle(left) [label="Partition Key"]
n7.handle(right) -> n8.handle(left)
n8.handle(bottom) -> Projectors.n9.handle(top) [label="Fan-Out"]
}
Projectors { # View Projectors
n9: rectangle label:"Order Summary Projector"
n10: rectangle label:"Customer Dashboard Projector"
n11: rectangle label:"Analytics Projector"
n12: rectangle label:"Search Index Projector"
n9.handle(bottom) -> Views.n13.handle(top) [label="Build View"]
n10.handle(bottom) -> Views.n14.handle(top) [label="Build View"]
n11.handle(bottom) -> Views.n15.handle(top) [label="Build View"]
n12.handle(bottom) -> Views.n16.handle(top) [label="Build View"]
}
Views { # Materialized Views
n13: rectangle label:"Order Summary Table"
n14: rectangle label:"Customer Dashboard Cache"
n15: rectangle label:"Analytics Cube"
n16: rectangle label:"Elasticsearch Index"
n17: rectangle label:"Query API"
n18: circle label:"Fast Read Response"
n13.handle(right) -> n17.handle(left)
n14.handle(right) -> n17.handle(left)
n15.handle(right) -> n17.handle(left)
n16.handle(right) -> n17.handle(left)
n17.handle(right) -> n18.handle(left) [label="Sub-ms Latency"]
}
Different consumers need different views of the same data: dashboards need aggregations, search needs full-text indexes, and APIs need denormalized joins. Materialized views built from a single event stream allow each consumer to have a purpose-built read model without complex cross-service queries.
Database views and materialized views work for single-database scenarios. GraphQL federation can compose data without materialized views. This template shows how to build multiple optimized read models from a single event stream.
| Template Name | CQRS 物化视图架构 |
| Category | Architecture |
| Steps | 6 workflow steps |
| Format | FlowZap Code (.fz file) |
Architecture
CQRS 架构图,结合独立的命令和查询 API 与事件总线进行异步读模型同步,包括从领域事件构建反规范化视图的投影器。该模板演示了完整的 CQRS+ES 技术栈,写入通过领域验证,读取从优化的物化视图提供服务。适合读写工作负载具有根本不同扩展需求的高吞吐量系统。
Architecture
CQRS 读写分离架构图,展示专用的命令和查询路径,PostgreSQL 用于写入,Redis 或 Elasticsearch 用于优化读取,以及带有延迟监控的事件驱动同步层。该模板演示了 CQRS 的核心原则——分离读写模型以独立扩展和优化每条路径。适合读写比例不对称且查询性能至关重要的应用。
Architecture
CQRS 基于任务的 UI 架构图,前端将用户意图捕获为显式命令,异步提交并进行乐观更新,当读模型同步时通过 WebSocket 接收实时确认。该模板模拟用意图驱动命令替代 CRUD 表单的现代 UI 模式,实现具有最终一致性的响应式用户体验。推荐给在 CQRS 后端上构建响应式前端的团队。
Architecture
微服务 API 网关架构图,展示请求路由、JWT 身份验证、速率限制、服务发现以及跨分布式后端服务的响应聚合。该模板模拟微服务生态系统中所有客户端流量的入口点,在请求到达内部服务之前执行安全策略。适合设计具有集中式横切关注点的可扩展 API 基础设施的平台工程师。
Architecture
每服务独立数据库架构图,每个微服务拥有其专用数据存储,通过 Kafka 进行事件驱动同步以实现跨服务数据一致性。该模板展示了微服务数据隔离的核心原则,展示 PostgreSQL 和 MongoDB 如何在多语言持久化策略中共存。对于在保持最终一致性的同时强制服务自治的架构师至关重要。