Chapter 8
Data Transformation, Quality and Observability
Post Graduate Program in Information Technology
Big Data Engineering
•
Post Graduate
Data Transformation, Quality and Observability
Introduction
A data product is trustworthy only when its meaning, structure, freshness, and operational behaviour are controlled. In a modern data platform, raw events may pass through ingestion, parsing, enrichment, aggregation, storage, and serving layers before they support a dashboard, machine-learning model, regulatory report, or automated decision. Each transformation can introduce defects. Consequently, data engineering is not merely the movement of data; it is the disciplined production of reliable information.
This chapter presents an integrated approach to transformation, data quality, metadata, lineage, contracts, anomaly detection, and observability. The emphasis is on reusable engineering practices suitable for batch and streaming systems. A central argument is that quality must be designed into transformations and measured as a service characteristic, rather than inspected only after failures occur.
Learning Objectives
After studying this chapter, the reader should be able to:
Design modular, deterministic, tested data transformations.
Distinguish data quality dimensions and select appropriate controls.
Apply profiling, validation, data contracts, metadata, and lineage.
Design anomaly-detection approaches for data pipelines.
Define data observability metrics, service-level indicators (SLIs), and service-level objectives (SLOs).
Analyse governance, privacy, ethical, and operational implications of unreliable data products.
Evaluate a data-quality incident and propose a sustainable remediation strategy.
1. Data Transformation as an Engineering Discipline
A transformation maps input data to an output according to an explicit specification. In abstract form:
y = T(x; θ)
Here, x is the input dataset, y is the output dataset, T is the transformation, and θ represents configuration such as business rules, reference tables, or time windows. The expression is useful only when the assumptions about schema, units, time zone, null handling, and reference data are documented.
A production transformation should normally be:
Deterministic: identical inputs and configuration produce identical outputs, except where explicitly designed otherwise.
Idempotent: rerunning the same logical interval does not create duplicate or contradictory results.
Composable: the transformation has a clear input and output contract and can be combined with other stages.
Observable: its inputs, outputs, duration, failures, and quality measurements are recorded.
Testable: business rules can be evaluated independently of the production scheduler.
Reproducible: the relevant code version, data version, configuration, and reference data can be identified.
1.1 Transformation patterns
Common patterns include filtering, projection, standardisation, joining, deduplication, enrichment, aggregation, and feature construction. Each has characteristic risks.
Pattern
Typical purpose
Typical risk
Filtering
Remove invalid or irrelevant records
Accidental loss through incorrect predicates
Standardisation
Harmonise names, types, units, or formats
Silent semantic changes
Join
Combine facts with dimensions or reference data
Row multiplication or unmatched keys
Deduplication
Keep one logical record
Incorrect definition of identity
Aggregation
Produce summaries
Wrong grain or time boundary
Enrichment
Add external or reference attributes
Stale or version-inconsistent reference data
The grain of a dataset is the meaning of one row. For example, “one row per order line” differs from “one row per order.” Many serious defects are grain defects: a join intended to preserve one row per order instead creates several rows because the dimension key is not unique.
1.2 Reusable transformation design
A robust pipeline separates business logic from infrastructure. SQL models, Spark functions, or Python components should receive explicit inputs and return well-defined outputs. Configuration such as time zones and thresholds should not be hidden in code. A useful design document states:
input tables, event time, and expected grain;
output schema, types, units, and permitted nullability;
keys and uniqueness assumptions;
transformation rules and precedence;
late-arriving and corrected-data behaviour;
error-handling and quarantine policy;
ownership, version, and downstream consumers.
For incremental processing, a watermark identifies progress through an event-time stream. However, a watermark is not proof that all events before that time have arrived. The design must specify allowed lateness and the policy for corrections. In batch systems, partition-based processing should similarly define whether reruns replace, merge, or append partitions.
2. Data Quality: Dimensions and Measurement
Data quality is fitness for a defined use. A dataset can be accurate enough for exploratory analysis but unacceptable for a financial report. Quality therefore requires a stated use case, population, time period, and acceptance threshold.
Important dimensions include:
Completeness: required values or records are present.
Validity: values conform to permitted formats, types, ranges, and code sets.
Accuracy: values represent the real-world entity or event correctly.
Consistency: related datasets do not contradict one another.
Uniqueness: a logical entity or event is not represented more than once.
Timeliness: data arrives and becomes usable within the required time.
Integrity: relationships, such as foreign-key references, are preserved.
Freshness: the data reflects the required recency, not merely successful pipeline execution.
These dimensions are related but not interchangeable. A duplicated record may be complete and valid yet fail uniqueness. A fresh dataset may still be inaccurate.
2.1 Quality metrics
For a dataset containing N records, a simple completeness rate for a required attribute is:
C = Nnon-null / N
where Nnon-null is the number of records with a non-null value and N > 0. The result is a proportion between 0 and 1, often reported as a percentage. It does not establish accuracy.
A validity rate can be defined similarly:
V = Nvalid / Nevaluated
where Nvalid satisfies the validation rule and Nevaluated excludes records for which the rule is not applicable, if that exclusion is explicitly justified.
For a set of monitored quality rules with weights wi, where wi ≥ 0 and ∑wi = 1, a weighted score may be calculated as:
Q = ∑(wi qi)
where qi is the measured score for rule i. A weighted score is useful for prioritisation, but it can conceal a critical failure. Therefore, organisations should combine aggregate scores with hard gates—for example, “payment amount validity must be 100%.”
Worked example: completeness and validity
A daily customer extract contains 50,000 rows. The email field is non-null in 49,250 rows, and 48,500 of those values satisfy the organisation’s syntax and domain rules. Thus:
C = 49,250 / 50,000 = 0.985 = 98.5%
If validity is measured over all rows:
V = 48,500 / 50,000 = 0.97 = 97.0%
If validity is measured only among non-null values, its conditional validity is:
Vconditional = 48,500 / 49,250 ≈ 98.48%
The denominators answer different questions and must be labelled. A quality dashboard that reports 98.48% without explaining the denominator may create a misleading impression.
3. Profiling and Validation
Data profiling is the systematic examination of data characteristics. Basic profiling reports row counts, null rates, distinct counts, minimum and maximum values, quantiles, frequent values, patterns, and key relationships. Profiling is exploratory: it discovers what is present. Validation is normative: it tests what should be present.
A mature workflow is:
Profile a representative baseline.
Identify business-critical assumptions.
Express assumptions as executable rules.
Run checks at ingestion, transformation boundaries, and serving layers.
Classify failures by severity.
Route invalid records or stop publication according to policy.
Review rules as schemas and business processes change.
Examples of validation rules include:
order_id is non-null and unique at order grain.
quantity is an integer greater than zero.
currency belongs to an approved code set.
ship_date is not earlier than order_date.
every product key exists in the product dimension, subject to documented late-arrival rules.
daily revenue reconciles to the source within an approved tolerance.
Validation should occur at the right grain. A uniqueness test on order_id is incorrect for an order-line table if multiple rows per order are legitimate. Likewise, a range rule must account for units and exceptional but valid values.
3.1 Handling failures
Three common policies are:
Fail closed: stop publication when a critical rule fails.
Fail open with warning: publish data while recording an incident; suitable only when risk is low and consumers can tolerate degradation.
Quarantine: separate invalid records for investigation while processing valid records.
Quarantine is not deletion. The original record, reason, rule version, ingestion time, and remediation status should be retained, subject to privacy and retention controls. Silent coercion—such as converting an invalid date to null—can be more dangerous than an explicit failure because it hides the cause.
4. Data Contracts, Metadata and Lineage
A data contract is an explicit agreement between a producer and consumers about a data product. It normally includes schema, semantics, keys, quality guarantees, freshness, compatibility rules, ownership, privacy classification, and change-management procedures.
Contracts should distinguish:
Structural compatibility: fields and types remain readable.
Semantic compatibility: field meanings and units remain stable.
Operational compatibility: delivery schedule and availability remain adequate.
Policy compatibility: access, retention, and permitted uses remain lawful and authorised.
Schema compatibility alone is insufficient. Renaming amount from “tax-inclusive order amount” to “pre-tax amount” may preserve the data type while breaking every consumer.
Metadata provides context needed to interpret and operate data. Technical metadata includes schemas, partitions, file sizes, and job versions. Business metadata includes definitions, owners, stewardship responsibilities, and criticality. Operational metadata includes run duration, row counts, quality results, and incident history. Sensitive-data metadata includes classification, retention period, and approved purpose.
Lineage records how data moves and changes. At a coarse level it maps datasets and jobs; at a finer level it maps columns and expressions. Lineage supports impact analysis, root-cause investigation, regulatory explanation, and controlled deprecation. It is most valuable when captured automatically from orchestration and transformation systems, then supplemented with business definitions.
A useful conceptual chain is:
Data product trust chain from source to consumer
Figure: Data product trust chain from source to consumer
Figure: Controls and context connect source data to trustworthy consumption.
5. Anomaly Detection for Data Pipelines
An anomaly is an observation or pattern that differs materially from expected behaviour. Detection should be tied to a meaningful operational question, not applied indiscriminately.
5.1 Rule-based detection
Static rules are transparent and effective for hard constraints: negative quantities, impossible dates, unknown codes, or missing partitions. Dynamic rules compare current behaviour with historical baselines. For a metric with historical mean μ and standard deviation σ, a standardised score is:
z = (x − μ) / σ
Here, x is the current observation. A threshold such as |z| > 3 is only a heuristic; it assumes the baseline is reasonably stable and interpretable, and it can perform poorly for skewed, seasonal, or autocorrelated data.
A rolling mean over the previous k observations is:
x̄t = (1/k) ∑(i=1 to k) xt−i
The current observation should not be included when the intention is to compare it with prior behaviour. For daily data with weekly seasonality, comparing Monday with all preceding days may be inferior to comparing it with previous Mondays.
5.2 Statistical and machine-learning methods
Quantile thresholds are robust to outliers; the interquartile range is IQR = Q3 − Q1, where Q1 and Q3 are the first and third quartiles. A common exploratory rule flags values below Q1 − 1.5IQR or above Q3 + 1.5IQR. It is not a universal decision rule and should not be treated as proof of invalidity.
More advanced methods include change-point detection, exponentially weighted moving averages, isolation forests, and autoencoders. These can detect complex patterns but introduce training-data, explainability, drift, and false-positive risks. In high-consequence systems, a model-based alert should normally be accompanied by a clear reason code and a deterministic validation rule where possible.
Alert quality matters. Excessive false positives create alert fatigue; missed anomalies create latent risk. Thresholds should be calibrated using historical incidents, reviewed after process changes, and differentiated by criticality.
6. Observability and Data SLIs/SLOs
Traditional application observability examines logs, metrics, and traces. Data observability extends this approach to the health of datasets and pipelines. Common “data health” signals are:
freshness and delivery latency;
volume and row-count change;
schema and distribution change;
completeness and validity;
duplication and referential integrity;
pipeline execution and incident status;
lineage and downstream impact.
An SLI is a quantitative measure of a service aspect. An SLO is a target for that measure over a defined period. For example, an SLI may be the proportion of scheduled hourly partitions available within 15 minutes of the expected time. An SLO might require at least 99.5% over a rolling 30-day period.
Let ngood be the number of qualifying events and ntotal the number of eligible events. Then an availability-style SLI is:
SLI = ngood / ntotal
An SLO is meaningful only when the event definition, measurement window, exclusions, and ownership are explicit. If the target is 99.5%, the corresponding error budget is 0.5%. For 8,640 eligible hourly events in a 30-day period, the nominal budget is:
8,640 × 0.005 = 43.2 events
Because events are discrete, operational policy must specify whether at most 43 failures are allowed or whether the organisation measures continuous time instead. The arithmetic does not decide the policy.
SLOs should be consumer-centred. “Job succeeded” is a weak SLI if the output is empty, late, duplicated, or semantically wrong. A stronger product SLO may combine freshness, completeness, and validity, while retaining hard failure conditions for critical fields.
7. Testing Strategy for Data Products
Testing should operate at multiple levels:
Unit tests: verify functions such as currency conversion or date normalisation with controlled inputs.
Component tests: verify a transformation against a small fixture or local execution environment.
Contract tests: verify that producers and consumers agree on schema and semantics.
Integration tests: verify joins, storage, orchestration, permissions, and external dependencies.
Reconciliation tests: compare totals or controlled aggregates with an authoritative source.
Regression tests: preserve known behaviour for representative historical cases.
Property-based tests: verify general properties, such as non-negative quantities or idempotent reruns, across generated inputs.
Production monitoring: detect drift and failures not represented in test data.
A test suite should include positive, negative, boundary, null, duplicate, late-arriving, and schema-evolution cases. Tests must avoid brittle assumptions about unordered data or incidental physical layout. Golden datasets are valuable, but they should be versioned and protected from accidental changes.
A retailer publishes an hourly revenue data product used by finance, store operations, and a demand-forecasting model. The product combines point-of-sale transactions, product master data, tax tables, and store metadata.
Problem
Finance reports that revenue rose 18% in one region, while transaction counts rose only 2%. The pipeline is marked successful, and the dashboard is fresh. Consumers therefore initially suspect a genuine commercial event.
Analysis
Profiling shows that the product dimension contains duplicate rows for several products after a supplier feed change. The revenue transformation performs a many-to-one join but does not validate dimension-key uniqueness. Affected transaction lines are multiplied. The pipeline’s row-count check passes because it has no expected relationship between input and output grain. Completeness and freshness remain high, but uniqueness, referential modelling, and reconciliation fail.
Lineage identifies the affected dashboard, forecast feature, and regional report. The data contract states that product_id must be unique in the current product dimension, but the producer’s deployment process does not execute contract tests before publication.
Approach and solution
The team takes four actions:
Quarantines the affected hourly partitions and records the incident, rule version, and impacted consumers.
Corrects the dimension feed and rebuilds affected partitions using an idempotent replacement strategy.
Adds a pre-join uniqueness assertion and a post-join reconciliation test against transaction-line totals.
Establishes an SLO requiring hourly availability within 15 minutes, with a separate hard rule that published revenue must reconcile within an agreed tolerance.
A schema registry and catalogue are updated with ownership, grain, sensitivity classification, and lineage. The team also adds a canary comparison: a sample of transformed transactions is compared with an independent calculation before full publication.
Outcome
The corrected product restores financial totals and prevents the forecast model from training on duplicated revenue. The incident also reveals that pipeline success is not equivalent to data-product success. The new controls detect the same class of error before publication in later supplier changes.
Learning points
Validate relationship cardinality, not only field types.
Monitor semantic reconciliations as well as operational completion.
Treat dimensions and reference data as versioned dependencies.
Make ownership and impact visible through metadata and lineage.
Use incidents to improve contracts and tests rather than merely rerunning jobs.
9. Governance, Ethics and Professional Practice
Quality controls can expose personally identifiable information (PII) through profiling outputs, samples, logs, or quarantined records. Access should follow least privilege, and sensitive values should be masked, tokenised, or summarised. Retention and deletion requirements must apply to raw, intermediate, quarantine, and observability stores.
Data contracts should record lawful purpose, stewardship, permitted consumers, and escalation routes. A technically accurate dataset can still be inappropriate if it is used beyond its authorised purpose. Anomaly detection may unfairly flag small groups when historical data reflects unequal measurement or access. Teams should assess representativeness, document limitations, and avoid treating statistical unusualness as misconduct.
Governance also requires change management. A breaking semantic change should have a deprecation period, migration guidance, and consumer notification. Automated quality gates should be proportionate: an exploratory sandbox may tolerate warnings, while a safety, credit, payroll, or regulatory product may require fail-closed publication and human review.
10. Contemporary Developments and Limitations
Data mesh approaches emphasise domain ownership and data products, but decentralised ownership does not remove the need for shared standards, interoperability, and central governance. Data contracts and catalogues are increasingly integrated into CI/CD pipelines. Open table formats and event-driven architectures improve reproducibility and incremental processing, but they do not guarantee semantic correctness.
Artificial intelligence can assist with schema matching, documentation, anomaly triage, and lineage discovery. However, AI-generated rules can encode incorrect assumptions, and opaque anomaly models can increase operational risk. Human review, versioned prompts or models, reproducible evidence, and deterministic controls remain necessary for high-impact products.
No quality system detects every defect. Accuracy often requires comparison with external reality, not merely internal consistency. Metrics may be gamed if teams optimise the score rather than the purpose. Observability costs storage, computation, and engineering time. The appropriate design balances risk, criticality, privacy, and operational cost.
Best-Practice Checklist
Define row grain, keys, units, and time semantics before coding.
Make transformations deterministic, idempotent, versioned, and parameterised.
Profile before defining thresholds; validate explicit business assumptions.
Combine hard constraints, statistical monitoring, and consumer feedback.
Test contracts, cardinality, reconciliation, and late-data behaviour.
Capture metadata, ownership, lineage, sensitivity, and change history.
Separate invalid records safely; never silently discard evidence.
Define consumer-centred SLIs and SLOs with clear denominators and windows.
Review false positives, false negatives, and alert fatigue.
Protect samples, logs, quarantine data, and profiling outputs.
Chapter Summary
Trustworthy data products require more than successful pipeline execution. Transformations should be explicit, modular, deterministic, idempotent, testable, and observable. Data quality is multidimensional: completeness, validity, accuracy, consistency, uniqueness, timeliness, freshness, and integrity measure different properties and must be tied to a defined use.
Profiling discovers data characteristics, whereas validation tests required conditions. Data contracts formalise structural, semantic, operational, and policy expectations between producers and consumers. Metadata and lineage make data interpretable, governable, and diagnosable. Anomaly detection may use rules, historical baselines, quantiles, or machine-learning methods, but thresholds must reflect seasonality, drift, criticality, and the cost of false alerts.
Data observability applies service-management thinking to data products. SLIs quantify consumer-relevant behaviour, and SLOs establish targets and error budgets. Quality gates, reconciliation, contract testing, and incident learning connect engineering controls with organisational accountability. Finally, privacy, fairness, lawful use, retention, and human oversight are essential because reliable data can still be misused.
Key Terms
Data transformation: A defined operation that converts input data into output data.
Data grain: The real-world meaning represented by one row.
Idempotence: The property that repeating an operation produces the same logical result.
Data quality: Fitness of data for a specified purpose.
Completeness: Presence of required records or values.
Validity: Conformance to permitted structural or semantic rules.
Accuracy: Agreement between data and the real-world object or event.
Data profiling: Examination of observed data characteristics.
Validation: Testing data against explicit requirements.
Quarantine: Controlled isolation of records that fail processing or quality rules.
Data contract: An agreement defining a data product’s expectations and responsibilities.
Metadata: Information describing data, its meaning, operation, and governance.
Data lineage: A record of data origins, transformations, and downstream use.
Anomaly: An observation or pattern that materially differs from expected behaviour.
Data observability: Monitoring the health and behaviour of data products and pipelines.
Service-level indicator (SLI): A quantitative measure of a service characteristic.
Service-level objective (SLO): A target value or range for an SLI over a defined period.
Error budget: The permitted amount of SLO non-compliance.
Reconciliation: Comparison of related data products or calculations to detect disagreement.
Schema evolution: Controlled change to a dataset’s structure or semantics.
Review Questions
Short Answer Questions
Why is dataset grain important when designing a join?
Distinguish profiling from validation.
State two properties of a production-ready transformation.
What information does data lineage provide?
Why is “job succeeded” an insufficient data-quality indicator?
Long Answer Questions
Explain the major dimensions of data quality and show why a single aggregate score can be misleading.
Design a data contract for an hourly revenue data product.
Compare rule-based anomaly detection with statistical and machine-learning approaches.
Explain how metadata and lineage support impact analysis and governance.
Discuss how privacy, fairness, and retention requirements influence observability design.
Analytical / Application Questions
A join increases a transaction table from 1,000,000 to 1,080,000 rows, although the intended grain should be preserved. Identify likely causes, propose diagnostic tests, and specify remediation.
A service has 8,640 eligible hourly deliveries in a 30-day window, with an SLO of 99.5%. Calculate the nominal error budget and explain why the operational policy must address discrete events and exclusions.
A daily metric is strongly seasonal by weekday. Design an anomaly-detection baseline, identify two likely false-positive sources, and specify how you would evaluate alert quality.
Multiple Choice Questions with Answers
Question 1
Which property means that rerunning a transformation does not create additional logical records?
A. Idempotence
B. Completeness
C. Freshness
D. Validity
Correct Answer: A. Idempotence
Question 2
A table contains 20,000 rows, of which 19,000 have a required non-null value. What is the completeness rate?
A. 90%
B. 95%
C. 97.5%
D. 99%
Correct Answer: B. 95%
Question 3
What is the primary purpose of a data contract?
A. To compress historical data
B. To define expectations between data producers and consumers
C. To replace all data-quality tests
D. To increase dashboard visualisation options
Correct Answer: B. To define expectations between data producers and consumers
Question 4
Which problem is most directly detected by a uniqueness test on a dimension key?
A. Late-arriving events
B. Duplicate dimension records
C. Incorrect time zones
D. Low network bandwidth
Correct Answer: B. Duplicate dimension records
Question 5
In the formula z = (x − μ) / σ, what does μ represent?
A. The current observation
B. The sample size
C. The historical mean
D. The error budget
Correct Answer: C. The historical mean
Question 6
An SLI measures 9,950 good events out of 10,000 eligible events. What is the SLI?
A. 95.0%
B. 99.0%
C. 99.5%
D. 100.5%
Correct Answer: C. 99.5%
Question 7
Which practice best supports investigation of invalid records without silently losing evidence?
A. Delete them immediately
B. Convert every invalid value to zero
C. Quarantine them with reasons and rule versions
D. Ignore them if the pipeline completes
Correct Answer: C. Quarantine them with reasons and rule versions
Question 8
Why can a schema-compatible change still break consumers?
A. Schemas cannot contain data types
B. The field’s business meaning or unit may change
C. Lineage always prevents changes
D. Freshness automatically decreases
Correct Answer: B. The field’s business meaning or unit may change
Question 9
Which quality dimension concerns agreement with the real-world event?
A. Accuracy
B. Uniqueness
C. Timeliness
D. Completeness
Correct Answer: A. Accuracy
Question 10
For 8,640 eligible events and an SLO of 99.5%, what is the nominal error budget?