THN Interview Prep

CDC, outbox & projections

Senior loops punish naive dual-write (update DB + fire-and-forget cache/search). This page is the standard fix vocabulary: CDC, transactional outbox, and projections.


Quick mental model

PatternIdeaFailure mode you avoid
Dual-write (app)Two writes from handlerPartial success—DB ok, cache/index not
Transactional outboxSame DB txn writes business row + outbox rowAt-least-once relay must be idempotent downstream
CDCLog tail of DB changes (WAL/binlog) → bus/streamOperational complexity; schema drift handling
Loading diagram…

Transactional outbox (microservices default story)

  1. Begin transaction.
  2. Persist domain change + outbox row (topic, payload, schema_version).
  3. Commit (atomic).
  4. Relay process publishes to broker (Kafka/SNS/SQS/Rabbit) and marks outbox sent or deletes with tombstone policy.
  5. Consumers process idempotently (natural key / dedupe table).
Loading diagram…

Node.js: relay can be separate worker process; use SELECT FOR UPDATE SKIP LOCKED class patterns for concurrent relays where supported.


CDC (change data capture)

Sources: Postgres logical replication, Debezium on Kafka Connect, DMS, RDS native feeds—vendor-specific.

Flow: WAL/binlog → capturestreamwarehouse, Elasticsearch, analytics.

Pros: No second write in request path; fewer partial states.
Cons: lag, ordering per partition, schema evolution, ops burden.

┌────────┐    WAL / binlog     ┌──────────┐     ┌─────────────┐
│  OLTP  │ ─────────────────►  │  CDC     │ ──► │ Warehouse / │
│  (RDS) │     (ordered log)   │ connector│     │ search proj.│
└────────┘                     └──────────┘     └─────────────┘

Projections & read models

Projection = materialized view for a read path (search doc, cache warm list, dashboard aggregates).

Rules staff state aloud:

  • Rebuild path if projection drifts (replay from outbox or CDC).
  • Version events; tolerate duplicate delivery.
  • Backpressure consumers when downstream slow.

When to choose which

SituationBias
Same DB, must publish with writeOutbox
Many downstream replicas, infra owns pipeCDC
Low volume, simple invalidationSynchronous delete cache key + accept latency (still watch races)

Diagram — compare three integration shapes

Loading diagram…

See also

Last updated on

Spotted something unclear or wrong on this page?

On this page