← Building blocks

Move data between systems

Data processing & searchsenior

Analytics, search and ML each need a copy of production data in their own shape.

Say it like this

Search, analytics and the model each need production data in a different shape, so I run one pipeline that extracts changes from the source, transforms them per target, and loads idempotently, with the DAG scheduled and monitored as a product in its own right.

Basic solution

Extract from sources (CDC or dumps), transform, load into the target; schedule and monitor it as a DAG.

AirflowFivetranKafka ConnectDebezium

One extract, a raw zone, many targets

Changes are captured once from the source and landed raw; each target has its own transform node, and loads are upserts so any node can be rerun. Validation sits between transform and load.

How it works

  1. Extract: read the changes from each source. The preferred way is a change stream, either CDC reading the database's write-ahead log or the event topic the application already publishes to, because it captures every insert, update and delete as it happens. The fallback is a periodic query for rows whose updated_at is newer than the last run; the last resort is a full dump of the table.
  2. Land raw: write the extracted rows exactly as received into a raw zone, a folder in object storage or a raw schema in the warehouse, partitioned by when they were extracted. The raw zone is append-only and never edited, so it is the record of what the source said.
  3. Transform: build each target's shape from the raw rows with versioned code: flatten nested JSON into columns, join reference tables, mask personal data, aggregate. Each transform is a node in a DAG that declares which inputs it reads and which output it writes.
  4. Load: write the transformed rows into the target (a warehouse table, a search index, a feature store) as upserts keyed by a stable id, or as a full overwrite of one partition. Either way, loading the same rows twice leaves the target unchanged.
  5. Validate: before publishing, compare row counts with the source, check null rates, confirm foreign keys resolve, and check that the newest row is as fresh as expected. A failed check stops the run and alerts instead of publishing bad data.
  6. Schedule and observe: the orchestrator runs each node when its inputs are ready, retries failures, and records lineage, the chain of which node read which input, so a wrong number on a dashboard can be traced back to the node and source that produced it.

ETL versus ELT

  • ETL transforms the data before loading, on the pipeline's own compute. ELT loads the raw data into the warehouse first and transforms there in SQL. ELT is the default today because warehouse compute is elastic and the raw data stays available for transforms you have not written yet.

Worked example

Notification system: delivery data to analytics, search and the ML team

  • Source: the notification and delivery tables, 250M notification rows and 300M delivery rows per day, in Postgres partitioned by day.
  • Extract: Debezium reads the Postgres WAL and publishes row changes to Kafka; about 600M change events per day, 1 KB each, 600 GB of change traffic that Kafka Connect sinks to S3 as hourly Parquet files of roughly 60 GB per day compressed.
  • Targets: a warehouse table for per-channel delivery rates (aggregated, 10M rows per day), an OpenSearch index for support staff to find a user's notifications (last 30 days, about 7.5B documents, 3 TB), and a feature table for the send-time model (per user, 50M rows, rebuilt nightly).
  • Transforms: strip the message body before the analytics load (PII), join template metadata, derive delivered_latency = delivered_at - created_at. Three transform nodes share the one raw extract.
  • Latency: warehouse and search targets update within 5 minutes of the source change via the streaming sink; the feature table is a nightly batch node because the model trains daily.
  • Idempotency: the warehouse load is a MERGE on delivery_id; the search load is an upsert by document id; a replay of a day's change events produces no duplicates.
  • Cost of the alternative: each team querying Postgres directly would add three heavy readers to the transactional database and three copies of the masking logic.

Variants and when each wins

Managed connectors (Fivetran, Airbyte)

  • A hosted service that copies tables from a source into the warehouse with no code, with transforms done afterwards in dbt. It wins on setup time; you give up control over the shape of the copy and over cost.

Streaming pipeline (Kafka Connect, Debezium, Flink)

  • Changes flow continuously from the source's change log through connectors into the targets. It wins when the target must lag the source by seconds and the transforms are per row rather than aggregates.

