Skip to main content
Version: Next

Case: CDC to warehouse — Debezium changes into an upserting table

End-to-end flow: a database writes change events through Debezium to Kafka; ArkFlow decodes the envelope, filters to real mutations, and UPSERTs the current row image into a warehouse table. The sink is idempotent by key, so at-least-once replay converges.

Prerequisites​

  • Kafka with a Debezium connector publishing to shop.users (see the CDC recipe for the envelope shape).
  • A PostgreSQL warehouse database reachable from ArkFlow; the target table carries a primary key on id.

Configuration​

Full config: examples/case_cdc_warehouse.yaml (manifest name case-cdc-warehouse).

input:
type: kafka
brokers: ["localhost:9092"]
topics: ["shop.users"]
consumer_group: arkflow-cdc
start_from_latest: false
codec:
type: debezium_json
- type: sql
query: |
SELECT op, ts_ms, id, name, email
FROM flow
WHERE op IN ('c', 'u')
output:
type: sql
output_type:
type: postgres
uri: "postgres://warehouse:${secret:WAREHOUSE_PASSWORD:-}@db:5432/analytics"
table_name: users_current
upsert: true
upsert_keys: ["id"]

Notes:

  • The debezium_json codec flattens the envelope: business columns come from after (or before on delete), plus op, ts_ms, source_db, source_table.
  • WHERE op IN ('c','u') keeps inserts and updates; deletes can be routed to a second stream for tombstones, or handled with a delete marker column.
  • upsert: true + upsert_keys: ["id"] makes the table converge under redelivery — exactly the idempotency the replay guide relies on.

Expected result​

For each change event, the warehouse row for that id reflects the latest after image; op/ts_ms can be persisted alongside for auditing. Running the stream twice over the same topic range yields the same table state.

Verify​

  1. Insert/update a row in the source database; confirm the warehouse row updates within the pipeline latency.
  2. Kill ArkFlow mid-stream, restart, and confirm no warehouse row is missing or stale (duplicates are absorbed by the UPSERT).
  3. Re-run over a replayed offset range and compare a table checksum before and after — it must be identical.