Blog · 26 November 2026 · 1 min read

Keeping a full history of a live shop database without touching the app

Debezium reads the Postgres write-ahead log, Kafka carries the changes, and dbt builds SCD Type 2 history. Notes on getting exactly-once results from at-least-once delivery.

Project: E-commerce CDC Pipeline · live dashboard


The question behind this project: how do you keep a full, correct history of a live shop database without changing a single line of the application?

Explore the result in the interactive dashboard. It runs on a DuckDB snapshot in your browser, so there is no server to pause.

Read the log, not the tables

Polling tables misses deletes and anything that changes twice between polls. Instead, Debezium reads the Postgres write-ahead log, the same log the database uses for its own recovery. Every insert, update and delete becomes an event on a Kafka topic, in order, without the shop knowing.

Duplicates are normal, so plan for them

Kafka and Debezium promise at-least-once delivery. After a restart, some events come again. The loader lands events idempotently, keyed on the source position, so a replayed event overwrites itself instead of adding a row. At-least-once in, exactly-once results out.

History with SCD Type 2

Customers move and prices change. dbt models customers and product prices as SCD Type 2 dimensions: each version gets a valid-from and valid-to, and the current one is flagged.

That matters for a simple-sounding question like revenue by city. An order is credited to the city the customer lived in when they ordered, not where they live now. Without history, a customer moving from Tampere to Helsinki would quietly move their past spending too.

What the marts answer

On top of the star schema sit marts for revenue, retention cohorts, RFM segments, price elasticity and fulfilment SLAs. Because the history is correct, the cohort and elasticity numbers are too.

What I would do differently

I would add a schema registry from day one. A column change in the source is the most likely thing to break a CDC pipeline, and catching it at the topic is far cheaper than catching it in dbt.

Code: GitHub · Streamlit app

Portrait of Samwel Munyingi

Hi, I'm Samwel.

I'm a data engineer in Helsinki with a background in applied computer science. I build end-to-end pipelines on real open data, write about what breaks along the way, and teach data engineering for free.