Skip to content

Part 8 · Blueprint 45

Change Data Capture (CDC) & Outbox Pipelines (Debezium Scale)

14 min reading · Sources · Editorial review pending

A snapshot overlapping live changes can silently overwrite a newer downstream value.

More
20px
Reading list
Page details

Published date · Last edited:

Draft edition. Editorial review and supplementary reading recommendations are still being completed.

Format: Architecture walkthrough. Prerequisites: the beginner bootcamp. Chapter prerequisites: Message Queues & Event Streams: Kafka vs. RabbitMQ, Idempotency Keys & Distributed Retries, Event Sourcing & CQRS Architecture.

Sixty-second mental model

Problem: A snapshot overlapping live changes can silently overwrite a newer downstream value.

Use: Join snapshot and log under explicit positions and identities.

Design boundary: Replicate committed database changes into projections while preserving a coherent snapshot/stream boundary. A connector position is recovery evidence, not proof that every external effect is complete.

Layer 1 · Intuition

Hypothetical scenario: Northwind is designing change data capture. Maya represents product requirements, Dev implementation and Priya reliability. The team must agree what one change event means and which component owns the source log position.

Think of a courier forwarding the database's committed change journal. Separate the requester from source log position, then identify the retained evidence needed after failure.

Authority
The entitled state owner.
Invariant
A rule preserved across concurrency and failures.
CDC
Change data capture: extracting committed data changes for downstream processing. Analogy: Following the ledger's change journal to update other desks.

Architecture and worked reasoning

Design boundary: Replicate committed database changes into projections while preserving a coherent snapshot/stream boundary. A connector position is recovery evidence, not proof that every external effect is complete.

Responsibilities on the request path

Change data capture: responsibilities and request directionReplicate committed database changes into projections while preserving a coherent snapshot/stream boundary. A connector position is recovery evidence, not proof that every external effect is complete.Database logSnapshot readerChange streamProjection sink
Replicate committed database changes into projections while preserving a coherent snapshot/stream boundary. A connector position is recovery evidence, not proof that every external effect is complete.

Workload and limiting resource

Hypothetical source generates 5 MB/s of retained changes. A connector offline for two hours needs 5 × 7,200 = 36,000 MB, or 36 GB, of relevant history before overhead. A 10 GB retention budget cannot promise that outage recovery horizon.

Keep the units attached to each intermediate result. The assumptions above describe a hypothetical exercise, not observed vendor capacity. A real capacity decision also needs a measured service curve, skew, recovery traffic and an explicit admission policy for overload.

Mutation or publication path

Change data capture: mutation boundaryChoose a consistent snapshot and source position. Then: Emit committed changes with source identity/order. Then: Apply idempotent version-aware updates and durable progress.Step 1
Choose a consistent snapshot and source position.
Step 2
Emit committed changes with source identity/order.
Step 3
Apply idempotent version-aware updates and durable progress.
Choose a consistent snapshot and source position. Then: Emit committed changes with source identity/order. Then: Apply idempotent version-aware updates and durable progress.
  1. Choose a consistent snapshot and source position.
  2. Emit committed changes with source identity/order.
  3. Apply idempotent version-aware updates and durable progress.

Observation and recovery path

Change data capture: observation boundaryInspect projection version and source lag. Then: Recover from retained log positions. Then: Rebuild rather than silently skipping a missing history interval.Step 1
Inspect projection version and source lag.
Step 2
Recover from retained log positions.
Step 3
Rebuild rather than silently skipping a missing history interval.
Inspect projection version and source lag. Then: Recover from retained log positions. Then: Rebuild rather than silently skipping a missing history interval.
  1. Inspect projection version and source lag.
  2. Recover from retained log positions.
  3. Rebuild rather than silently skipping a missing history interval.

Failure that changes the decision

Hypothetical scenario: Snapshot rows race with live updates and overwrite newer projection versions. Join the snapshot and stream at a defined boundary and compare source versions.

Attempt this decision before reading the explanation

Can deleting an old log segment be harmless because the database is healthy?

Not if a required consumer still needs that segment. Retention must account for lagging recovery positions and acceptable rebuild procedures.

Supporting mechanism analysis

Hypothetical scenario: Northwind. Maya represents product, Dev implementation and Priya reliability. The following workflow develops the underlying mechanism.

