Outbox 模式可靠消息架构
Architecture
事务性 Outbox 架构图,领域写入和事件发布在同一数据库事务中完成,中继进程轮询 outbox 表并将事件发布到消息代理以保证交付。该模板解决了更新数据库和发布事件不是原子操作的双写问题,确保无需分布式事务即可实现精确一次事件交付。对于需要可靠消息发布的事件驱动架构至关重要。
Architecture
变更数据捕获架构图,使用 Debezium 读取数据库事务日志并将变更事件发布到 Kafka,供下游消费者更新搜索索引、使缓存失效、加载数据仓库和写入审计日志。该模板展示 CDC 如何通过在数据库级别捕获变更而无需修改应用代码来消除双写问题。对于异构系统间的数据同步至关重要。
SourceDB { # Source Database
n1: circle label:"Data Write Operation"
n2: rectangle label:"Transaction Log (WAL)"
n3: rectangle label:"Commit to Database"
n1.handle(right) -> n2.handle(left)
n2.handle(right) -> n3.handle(left) [label="Persist"]
n2.handle(bottom) -> CDC.n4.handle(top) [label="Log Tail"]
}
CDC { # CDC Engine (Debezium)
n4: rectangle label:"Read Transaction Log"
n5: rectangle label:"Detect Change Event"
n6: rectangle label:"Serialize to Avro/JSON"
n7: diamond label:"Schema Changed?"
n8: rectangle label:"Update Schema Registry"
n9: rectangle label:"Publish Change Event"
n4.handle(right) -> n5.handle(left) [label="INSERT/UPDATE/DELETE"]
n5.handle(right) -> n6.handle(left) [label="Before + After"]
n6.handle(right) -> n7.handle(left)
n7.handle(right) -> n9.handle(left) [label="No"]
n7.handle(bottom) -> n8.handle(top) [label="Yes"]
n8.handle(right) -> n9.handle(left) [label="Registered"]
n9.handle(bottom) -> Consumers.n10.handle(top) [label="Kafka Topic"]
}
Consumers { # Downstream Consumers
n10: rectangle label:"Search Index Updater"
n11: rectangle label:"Cache Invalidator"
n12: rectangle label:"Data Warehouse Loader"
n13: rectangle label:"Audit Log Writer"
n10.handle(right) -> n11.handle(left) [label="Elasticsearch"]
n12.handle(right) -> n13.handle(left) [label="Snowflake"]
}
TargetDB { # Target Systems
n14: rectangle label:"Elasticsearch Index"
n15: rectangle label:"Redis Cache"
n16: rectangle label:"Data Warehouse"
n17: rectangle label:"Audit Database"
n10.handle(bottom) -> TargetDB.n14.handle(top) [label="Upsert Doc"]
n11.handle(bottom) -> TargetDB.n15.handle(top) [label="Invalidate"]
n12.handle(bottom) -> TargetDB.n16.handle(top) [label="Load"]
n13.handle(bottom) -> TargetDB.n17.handle(top) [label="Append"]
}
Application-level dual writes (updating a database AND publishing an event) are inherently unreliable—if either fails, data becomes inconsistent. CDC captures changes directly from the database transaction log, guaranteeing that every committed write is captured and published without modifying application code.
Application-level event publishing requires code changes and risks dual-write inconsistency. Polling-based CDC is simpler but adds latency. Debezium with Kafka Connect provides the most reliable log-based CDC. This template shows the complete CDC pipeline.
| Template Name | 事件驱动 CDC(变更数据捕获)架构 |
| Category | Architecture |
| Steps | 6 workflow steps |
| Format | FlowZap Code (.fz file) |
Architecture
事务性 Outbox 架构图,领域写入和事件发布在同一数据库事务中完成,中继进程轮询 outbox 表并将事件发布到消息代理以保证交付。该模板解决了更新数据库和发布事件不是原子操作的双写问题,确保无需分布式事务即可实现精确一次事件交付。对于需要可靠消息发布的事件驱动架构至关重要。
Architecture
微服务 API 网关架构图,展示请求路由、JWT 身份验证、速率限制、服务发现以及跨分布式后端服务的响应聚合。该模板模拟微服务生态系统中所有客户端流量的入口点,在请求到达内部服务之前执行安全策略。适合设计具有集中式横切关注点的可扩展 API 基础设施的平台工程师。
Architecture
每服务独立数据库架构图,每个微服务拥有其专用数据存储,通过 Kafka 进行事件驱动同步以实现跨服务数据一致性。该模板展示了微服务数据隔离的核心原则,展示 PostgreSQL 和 MongoDB 如何在多语言持久化策略中共存。对于在保持最终一致性的同时强制服务自治的架构师至关重要。
Architecture
按业务能力组织的微服务分解架构图:身份认证、产品目录、定价和订单履行,每个都有独立的数据存储和 API。该模板展示如何将单体应用拆分为与业务领域对齐的服务,使用 Backend-for-Frontend (BFF) 模式进行客户端特定的聚合。适合规划领域驱动微服务边界的架构师。
Architecture
绞杀者模式迁移架构图,展示使用路由层在新旧系统之间分流流量,逐步用新微服务替换遗留单体应用。该模板模拟经过验证的迁移策略,新功能作为微服务构建,遗留端点逐步退役。对于在不进行高风险大爆炸重写的情况下现代化遗留系统的团队至关重要。