Add the source-aligned CDC template, and key the canonical template's topics

The first template of the source-aligned family: one data product per source
system, capturing a database by CDC and turning what it emits into what a
canonical product accepts. It runs on the Integration Bus, not in a domain, and
is deployed with the `data-bus` CLI.

What it produces, and what its tests hold it to: raw topics in the source's own
shape; deterministic identity, so a re-snapshot upserts rather than duplicating;
validation against the canonical product's rules before publishing, with what
fails going to the product's own dead-letter topic with the reason; keying by the
canonical identifier; provenance in headers; and an archive in the bus object
store that can be replayed back onto the raw topic.

The worked example captures an ERP customer table and delivers into Canonical
Party in the digital-core domain: 12 smoke checks, 37 unit tests, including a
poison record that is quarantined while the next record still arrives.

The canonical template's topics now declare the key producers must set, which is
the other half of that contract.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
paulandClaude Opus 5 committed 2026-09-18 10:54:39 +12:00
1 parent ca6bea351a
commit 866bcfe238
44 files changed
+2505 -11

No files matched your search

+4 -1
View File
@@ -1,5 +1,8 @@
-- Example Address: streaming job (Flink SQL, Flink 2.2).
-- Submitted by the platform CLI with `bin/sql-client.sh -f job.sql` on the jobmanager.
-- Submitted by `data-domain deploy` with `bin/sql-client.sh -f job.sql` on the jobmanager.
-- ${ODS_PASSWORD} is substituted from the domain's .env at submission and never committed.
-- address_inbound reads records keyed by address_id: only messages sharing a key share a
-- partition, and only one partition keeps them in order.
SET 'pipeline.name' = 'example-address';
SET 'execution.checkpointing.interval' = '10 s';
+1 -1
View File
@@ -53,7 +53,7 @@ product:
name:
en: Publish Input
description:
en: "Kafka topic accepting canonical Address records."
en: "Kafka topic accepting canonical Address records, keyed by address_id, which is what keeps changes to one address in order."
outputPorttype: API
format: JSON
authenticationMethod: none
@@ -27,6 +27,7 @@ events:
topics:
- name: "digital-core.example-address.address.inbound"
role: publish-input
key: "address_id" # producers MUST key by this: order holds per key, per partition
table: "address"
schema: events/schemas/address.schema.json
partitions: 3
@@ -34,6 +35,7 @@ events:
retention_ms: 604800000
- name: "digital-core.example-address.address.outbound"
role: subscribe-output
key: "address_id" # set by the Flink upsert-kafka sink
table: "address"
schema: events/schemas/address.schema.json
partitions: 3
@@ -43,15 +43,25 @@ def test_record_round_trip(dp):
refused = dp.sql_error(f"INSERT INTO {schema}.{table} ({columns}) VALUES ({values})")
assert refused is None, f"the ODS would refuse the round-trip record, so it is not published: {refused}"
inbound = next(t for t in dp.product.topics if t.table == table and t.role == "publish-input")
assert inbound.key, f"{inbound.name} declares no key in product.yaml; producers cannot keep changes in order"
try:
# Publish input -> Flink -> ODS
dp.publish(dp.topic(table, "publish-input"), [record])
# Publish input -> Flink -> ODS, keyed as the contract requires
dp.publish(inbound.name, [record], key_field=inbound.key)
dp.eventually(lambda: contains(record, (dp.sql(f"SELECT * FROM {schema}.{table} WHERE {where}") or [None])[0]))
# ODS -> Flink CDC -> subscribe output, and ODS -> pg_duckpipe -> lake
dp.eventually(lambda: contains(record, dp.latest(outbound).get(record_key)))
dp.eventually(lambda: dp.trino(f"SELECT count(*) AS n FROM {lake} WHERE CAST({key} AS varchar) = '{record_key}'") == [{"n": 1}])
# Two more, published in order under the same key: one partition, so the last one wins
column, value = next(iter(update.items()))
ordered = [dict(record, **{column: f"{value} first"}), dict(record, **{column: f"{value} second"})]
dp.publish(inbound.name, ordered, key_field=inbound.key)
dp.eventually(lambda: (dp.sql(f"SELECT {column} FROM {schema}.{table} WHERE {where}") or [{}])[0].get(column)
== f"{value} second")
# CRUD API update -> subscribe output and lake
assignments = ", ".join(f'{camel(c)}: "{v}"' for c, v in update.items())
data = dp.graphql(
@@ -60,7 +70,6 @@ def test_record_round_trip(dp):
)
assert data[f"update{pascal(table)}Collection"]["affectedCount"] == 1
dp.eventually(lambda: contains(update, dp.latest(outbound).get(record_key)))
column, value = next(iter(update.items()))
dp.eventually(lambda: dp.trino(f"SELECT CAST({column} AS varchar) AS v FROM {lake} WHERE CAST({key} AS varchar) = '{record_key}'") == [{"v": str(value)}])
# CRUD API delete -> tombstone on subscribe output, row gone from the lake
+3 -1
View File
@@ -3,7 +3,9 @@
-- ${ODS_PASSWORD} is substituted from the domain's .env at submission and never committed.
--
-- Per entity table, four Flink tables and two continuous INSERTs:
-- <table>_inbound kafka Publish Input: records producers publish (JSON, schema in events/schemas)
-- <table>_inbound kafka Publish Input: records producers publish (JSON, schema in events/schemas),
-- keyed by <table>_id: only messages sharing a key share a partition,
-- and only one partition keeps them in order
-- <table>_ods jdbc upserts inbound records into the ODS table by primary key
-- <table>_cdc postgres-cdc every change committed to the ODS table, however it arrived
-- <table>_outbound upsert-kafka Subscribe Output: compacted topic keyed by <table>_id, deletes as tombstones
+1 -1
View File
@@ -60,7 +60,7 @@ product:
name:
en: Publish Input
description:
en: "Kafka topics that accept canonical records, one per entity. JSON payloads conform to the schema registered for the topic."
en: "Kafka topics that accept canonical records, one per entity. JSON payloads conform to the schema registered for the topic, and each message is keyed by the entity's identifier, which is what keeps changes to one entity in order."
outputPorttype: API
format: JSON
authenticationMethod: none
+2
View File
@@ -32,6 +32,7 @@ events:
- name: "{{domain.slug}}.{{product.slug}}.{{table}}.inbound"
role: publish-input # producers publish canonical records here
table: "{{table}}"
key: "{{table}}_id" # producers MUST key by this: order holds per key, per partition
schema: events/schemas/{{table}}.schema.json
partitions: 3
cleanup_policy: delete
@@ -39,6 +40,7 @@ events:
- name: "{{domain.slug}}.{{product.slug}}.{{table}}.outbound"
role: subscribe-output # every change to the ODS table, keyed by {{table}}_id
table: "{{table}}"
key: "{{table}}_id" # set by the Flink upsert-kafka sink
schema: events/schemas/{{table}}.schema.json
partitions: 3
cleanup_policy: compact
+12 -3
View File
@@ -43,15 +43,25 @@ def test_record_round_trip(dp):
refused = dp.sql_error(f"INSERT INTO {schema}.{table} ({columns}) VALUES ({values})")
assert refused is None, f"the ODS would refuse the round-trip record, so it is not published: {refused}"
inbound = next(t for t in dp.product.topics if t.table == table and t.role == "publish-input")
assert inbound.key, f"{inbound.name} declares no key in product.yaml; producers cannot keep changes in order"
try:
# Publish input -> Flink -> ODS
dp.publish(dp.topic(table, "publish-input"), [record])
# Publish input -> Flink -> ODS, keyed as the contract requires
dp.publish(inbound.name, [record], key_field=inbound.key)
dp.eventually(lambda: contains(record, (dp.sql(f"SELECT * FROM {schema}.{table} WHERE {where}") or [None])[0]))
# ODS -> Flink CDC -> subscribe output, and ODS -> pg_duckpipe -> lake
dp.eventually(lambda: contains(record, dp.latest(outbound).get(record_key)))
dp.eventually(lambda: dp.trino(f"SELECT count(*) AS n FROM {lake} WHERE CAST({key} AS varchar) = '{record_key}'") == [{"n": 1}])
# Two more, published in order under the same key: one partition, so the last one wins
column, value = next(iter(update.items()))
ordered = [dict(record, **{column: f"{value} first"}), dict(record, **{column: f"{value} second"})]
dp.publish(inbound.name, ordered, key_field=inbound.key)
dp.eventually(lambda: (dp.sql(f"SELECT {column} FROM {schema}.{table} WHERE {where}") or [{}])[0].get(column)
== f"{value} second")
# CRUD API update -> subscribe output and lake
assignments = ", ".join(f'{camel(c)}: "{v}"' for c, v in update.items())
data = dp.graphql(
@@ -60,7 +70,6 @@ def test_record_round_trip(dp):
)
assert data[f"update{pascal(table)}Collection"]["affectedCount"] == 1
dp.eventually(lambda: contains(update, dp.latest(outbound).get(record_key)))
column, value = next(iter(update.items()))
dp.eventually(lambda: dp.trino(f"SELECT CAST({column} AS varchar) AS v FROM {lake} WHERE CAST({key} AS varchar) = '{record_key}'") == [{"v": str(value)}])
# CRUD API delete -> tombstone on subscribe output, row gone from the lake