🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

ETL Patterns: ADF, Databricks & Synapse Pipelines

Azure Data EngineeringETL Patterns⭐ Premium

Prerequisites

  • !The difference between transform-before-load and transform-after-load
  • !Basic SQL joins and aggregation
  • !What a staging area is for

What You'll Learn

  • 1State when transform-before-load is the right choice and defend it
  • 2Compare ADF mapping data flows, Databricks and Synapse Pipelines on the criteria that matter
  • 3Handle late arriving and rejected records without losing them
  • 4Design slowly changing dimensions that survive a re-run
  • 5Avoid the fan-out query pattern that silently multiplies rows

What ETL actually buys you

Extract, transform, load moves the transformation step ahead of the write, so the serving layer receives data that is already conformed, joined and cleaned. The opposite pattern, where raw data lands first and transformation happens at query time, trades storage for flexibility. Choosing between them is mostly about how well you know the shape of the questions being asked.

Transform-before-load wins when the output shape is stable and the serving layer is expensive per query. A dedicated SQL pool charges for compute on every scan, so pre-joining dimensions and pre-aggregating measures directly reduces the bill. It also means business rules are evaluated once rather than once per dashboard, which is where metric inconsistency usually comes from.

The cost of ETL is rigidity. Every new attribute means changing a transformation and backfilling, and a mistake in a rule is baked into stored results until someone notices. The mitigation is discipline: version the transformation code, keep raw data untouched so a backfill is possible, and reject rather than silently repair bad records.

CriterionADF mapping data flowDatabricks notebookSynapse pipeline
Who owns itData engineers comfortable with visual mappingEngineers comfortable with Spark codeEngineers already in Synapse
Best forSet-based conformance, SCDs, moderate joinsComplex logic, libraries, large joinsOrchestration inside the warehouse
DebuggingData flow debug session with row visualsSpark UI, notebooks, unit testsPipeline activity runs and logs
ReuseParameters and linked servicesLibraries and modulesStored procedures and activities
Cost modelManaged cluster per debug and runCluster you size and terminateWarehouse and integration runtime

The honest answer in an interview is rarely one tool. A pattern that works is extraction and light conformance in ADF, heavy transformation in Databricks, and loading plus validation in Synapse, with ADF or a Synapse pipeline orchestrating the whole sequence.

Extraction: the parts that break quietly

Extraction fails in ways that look like success. A source query with a date filter that excludes rows because of a timezone mismatch returns fewer rows without raising an error. A bulk read that times out on a large table can leave a partial file that downstream treats as complete.

The countermeasures are mechanical. Record the source's maximum watermark and row count at extract time, write them into a control table alongside the output file name, and have the next stage assert the counts match. Compare a checksum of the primary key range rather than only totals, because totals match surprisingly often when rows are both added and removed.

python
import pyodbc
import pandas as pd

def extract_orders(server, database, watermark):
    conn = pyodbc.connect(
        f"DRIVER={{ODBC Driver 18 for SQL Server}};SERVER={server};"
        f"DATABASE={database};Trusted_Connection=yes;TrustServerCertificate=yes"
    )
    query = """
        SELECT OrderId, CustomerId, Status, Amount, ModifiedAt
        FROM dbo.Orders
        WHERE ModifiedAt > ?
        ORDER BY ModifiedAt
    """
    df = pd.read_sql(query, conn, params=[watermark])
    conn.close()
    return df

def write_with_control(df, path, watermark_column, spark):
    high = df[watermark_column].max()
    (spark.createDataFrame(df)
         .write.mode("append")
         .parquet(path))
    return {"rows": len(df), "high_watermark": str(high)}

Returning the control record alongside the data makes the assertion the caller's responsibility rather than a side effect buried in a helper. That is the difference between a pipeline that notices a short extract and one that ships it.

Transformation: joins, fan-out and slowly changing dimensions

The fan-out bug is the most common correctness defect in ETL work. Joining a fact to a dimension without constraining the version produces multiple rows per fact when the dimension has more than one version, and every total downstream silently doubles.

Slowly changing dimension handling is where this becomes explicit. Type one overwrites history, which is fast and wrong for anything analysed over time. Type two keeps every version with valid-from and valid-to dates, which is correct and adds a join predicate to every query. Type three keeps the previous value in an extra column, which suits a narrow set of attributes such as region.

-- Type 2 dimension with explicit validity windows
MERGE INTO sales.dim_customer AS target
USING staged_customer AS source
  ON target.customer_key = source.customer_key
  AND target.is_current = 1
WHEN MATCHED AND (
      target.email <> source.email
   OR target.segment <> source.segment
) THEN UPDATE SET
  target.is_current = 0,
  target.valid_to = DATEADD(day, -1, CAST(source.effective_from AS date))
WHEN NOT MATCHED THEN INSERT (customer_key, email, segment, valid_from, valid_to, is_current)
  VALUES (source.customer_key, source.email, source.segment,
          CAST(source.effective_from AS date), '9999-12-31', 1);

-- Facts must join on validity, not only on the key
SELECT f.order_id, c.segment, f.amount
FROM sales.fact_order f
JOIN sales.dim_customer c
  ON f.customer_key = c.customer_key
 AND f.order_date BETWEEN c.valid_from AND c.valid_to;

