Mapping data flows give you a visual ETL surface that compiles to a Spark job, which is genuinely useful for transformations that are too intricate for a copy activity and too simple to justify a Databricks notebook. The tool is easy to demo and surprisingly easy to make slow, so most of the value in this lesson comes from the decisions around it rather than from the canvas itself.
You will be able to do the following afterwards:
- Decide when a data flow beats copy activity or a notebook.
- Structure a flow that separates clean rows from rejected ones.
- Use debug mode to inspect data at every transformation.
- Size the underlying cluster so cost matches the workload.
Prerequisites
- !ADF datasets and pipelines
- !Basic understanding of Spark execution
- !A factory with debug cluster permissions
What a data flow is genuinely good for
A data flow shines when you need row-level transformations with visibility: joins against reference data, derived columns, conditional splits, and quality rules whose behaviour you want to inspect interactively. It sits between a copy activity, which moves data at speed, and a notebook, which gives full programming freedom.
The trade-off is that every data flow runs on a Spark cluster that you pay for while it executes. A flow that copies ten million rows unchanged costs far more than the equivalent copy activity, because you are renting compute to do nothing. Treat the data flow as the place where meaning is applied, and keep raw movement in the copy activity.
Design each flow around a single responsibility. One flow filters, joins, and writes to the silver layer; a second handles aggregation into the marts. Flows that try to do everything become unreadable graphs where a reviewer cannot tell which branch introduced a bad row.
Choosing transformations deliberately
Most flows need only a handful of transformations, and picking the right one for the job keeps the graph legible.
| Transformation | Purpose | Common misuse |
|---|---|---|
| Filter | Drop rows failing a condition | Used instead of routing, losing evidence |
| Conditional split | Route rows to different outputs | Duplicated logic across branches |
| Join | Combine two streaming inputs | Joining without considering skew |
| Lookup | Attach cached reference attributes | Used for very large reference tables |
| Derived column | Add or overwrite calculated fields | Hiding business logic in long expressions |
| Aggregate | Group and summarise | Aggregating before filtering |
Filter removes rows permanently, which is why quality-driven rejection should use a conditional split that sends failures to a quarantine sink instead. Keeping rejected rows costs little storage and saves hours of argument about whether the source or the pipeline dropped the data.
A flow that quarantines instead of discarding
The shape below filters on validity, joins customer reference data, derives calculated columns, and routes anything that fails a rule to a separate output.
{
"name": "df_sales_curate",
"properties": {
"type": "MappingDataFlow",
"typeProperties": {
"sources": [
{ "name": "src_sales", "dataset": { "referenceName": "ds_bronze_sales" } },
{ "name": "src_customers", "dataset": { "referenceName": "ds_dim_customer" } }
],
"sinks": [
{ "name": "sink_silver", "dataset": { "referenceName": "ds_silver_sales" } },
{ "name": "sink_quarantine", "dataset": { "referenceName": "ds_quarantine" } }
],
"transformations": [
{
"name": "rule_check",
"type": "ConditionalSplit",
"typeProperties": {
"otherwise": "rejected",
"splits": [
{
"name": "accepted",
"condition": "sale_id != null && quantity > 0 && unit_price > 0"
}
]
}
},
{
"name": "join_customer",
"type": "Join",
"typeProperties": {
"joinType": "LeftOuter",
"joinCondition": {
"$operator": "&&",
"left": "accepted.customer_id",
"right": "src_customers.customer_id"
}
}
},
{
"name": "derive_totals",
"type": "DerivedColumn",
"typeProperties": {
"columns": [
{ "name": "line_total", "expression": "accepted.quantity * accepted.unit_price" },
{ "name": "sale_year", "expression": "year(accepted.order_date)" }
]
}
}
]
}
}
}
Writing the flow out as JSON is worth doing once even if you author visually, because the diff in a pull request is what a reviewer actually reads.
Debug mode and row-level inspection
Debug mode allocates a cluster and lets you preview the data at any node in the graph. Use it before you wire the flow into a scheduled pipeline, not after the first failed production run.
from azure.identity import DefaultAzureCredential
from azure.mgmt.datafactory import DataFactoryManagementClient
credential = DefaultAzureCredential()
adf = DataFactoryManagementClient(credential, subscription_id)
run = adf.data_flow_runs.get(
resource_group_name="rg-data",
factory_name="adf-prod",
data_flow_run_id="run-id",
)
print(run.status, run.run_duration, run.cluster_size)
for t in run.transformations:
print(f"{t.name}: in={t.input_rows} out={t.output_rows}")
Compare input and output row counts at every transformation. A step that silently drops ninety percent of rows is either doing its job or doing it twice, and the preview is the fastest way to tell. Also check a handful of rows for type coercion, since a value that arrives as text and is used as a number will quietly become null rather than raising an error.
Schema drift without broken pipelines
Upstream systems add columns, reorder fields, and change types. Enable schema drift on the source so new columns are carried through rather than dropped, then decide explicitly which of those columns your transformation depends on.
Drift handling works best with three habits. First, keep explicit column mappings in the sink so unexpected additions do not change the physical layout of a downstream table. Second, log the observed schema each run and compare it with the previous one, so a change is visible even when nothing fails. Third, treat a type change as a breaking change: a column moving from string to decimal affects every downstream calculation, and it deserves a reviewed migration rather than an automatic promotion.
Sizing the cluster so the bill behaves
Data flow cost is a function of core count, compute type, and execution time. Oversizing makes each run expensive; undersizing makes it slow enough that the cluster runs longer, which can cost more overall.
| Setting | Lower cost | Higher cost |
|---|---|---|
| Core count | Fewer cores, longer runtime | More cores, shorter runtime |
| Compute type | General purpose | Memory optimized for wide joins |
| Parallelism | Few large partitions | Many small tasks with overhead |
| Debug cluster | Off when not authoring | On continuously during development |
Enable dynamic allocation where the workload is bursty, keep the minimum executor count low, and set a maximum you would be comfortable paying for at peak. Turn the debug cluster off when nobody is editing; a forgotten debug session is one of the quietest sources of spend in a factory.
Testing a flow before it earns a schedule
Treat the flow like any other code and give it a fixture. A small dataset with known-good rows, known-bad rows, and at least one edge case such as a zero quantity or a missing customer reference lets you assert the expected split rather than eyeballing a preview.
Wire that fixture into the release pipeline as a pipeline run against a development factory, and compare the row counts written to the silver and quarantine sinks with the expected values. When the numbers match, promote the same definition to production; when they do not, the failing assertion tells you which rule regressed without anyone having to reconstruct the scenario by hand.
Keep the fixtures in the repository next to the flow definition so they are reviewed together. A transformation change that alters row routing without updating the fixture should fail review, which is exactly the kind of pull request comment that prevents a quiet data loss from reaching the silver layer over a weekend.
Common Mistakes
Using a data flow to move data that needs no transformation
Fix: Use copy activity for movement, and reserve data flows for row-level logic that needs inspection.
Filtering bad rows away with no quarantine output
Fix: Route failures through a conditional split to a separate sink so the evidence survives.
Leaving debug clusters running after authoring sessions
Fix: Set an auto-timeout on debug and check cluster state as part of a weekly cost review.
Allowing schema drift to change a sink layout silently
Fix: Map sink columns explicitly and compare the observed schema run against run.
Best Practices
- Give each data flow one responsibility and a readable name
- Preview every transformation during development, not only the final output
- Quarantine rejected rows with the rule that rejected them
- Log observed schema and alert on unexpected change
- Review core count and parallelism after any large cost jump
Questions interviewers ask about data flows
đ¯Interview Tip
The comparison question, data flow versus copy activity, is nearly guaranteed. Answer with cost and capability: copy activity is optimized throughput for movement, while a data flow rents Spark to apply and inspect row-level logic.
Interview Questions
Q1: When would you use a lookup instead of a join?
Use lookup to attach attributes from a small reference dataset that fits in memory, since it caches the reference side. Use join when both inputs are streaming at scale and the reference data is too large to hold in memory for the whole run.
Q2: How do you handle schema drift?
Enable drift on the source so unknown columns flow through, keep explicit mappings in the sink, record the observed schema each run and compare it with the previous one, and treat any type change as a breaking change requiring review.
Q3: How do you optimize data flow performance?
Right-size core count and compute type, enable dynamic allocation with sensible bounds, reduce unnecessary columns early, filter before joining to shrink the working set, and avoid skew by checking row distribution across partitions.
Q4: Difference between filter and conditional split?
Filter discards rows that fail a condition, while conditional split routes rows to different outputs based on conditions. For data quality use conditional split so rejected rows land in quarantine with the reason attached instead of disappearing.
Key Takeaways
- Data flows apply meaning; copy activity handles movement
- Conditional split plus a quarantine sink preserves evidence of bad data
- Input and output counts at each step expose silent row loss
- Schema drift should be visible in logs even when nothing fails
- Cluster size, not just row count, drives data flow cost
- Author in debug mode, review the JSON, then publish through Git