欢迎使用 FlowZap,快速、清晰、掌控的绘图应用。

事件驱动 CDC(变更数据捕获)架构

Architecture

变更数据捕获架构图,使用 Debezium 读取数据库事务日志并将变更事件发布到 Kafka,供下游消费者更新搜索索引、使缓存失效、加载数据仓库和写入审计日志。该模板展示 CDC 如何通过在数据库级别捕获变更而无需修改应用代码来消除双写问题。对于异构系统间的数据同步至关重要。

完整 FlowZap 代码

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.

工作原理

  1. Step 1: Application writes data to the source database as normal.
  2. Step 2: Debezium tails the database transaction log (WAL) to detect changes.
  3. Step 3: Each INSERT, UPDATE, or DELETE is captured as a change event with before/after state.
  4. Step 4: Events are serialized and published to Kafka topics.
  5. Step 5: Downstream consumers update search indexes, invalidate caches, and load data warehouses.
  6. Step 6: Schema changes are detected and registered in the Schema Registry.

替代方案

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.

Key Facts

Template Name事件驱动 CDC(变更数据捕获)架构
CategoryArchitecture
Steps6 workflow steps
FormatFlowZap Code (.fz file)

相关模板

Outbox 模式可靠消息架构

Architecture

事务性 Outbox 架构图,领域写入和事件发布在同一数据库事务中完成,中继进程轮询 outbox 表并将事件发布到消息代理以保证交付。该模板解决了更新数据库和发布事件不是原子操作的双写问题,确保无需分布式事务即可实现精确一次事件交付。对于需要可靠消息发布的事件驱动架构至关重要。

微服务 API 网关架构

Architecture

微服务 API 网关架构图,展示请求路由、JWT 身份验证、速率限制、服务发现以及跨分布式后端服务的响应聚合。该模板模拟微服务生态系统中所有客户端流量的入口点,在请求到达内部服务之前执行安全策略。适合设计具有集中式横切关注点的可扩展 API 基础设施的平台工程师。

微服务服务网格架构

Architecture

服务网格架构图,展示 Istio 或 Linkerd 边车代理处理 mTLS 加密、流量策略、熔断器和跨微服务的分布式追踪。该模板可视化服务网格如何将网络关注点从应用代码中抽象出来,实现服务间的零信任通信。对于采用服务网格基础设施以提升可观测性和安全性的团队至关重要。

微服务每服务独立数据库架构

Architecture

每服务独立数据库架构图,每个微服务拥有其专用数据存储,通过 Kafka 进行事件驱动同步以实现跨服务数据一致性。该模板展示了微服务数据隔离的核心原则,展示 PostgreSQL 和 MongoDB 如何在多语言持久化策略中共存。对于在保持最终一致性的同时强制服务自治的架构师至关重要。

按业务能力分解微服务架构

Architecture

按业务能力组织的微服务分解架构图:身份认证、产品目录、定价和订单履行,每个都有独立的数据存储和 API。该模板展示如何将单体应用拆分为与业务领域对齐的服务,使用 Backend-for-Frontend (BFF) 模式进行客户端特定的聚合。适合规划领域驱动微服务边界的架构师。

微服务绞杀者模式迁移架构

Architecture

绞杀者模式迁移架构图,展示使用路由层在新旧系统之间分流流量,逐步用新微服务替换遗留单体应用。该模板模拟经过验证的迁移策略,新功能作为微服务构建,遗留端点逐步退役。对于在不进行高风险大爆炸重写的情况下现代化遗留系统的团队至关重要。

返回所有模板