The second query is the one to memorise. Joining only on customer_key with a type two dimension returns the current segment for historical orders, which is precisely the error that makes a quarter's revenue attribution wrong in a way nobody notices until a customer disputes it.

Handling records that do not belong

Every real source contains records that cannot be loaded: malformed dates, orphaned foreign keys, values outside a permitted range. The three options are reject them, repair them, or fail the pipeline. Failing on a single bad row in a feed of millions is operationally unacceptable, and repairing silently hides data quality problems until they are expensive.

The pattern that holds up is a quarantine path. Records failing validation are written to a quarantine folder or table with the reason attached, the good records continue, and a counter feeds a data quality dashboard. The quarantine is then a work item rather than an invisible loss.

OutcomeWhen it is rightOperational consequence
Quarantine and continueVolume sources with intermittent defectsRequires an owner to triage daily
Fail the pipelineRegulatory loads where partial data is dangerousNeeds a fast human response
Repair with a documented ruleKnown, bounded issues such as timezone offsetsThe rule becomes part of the contract
Drop silentlyAlmost neverGuarantees a future audit finding

Reprocessing is the other half of the story. Because raw data is retained untouched, a fixed rule can be applied to the quarantine folder and merged in later, which is only possible if rejection was recorded rather than discarded.

Loading into the serving layer

The load step should be boring: a bounded set of statements with a defined rollback story. For a dedicated pool that means staging, distribution-aware movement and statistics refresh. For a Delta table it means a MERGE on a natural key with an explicit source-system qualifier.

Whatever the target, the load must be idempotent. Re-running today's load must produce today's table, not today's table plus a duplicate of today's load. Idempotency is what makes retries, backfills and re-deploys safe rather than nerve-wracking.

-- Idempotent daily load: replace the partition, then refresh metadata
BEGIN TRANSACTION;

DELETE FROM sales.fact_order WHERE order_date = '2026-10-11';

INSERT INTO sales.fact_order
SELECT * FROM stg.fact_order WHERE order_date = '2026-10-11';

UPDATE STATISTICS sales.fact_order WITH FULLSCAN;

COMMIT TRANSACTION;

Wrapping delete and insert in one transaction means a failure mid-load leaves yesterday's numbers visible rather than an empty day. Statistics refresh inside the same transaction costs time but prevents the query planner from running against stale distribution metadata straight after a large load.

Orchestrating the sequence

The orchestrator's job is dependency, not logic. Each activity declares what it consumes and what it produces, and failure propagates so downstream work stops rather than running on stale input. The two design choices that matter are how runs are identified and how partial failures recover.

A logical run identifier, usually the business date, should be threaded through every stage as a parameter. It keys the control records, the output partitions and the alerts, which makes a targeted re-run of one date possible without touching anything else. Pipelines that infer the run date from the current clock make backfills awkward and dangerous.

Common Mistakes

Joining a fact to a type two dimension without a validity predicate

Fix: Constrain the join with the fact date between valid_from and valid_to, and verify totals against a known baseline

Dropping rows that fail validation

Fix: Write them to a quarantine store with a reason and feed the count into a data quality metric

Deriving the run date from the system clock inside each stage

Fix: Thread an explicit run identifier parameter through every stage so backfills are deterministic

Choosing one tool for every stage because it keeps the estate simple

Fix: Match each stage to the engine that fits: visual mapping for conformance, notebooks for complex logic, warehouse for serving

Best Practices

  • Keep raw data immutable so any transformation rule can be backfilled
  • Record extract control counts and assert them before transformation proceeds
  • Make every load idempotent before enabling retries
  • Version transformation code alongside the pipeline definitions that invoke it

Interview Questions

Q1: When would you choose ETL over ELT?

When the serving compute is expensive per query or cannot handle raw shapes, so joining and aggregating before the load reduces total cost. Also when compliance requires that unvalidated records never reach the serving layer.

Q2: Explain the fan-out problem in dimensional modelling.

Joining a fact to a dimension that has multiple versions without a validity predicate duplicates fact rows and inflates every total. The fix is a date-range predicate against valid_from and valid_to.

Q3: How do you handle records that fail validation in a high-volume feed?

Quarantine them with a reason code, continue processing valid records, and publish the rejection count as a data quality metric so someone owns triage.

Q4: Why must a load be idempotent?

So a retry, backfill or re-deploy produces the same result rather than duplicates. Idempotency is what makes aggressive retry policy safe.

Q5: Compare ADF mapping data flows with Databricks for transformation.

Data flows are visual, parameterised and well suited to set-based conformance and SCDs. Databricks wins for complex logic, libraries and large joins, at the cost of owning notebooks and cluster configuration.

Key Takeaways

  • Transform-before-load trades flexibility for compute efficiency and consistent rules
  • Control counts at extract time are what make silent truncation detectable
  • Type two dimensions require a validity predicate on every fact join
  • Quarantine beats dropping, because rejected rows can be recovered once the rule is fixed
  • An explicit run identifier threaded through every stage is what makes backfills safe
🔒

Premium Content

ETL Patterns: ADF, Databricks & Synapse Pipelines

You've previewed the first section. Unlock this full lesson and 900+ advanced tutorials with a Premium plan.

đŸŽ¯End-to-end Projects
đŸ’ŧInterview Prep
📜Certificates
🤝Community Access

Already a member? Log in

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-12

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Advertisement