Treat a release as a change between interacting contracts. Stage compatible readers and writers, limit initial exposure and choose stop evidence before widening the rollout. The canary calculation introduces its own selected cohort; it does not claim observed catalogue capacity.

A deployment makes a new application configuration serve work. The configuration includes executable artifacts, schema expectations, API versions, service permissions and the interpretation of stored state. Northwind can keep the same URL while changing a response in a way that breaks its consumer. Reachability and compatibility are therefore separate release conditions.

A health endpoint can remain green while the catalogue returns stale price evidence or a malformed reservation. Choose checks from the user journey. For Northwind, current price evidence, parseable structure and an authorized reservation are part of a useful result. A low HTTP error rate says little about those semantic requirements.

Define the release unit before comparing it. If Dev changes the API handler, database query and schema together, that combined candidate can be evaluated, but a regression cannot automatically be attributed to the query. The manifest should identify each dependency so the team can reproduce the relevant configuration and choose a compatible recovery set.

A canary checks behavior for admitted traffic, not merely process health. Compare equivalent workload cohorts and preserve failures, rejected work and pending outcomes in the ledger. Shadow reads can compare outputs, but shadow writes or provider calls require effect suppression or isolated authority.

Suppose a new consumer expects a price revision field that old records lack. An expand step first makes readers accept both forms and adds the field without removing the old path. Writers can then populate it while a backfill updates older records. A later contract step removes the obsolete representation after every dependent reader and rollback configuration can tolerate that change.

Hypothetical scenario. The expanded product record retains its old price and adds a new representation with a source-revision field. A backfill reads Q7 at revision 12 with a selected price of 1,200 minor units. Before its write arrives, a live edit commits revision 13 with price 1,300. Blindly storing the delayed conversion of revision 12 would overwrite newer evidence even though both binaries accept the expanded schema.

Hypothetical worked example: Northwind receives 100 eligible requests per second and routes 5% to a canary. Candidate traffic is 100 × 0.05 = 5 requests per second. Over a chosen 10-minute observation window, 10 × 60 = 600 seconds, so the expected candidate population is 5 × 600 = 3,000 requests when the rate and routing share remain constant.

Compare the baseline on the same task categories and time interval. A sale changes the input mix, so yesterday’s average is a weak control. Track the denominator for each slice, including abstentions and rejected work. Waiting for 3,000 completions also differs from waiting ten minutes if some requests are still queued or unresolved.

A shadow receives eligible input and produces a candidate result without becoming the source of business actions. It helps compare representations, schemas and latency under a realistic input population. Disable consequential writes in the shadow path. A second refund is not an acceptable price for a more realistic comparison.

A human reviewer can inspect disagreements, but the review queue needs ownership and a spending limit. If every disagreement sits indefinitely, the release decision has merely moved into an unbounded backlog. Decide which differences block expansion, which require investigation and which are acceptable wording changes before the first canary cohort begins.

The transferable issue is the relationship between operator intent and enforced scope. A release control should bound the actual population affected, not merely display a reassuring percentage beside a command. Validate scope, establish a stop path and understand which shared dependency can make an apparently small change affect unrelated traffic.

For read-only catalogue responses, a stale replica can display a superseded price. For payments, two regions must not independently create effects for the same approved action. Keep the authoritative operation identity and fencing arrangement clear. A regional failover test should include recovery and reconciliation, not only the first successful response from the alternate location.

Keep the old representation and a coherent write policy through the migration window, or establish a separately evaluated data recovery path. A dual-write plan also needs atomicity or reconciliation for disagreements. Removing old state is a later decision supported by evidence about every remaining reader and recovery configuration.

Another misconception is that a canary must eventually expand. A candidate can remain blocked or be discarded when the evidence does not support it. Returning to a known compatible configuration is a valid outcome. Preserve the failed candidate’s observations so the next release addresses the actual regression rather than repeating a slightly different guess.

Northwind assigns Dev the manifest and compatibility checks, Priya the user-outcome rubric and Sam the rollout and stop controls. An expansion requires all three views to agree. This keeps a fast technically successful deployment from overriding a product-level failure that another owner can already demonstrate.

