事件驱动 CDC(变更数据捕获)架构
Architecture
变更数据捕获架构图,使用 Debezium 读取数据库事务日志并将变更事件发布到 Kafka,供下游消费者更新搜索索引、使缓存失效、加载数据仓库和写入审计日志。该模板展示 CDC 如何通过在数据库级别捕获变更而无需修改应用代码来消除双写问题。对于异构系统间的数据同步至关重要。
Architecture
事务性 Outbox 架构图,领域写入和事件发布在同一数据库事务中完成,中继进程轮询 outbox 表并将事件发布到消息代理以保证交付。该模板解决了更新数据库和发布事件不是原子操作的双写问题,确保无需分布式事务即可实现精确一次事件交付。对于需要可靠消息发布的事件驱动架构至关重要。
Application { # Application Service
n1: circle label:"Business Operation"
n2: rectangle label:"Begin Transaction"
n3: rectangle label:"Update Domain Table"
n4: rectangle label:"Insert into Outbox Table"
n5: rectangle label:"Commit Transaction"
n6: circle label:"Return Success"
n1.handle(right) -> n2.handle(left)
n2.handle(right) -> n3.handle(left) [label="Atomic"]
n3.handle(right) -> n4.handle(left) [label="Same TX"]
n4.handle(right) -> n5.handle(left) [label="Commit"]
n5.handle(right) -> n6.handle(left)
n4.handle(bottom) -> Database.n7.handle(top) [label="Write"]
}
Database { # Database
n7: rectangle label:"Domain Table (Orders)"
n8: rectangle label:"Outbox Table (Events)"
n9: rectangle label:"Outbox Row: Pending"
n7.handle(right) -> n8.handle(left) [label="Same Database"]
n8.handle(right) -> n9.handle(left) [label="Status: PENDING"]
n9.handle(bottom) -> Relay.n10.handle(top) [label="Poll"]
}
Relay { # Outbox Relay (Debezium/Poller)
n10: rectangle label:"Poll Outbox Table"
n11: rectangle label:"Read Pending Events"
n12: rectangle label:"Publish to Message Broker"
n13: diamond label:"Published Successfully?"
n14: rectangle label:"Mark as Processed"
n15: rectangle label:"Retry with Backoff"
n10.handle(right) -> n11.handle(left) [label="SELECT WHERE status=PENDING"]
n11.handle(right) -> n12.handle(left) [label="Serialize"]
n12.handle(right) -> n13.handle(left)
n13.handle(right) -> n14.handle(left) [label="Yes"]
n13.handle(bottom) -> n15.handle(top) [label="No"]
n14.handle(top) -> Database.n9.handle(bottom) [label="UPDATE status=DONE"]
n15.handle(top) -> n12.handle(bottom) [label="Retry"]
}
Consumers { # Downstream Consumers
n16: rectangle label:"Notification Service"
n17: rectangle label:"Analytics Service"
n18: rectangle label:"Search Index Service"
n12.handle(bottom) -> Consumers.n16.handle(top) [label="OrderCreated"]
n12.handle(bottom) -> Consumers.n17.handle(top) [label="OrderCreated"]
n12.handle(bottom) -> Consumers.n18.handle(top) [label="OrderCreated"]
}
Publishing an event to a message broker after updating a database is a dual-write problem—if the broker publish fails after the database commit, the event is lost. The outbox pattern solves this by writing both the domain change and the event to the same database transaction, then reliably relaying events to the broker.
Application-level event publishing risks data inconsistency on partial failures. CDC without an outbox table captures all changes, not just domain events. This template shows the transactional outbox pattern for guaranteed event delivery.
| Template Name | Outbox 模式可靠消息架构 |
| Category | Architecture |
| Steps | 6 workflow steps |
| Format | FlowZap Code (.fz file) |
Architecture
变更数据捕获架构图,使用 Debezium 读取数据库事务日志并将变更事件发布到 Kafka,供下游消费者更新搜索索引、使缓存失效、加载数据仓库和写入审计日志。该模板展示 CDC 如何通过在数据库级别捕获变更而无需修改应用代码来消除双写问题。对于异构系统间的数据同步至关重要。
Architecture
微服务 API 网关架构图,展示请求路由、JWT 身份验证、速率限制、服务发现以及跨分布式后端服务的响应聚合。该模板模拟微服务生态系统中所有客户端流量的入口点,在请求到达内部服务之前执行安全策略。适合设计具有集中式横切关注点的可扩展 API 基础设施的平台工程师。
Architecture
每服务独立数据库架构图,每个微服务拥有其专用数据存储,通过 Kafka 进行事件驱动同步以实现跨服务数据一致性。该模板展示了微服务数据隔离的核心原则,展示 PostgreSQL 和 MongoDB 如何在多语言持久化策略中共存。对于在保持最终一致性的同时强制服务自治的架构师至关重要。
Architecture
按业务能力组织的微服务分解架构图:身份认证、产品目录、定价和订单履行,每个都有独立的数据存储和 API。该模板展示如何将单体应用拆分为与业务领域对齐的服务,使用 Backend-for-Frontend (BFF) 模式进行客户端特定的聚合。适合规划领域驱动微服务边界的架构师。
Architecture
绞杀者模式迁移架构图,展示使用路由层在新旧系统之间分流流量,逐步用新微服务替换遗留单体应用。该模板模拟经过验证的迁移策略,新功能作为微服务构建,遗留端点逐步退役。对于在不进行高风险大爆炸重写的情况下现代化遗留系统的团队至关重要。