Orchestrated batch DAG (Airflow, Dagster, dbt)

  • Scheduled nodes with lineage, retries and backfills, each node a transform over a partition. It wins for daily joins and aggregates; it is the workhorse of most data teams.

Reverse ETL

  • Results computed in the warehouse pushed back into operational tools such as a CRM or an email system. It wins when the business acts on warehouse data; it needs the same idempotent-load discipline in the opposite direction.

Recommendation: CDC into a raw zone, dbt-style transforms in the warehouse for analytics, and a streaming sink only for the targets that need minutes rather than hours.

Failure modes

Schema drift breaks a load

  • The pipeline fails at 02:00 with a type error, or worse, loads a column of nulls without complaint. It happens because a source column was renamed or changed type and the transform was written against the old shape. Put the source behind a schema registry or contract tests, keep the raw zone tolerant of new columns, and alert when the source schema changes.

Duplicate rows after a retry

  • Delivery counts for one day are 3 percent too high. It happens because a load that appends rows was retried after it had partly succeeded, so the rows from the first attempt were loaded twice. Load with upserts keyed by a stable id, or overwrite the whole partition; never append to a target.

Late-arriving data

  • Yesterday's totals keep changing for a week. It happens because events for day D continue to arrive on D+1 and later, after that day's run already finished. Reprocess a trailing window of the last three days on every run, and version the published numbers so consumers can see that a figure was revised.

PII leaks into a target

  • Message bodies appear in the search index. It happens because the masking step lived inside one target's transform, and a new target was added that read raw data directly. Mask once in the step from raw to curated, so every downstream target reads masked data.

Nobody owns the pipeline

  • The dashboard has been stale for a week and nobody noticed. It happens because there is no freshness objective and alerts go to a channel nobody reads. Define a freshness check per target with a named on-call owner, and use lineage so the alert names the exact node that broke.

Interviewer follow-ups

Answer out loud before you open each one.

How do you avoid double loading when a pipeline step is retried?

Make every load idempotent: upsert by a stable key, or overwrite the whole output partition for the run. Then a retry produces the same target state as a single success, and the orchestrator can retry freely.

Why keep a raw copy before transforming?

Raw is the replay buffer. When a transform has a bug or a new target appears, you rebuild from raw without touching the source database again, and you can prove what the source said at the time.

How do you choose between CDC and periodic queries for extraction?

CDC when the source is a database you control and freshness or load matters, because it captures every change including deletes with no query load. Periodic queries on updated_at when CDC is not available, accepting that hard deletes are missed and the polling interval sets the lag.

What does lineage buy you in an incident?

When a number on a dashboard is wrong, lineage walks back from that table through each transform to the raw extract and the source, so you find the node that changed and the other targets it affected. Without it, the investigation is a grep through scripts.

Connections

Built on
DAG of tasks
Pairs with
React to database changes · Process large data offline · Analytics without hurting production · Full-text and fuzzy search · Run work later or on a schedule · Make retries safe

The same parts on other clouds

The diagrams above name AWS services as one concrete example. Every part has a close equivalent elsewhere. In an interview, name the role first, such as “a managed Redis cache”, then the product you would pick.

AWSUsed here asGoogle CloudMicrosoft AzureOpen source and others
Amazon AuroraPostgres (source)AlloyDB for PostgreSQL, Cloud SQLAzure Database for PostgreSQL or MySQLPostgreSQL, MySQL, CockroachDB
Amazon EC2 Auto ScalingDebezium / ConnectCompute Engine managed instance groupsVirtual Machine Scale SetsKubernetes Deployment with a HorizontalPodAutoscaler, Nomad
Amazon S3Raw zone (S3)Cloud StorageBlob StorageCloudflare R2, MinIO, Ceph
Amazon EMRTransform DAGDataprocAzure Databricks, HDInsightApache Spark, Databricks
Amazon RedshiftWarehouseBigQuerySynapse Analytics, Microsoft FabricClickHouse, Snowflake, Apache Druid
Amazon OpenSearch ServiceOpenSearchElastic Cloud on Google CloudAzure AI SearchElasticsearch, OpenSearch, Apache Solr