ActualBuild Start a project

Work / Case study 02

Kafka CDC

Moving PolicyBazaar's data from 3-hour batches to a stream that lands in 10–15 minutes, across 8,000+ tables and billions of records.

Type
Internship · Product Engineering, PolicyBazaar (PB Fintech)
Scope
Team of 4 · I owned 12+ table pipelines end to end
Stack
Kafka · Debezium · MySQL · MSSQL · AWS · Airflow
When
Jan – Jun 2026
Before: batches with long waits in between. After: a continuous stream of change events. Data lag went from 2–3 hours to 10–15 minutes.

01 — The problem

The dashboards were always a few hours behind.

Policy, customer and order data lived in transactional MySQL and MSSQL databases. Getting it to analysts went through a batch-first pipeline: AWS DMS and Sqoop pulled data into an S3 lake (raw → processed → curated), Glue and EMR transformed it, Athena served SQL, and Metabase drew the dashboards. Airflow ran it all and logged every run to a Postgres metadata store.

It was observable and auditable. It was also slow: changes reached the dashboards 2–3 hours after they happened in production, across 8,000+ tables. For an insurance business with millions of policyholders, that's not live reporting. Three constraints shaped the migration:

  1. Production databases don't feel it. Ingestion can't add load to the systems customers use.
  2. Trust survives the move. Analysts depended on the existing dashboards and quality checks, so the new path had to stay just as auditable.
  3. No big-bang cutover. 8,000+ tables can't all move in one weekend.

02 — The approach

Read the log, not the tables.

Polling tables on a schedule means every change waits for the next batch. Change data capture flips it: Debezium tails each database's transaction log and turns every insert, update and delete into an event on Kafka the moment it commits. Watch one change travel:

CDC path: MySQL and MSSQL, Debezium, Kafka, S3 data lake, Glue and EMR, Athena, Metabase; Airflow and a Postgres metadata store as supporting pieces.AWS · data lake & analyticsMySQL · MSSQLtransaction logsDebeziumCDC connectorsKafkatopic per tableS3 data lakeraw → curatedGlue · EMRPySpark transformsAthenaserverless SQLMetabasedashboardsAirflow5 single-job DAGsPostgresmetadata store123456
Change pathGrey lines: orchestration & pipeline health
  1. 1
    Read the log

    Debezium tails the MySQL binlog and MSSQL change tables. Nothing scans production tables row by row.

  2. 2
    One topic per table

    Each table's changes get their own Kafka topic, so one busy table can't hold up the rest.

  3. 3
    Land in the lake

    Events land in the S3 raw zone. Raw stays untouched, so anything can be reprocessed.

  4. 4
    Same transforms, fresher input

    Glue and EMR (PySpark) build the processed and curated layers, now from minutes-old data.

  5. 5
    Same dashboards

    Athena and Metabase didn't change for analysts. The data just stopped being hours old.

  6. 6
    Health you can query

    Airflow writes run status and row counts to Postgres, so pipeline health is a dashboard, not a log search.

03 — Decisions in numbers

10–15 min
End-to-end data lag after moving from scheduled batches to log-based CDC, down from 2–3 hours, on billions of records.
8,000+ tables
Scope of the migration, moved by a team of four. I owned 12+ of the pipelines end to end.
80 → 44 min
A distributed job's runtime (−45%) after re-tuning its partitioning and joins.
5 DAGs
Ingest → Transform → Catalog → Quality → Notify. One job each, so one failure never hides another.

04 — Decisions & the hard part

The 80-minute job

Symptom A downstream distributed job took 80 minutes and ate the freshness gained upstream.

Cause Partitioning and join strategy didn't fit the data's shape.

Fix Re-tuned both. 80 → 44 minutes, a 45% cut.

Right tool per table

Choice Streaming where freshness matters, batch where it doesn't.

Why CDC everywhere over-engineers slow tables. Batch everywhere leaves orders stale.

Trade-off More than one ingestion path to run and monitor.

Health in a table

Choice Every run writes status, row counts and quality results to Postgres.

Why "Is today's data complete?" should be one dashboard, readable by non-engineers.

Trade-off One more store to keep in sync with the pipeline.

05 — Honest gaps & what's next

  • Minutes, not seconds. The remaining lag sits in landing and batch transforms. Streaming transforms are the next step for tables that need it.
  • Schema drift. Source schema changes still needed a human. Automated drift alerts were on the roadmap.
  • Quality checks run late. Null-rate and row-count-delta checks belong in ingestion, not after transform.
  • Cost per run. Tracking Glue, EMR and Athena spend per run in the metadata store was planned, not done.
  • Internal details stay internal. No schemas, table names or numbers here beyond what's public on my resume.
Go deeper · Medium ↗ The original pipeline: three-zone S3 lake, five Airflow DAGs and the metadata store →

Data hours behind?

I've helped move billions of records from batch to streaming. Happy to look at yours.

Get in touch