A finite cohort cannot certify future traffic, and a quiet interval can miss a rare important task. A regional incident can also remove the baseline needed for a clean comparison. State those limits in the release decision, retain a usable compatible recovery configuration and continue monitoring the same acceptance conditions after expansion.

Layer 3 · Internals

PostgreSQL change data capture follows committed database changes using a source position such as a log sequence number. Debezium coordinates an initial snapshot with continued log consumption so a downstream view can be built while the source remains active. The snapshot boundary and source offset are part of correctness, not implementation trivia.

A downstream upsert needs an ordering or version rule. Suppose the snapshot supplies product version 7 after the stream has already delivered version 8. Blindly applying arrival order resurrects the older value. Preserve the source version or a connector-supported ordering boundary and reject obsolete replacement. Deletions need durable representation too; dropping tombstones too early can bring removed entities back during replay. Connector offsets, schema history and retained source logs must survive recovery together. Backpressure that outlasts source-log retention requires a deliberate resnapshot procedure, not an assertion that every gap can be replayed forever.

Trade-offs and limits

ApproachProvidesRequires
Initial snapshot plus logBootstraps history while following new changes.Snapshot overlap and retained offsets need a coordinated protocol.
Periodic bulk exportSimplifies a low-frequency downstream refresh.Freshness and deletion handling become coarse and expensive.

Recovery decision

Hypothetical scenario: Snapshot rows race with live updates and overwrite newer projection versions. Join the snapshot and stream at a defined boundary and compare source versions.

Not if a required consumer still needs that segment. Retention must account for lagging recovery positions and acceptable rebuild procedures.

Write your design before revealing the review

Can deleting an old log segment be harmless because the database is healthy?

Evidence you can explain in your own design

Drafts and self-review are stored only in this browser. They are separate from reading completion.

Compare your decision

Not if a required consumer still needs that segment. Retention must account for lagging recovery positions and acceptable rebuild procedures.

Snapshot rows race with live updates and overwrite newer projection versions. Join the snapshot and stream at a defined boundary and compare source versions.

Check your understanding

Can deleting an old log segment be harmless because the database is healthy?

Not if a required consumer still needs that segment. Retention must account for lagging recovery positions and acceptable rebuild procedures.

How would you recover from this failure: Snapshot rows race with live updates and overwrite newer projection versions. Join the snapshot and stream at a defined boundary and compare source versions.

Start with the exact boundary that failed. Choose a consistent snapshot and source position. Emit committed changes with source identity/order. Apply idempotent version-aware updates and durable progress. Then recover evidence through the observation path: Inspect projection version and source lag. Recover from retained log positions. Rebuild rather than silently skipping a missing history interval. Preserve the distinction between a confirmed state change and an unavailable response.

Which assumption in the worked calculation would a burst or concentrated tenant invalidate first?

Hypothetical source generates 5 MB/s of retained changes. A connector offline for two hours needs 5 × 7,200 = 36,000 MB, or 36 GB, of relevant history before overhead. A 10 GB retention budget cannot promise that outage recovery horizon. Recompute the affected resource rather than multiplying unrelated storage and network budgets by the same factor. Replicate committed database changes into projections while preserving a coherent snapshot/stream boundary. A connector position is recovery evidence, not proof that every external effect is complete.

Which component in this topology could be removed from a smaller first deployment?

Database log, Snapshot reader, Change stream, Projection sink name responsibilities, not a requirement for separate processes. Co-locate responsibilities when their transaction, trust and capacity boundaries permit it. Choose a consistent snapshot and source position.

What evidence must a caller have before relying on the observation path?

Inspect projection version and source lag. Recover from retained log positions. Rebuild rather than silently skipping a missing history interval. Not if a required consumer still needs that segment. Retention must account for lagging recovery positions and acceptable rebuild procedures.

45-minute interview rubric

  1. 00–05: scope change event and source log position.
  2. 05–12: identify the limiting resource and derive the domain workload above, retaining units and assumptions.
  3. 12–28: draw source log position, numbered writes and reads.
  4. 28–40: challenge recovery: Join snapshot and log under explicit positions and identities.
  5. 40–45: defend source_partition placement, observations and remaining assumptions.

Go deeper

Decision log

Join snapshot and log under explicit positions and identities.

Preserve change event identity and source log position ownership.

Revisit changed workload, observations or recovery objectives.