How to prevent bad data from reaching analytics, machine learning, and business decisions using AWS services.
Imagine your company's sales dashboard reports a 35% increase in revenue overnight.
The leadership team is excited. The marketing department is celebrating. Business analysts are preparing reports.
But after investigating the numbers, the data engineering team discovers thousands of duplicate transactions and missing customer records.
The pipeline completed successfully.
AWS Glue jobs ran without errors. Amazon S3 stored the files. Amazon Athena executed the queries.
Everything worked technically.
But the results were wrong.
This is a classic example of a fundamental computing principle:
Garbage In, Garbage Out (GIGO).
A modern data platform can process terabytes of information, scale automatically, and deliver results in seconds. But if the input data is incorrect, the output will still be incorrect.
The real challenge is not simply building a pipeline that moves data quickly. It is building a pipeline that moves trustworthy data.
Let's explore how to solve this problem using AWS services.
1. Understanding the Garbage In, Garbage Out Principle
Garbage In, Garbage Out means that the quality of the output depends heavily on the quality of the input.
Consider an e-commerce company processing millions of orders.
Its dataset contains order IDs, customer IDs, order amounts, order statuses, and transaction timestamps.
However, the incoming data may contain:
| Problem | Example | Business Impact |
|---|---|---|
| Missing values | Customer ID is NULL | Incomplete customer analytics |
| Duplicate records | Same order ID appears twice | Inflated revenue |
| Invalid values | Negative order amount | Incorrect financial reporting |
| Schema drift | Column data type changes | ETL failures |
| Inconsistent formats | Different timestamp formats | Incorrect time-based analysis |
| Late-arriving data | Missing daily transactions | Incomplete dashboards |
If these problems are not detected, they can spread through the data platform and affect analytics, reporting, and machine learning.
A successful ETL execution does not necessarily mean the resulting data is correct.
2. Designing a Data Quality-Driven AWS Architecture
A production-grade data pipeline should validate data at multiple stages.
Here is a reference architecture:
DATA SOURCES
Applications | APIs | Databases
Streaming | Batch Files
|
v
Amazon Kinesis Data Streams
(Streaming Ingestion)
|
v
Amazon S3 - RAW
Original Source Data
|
v
Amazon EventBridge
Pipeline Events
|
v
AWS Step Functions
Workflow Orchestration
|
v
AWS Glue
Data Processing and ETL
|
v
AWS Glue Data Quality
Validation and Detection
|
+-----+-----+
| |
v v
Valid Data Invalid Data
| |
v v
S3 Clean S3 Quarantine
|
v
S3 Curated Zone
|
+---+----------+
| |
v v
Amazon Athena Amazon Redshift
| |
+-------+------+
|
v
Amazon QuickSight
Monitoring: Amazon CloudWatch
Notifications: Amazon SNS
Each AWS service has a specific responsibility.
| AWS Service | Responsibility |
|---|---|
| Amazon S3 | Raw, clean, quarantine, and curated storage |
| Amazon Kinesis Data Streams | Streaming data ingestion |
| AWS Glue | Serverless ETL processing |
| AWS Glue Data Quality | Data validation and anomaly detection |
| AWS Step Functions | Workflow orchestration |
| Amazon EventBridge | Event-driven automation |
| Amazon CloudWatch | Monitoring and logging |
| Amazon SNS | Operational notifications |
| Amazon Athena | SQL analytics on S3 |
| Amazon Redshift | Data warehousing and analytics |
The key design principle is simple:
Invalid data should never silently become trusted business data.
3. Organizing the Data Lake into Quality Zones
One effective way to prevent GIGO problems is to organize the data lake into separate processing zones.
Amazon S3 provides the storage foundation.
Raw Zone
The raw zone stores the original data exactly as received from the source.
s3://company-data-lake/raw/orders/
s3://company-data-lake/raw/customers/
s3://company-data-lake/raw/products/
Preserving original data makes auditing, troubleshooting, and reprocessing easier.
Clean Zone
The clean zone contains records that have passed validation and standardization.
s3://company-data-lake/clean/orders/
Typical operations include type conversion, timestamp normalization, duplicate handling, and required-field validation.
Quarantine Zone
Invalid or suspicious records are stored separately.
s3://company-data-lake/quarantine/orders/
This prevents bad records from contaminating trusted datasets while allowing engineers to investigate and recover valid information when appropriate.
Curated Zone
The curated zone contains business-ready datasets.
s3://company-data-lake/curated/sales/
s3://company-data-lake/curated/customer_360/
These datasets can be consumed by Amazon Athena, Amazon Redshift, dashboards, and machine learning applications.
4. Validating Data with AWS Glue Data Quality
AWS Glue Data Quality helps data engineers define expectations about datasets and evaluate whether incoming data meets those expectations.
It uses Data Quality Definition Language (DQDL) to define validation rules.
For example, consider an order dataset where every order should have a unique ID, a valid customer ID, a positive order amount, and an accepted order status.
A DQDL ruleset could look like this:
Rules = [
IsComplete "order_id",
IsUnique "order_id",
IsComplete "customer_id",
ColumnValues "order_amount" > 0,
ColumnValues "order_status"
in ["PENDING", "PAID", "SHIPPED", "CANCELLED"],
IsComplete "order_timestamp",
RowCount > 0
]
These rules help identify missing values, duplicate identifiers, invalid amounts, unexpected statuses, and empty datasets.
The important thing is to define rules based on actual business requirements.
For example, negative amounts may be valid in a refund dataset. Applying a positive-only rule to every financial dataset would incorrectly reject legitimate transactions.
Data quality rules should reflect business meaning, not just technical assumptions.
Documentation: AWS Glue Data Quality
5. Detecting Anomalies with Historical Data
Fixed validation rules cannot identify every unexpected problem.
Imagine an e-commerce platform that normally processes one million orders daily.
One day, only 50,000 records arrive.
A basic rule checking whether the dataset contains at least one record will pass.
But the business may have lost 95% of its transactions.
AWS Glue Data Quality supports anomaly detection using historical data statistics.
Engineers can monitor metrics such as record counts, completeness, uniqueness, and data distributions.
Consider this example:
| Day | Expected Orders | Actual Orders |
|---|---|---|
| Monday | 950,000 | 948,000 |
| Tuesday | 980,000 | 975,000 |
| Wednesday | 1,020,000 | 1,018,000 |
| Thursday | 1,000,000 | 420,000 |
The Thursday result should trigger an investigation.
Possible causes include an upstream API failure, missing source partitions, incomplete file transfers, or unexpected application behavior.
Anomaly detection provides an early warning, but an anomaly does not automatically mean the data is incorrect. Business events can also create legitimate changes in data volume.
Documentation: AWS Glue Anomaly Detection
6. Building an Optimized AWS Glue ETL Pipeline
Data quality is only one part of the solution. A production pipeline must also process data efficiently as volumes grow.
AWS Glue provides serverless ETL capabilities using Apache Spark.
Here is a simplified PySpark example that reads raw order data, standardizes data types, and separates valid and invalid records.
from pyspark.sql import functions as F
# Read raw order data
orders_df = (
spark.read
.option("header", "true")
.csv("s3://company-data-lake/raw/orders/")
)
# Standardize data types
orders_df = (
orders_df
.withColumn(
"order_amount",
F.col("order_amount").cast("decimal(12,2)")
)
.withColumn(
"order_timestamp",
F.to_timestamp("order_timestamp")
)
)
# Define validation conditions
valid_condition = (
F.col("order_id").isNotNull()
& F.col("customer_id").isNotNull()
& F.col("order_amount").isNotNull()
& (F.col("order_amount") > 0)
& F.col("order_timestamp").isNotNull()
)
# Separate valid and invalid records
valid_orders = orders_df.filter(valid_condition)
invalid_orders = orders_df.filter(~valid_condition)
# Store invalid records
(
invalid_orders.write
.mode("append")
.parquet("s3://company-data-lake/quarantine/orders/")
)
# Store valid records
(
valid_orders.write
.mode("append")
.parquet("s3://company-data-lake/clean/orders/")
)
This is an illustrative transformation, not a complete production ETL job. Production implementations should also handle malformed input, duplicate business keys, schema changes, source batch identification, and reliable retries.
For scalable processing, consider the following practices.
Use columnar formats.
Apache Parquet can reduce the amount of data read by analytical workloads.
Apply partitioning carefully.
Partition large datasets using attributes commonly used in filters, such as transaction date or region.
Process incrementally.
Avoid repeatedly scanning historical data. AWS Glue job bookmarks can help track previously processed data for supported sources and workloads.
Avoid small files.
Excessive small files increase metadata overhead and can reduce query performance.
Optimize compute resources.
Choose suitable AWS Glue worker types and job configurations based on workload size and performance requirements.
7. Orchestrating Data Quality with AWS Step Functions
A pipeline should not publish data simply because an ETL job completed.
It should publish data only after the required quality checks pass.
AWS Step Functions can coordinate ingestion, transformation, validation, and publishing.
Start Pipeline
|
v
Ingest Data
|
v
Run AWS Glue ETL
|
v
Evaluate Data Quality
|
v
Quality Passed?
/ \
Yes No
| |
v v
Publish Quarantine
Curated Invalid Data
Data |
| v
| Send Alert
| |
v v
Update Investigate
Catalog
|
v
Notify Success
|
v
End
When validation passes, the workflow can publish the curated dataset.
When validation fails, it can stop downstream publication, quarantine invalid records, and notify the engineering team.
Step Functions also supports retry and error-handling patterns for transient infrastructure failures.
However, retrying the same invalid data without correcting the underlying problem will not solve a data quality failure.
Documentation: AWS Step Functions
8. Monitoring with EventBridge and CloudWatch
A production data platform needs visibility into both infrastructure health and data quality.
Amazon EventBridge can respond to AWS Glue job state change events.
For example, this event pattern identifies failed or timed-out Glue jobs:
{
"source": ["aws.glue"],
"detail-type": ["Glue Job State Change"],
"detail": {
"state": ["FAILED", "TIMEOUT"]
}
}
A matching event can trigger AWS Lambda, start a Step Functions workflow, or publish an Amazon SNS notification.
Amazon CloudWatch can monitor:
- Glue job execution duration.
- Job failures and timeouts.
- Processed and rejected record counts.
- Data quality evaluation results.
- Pipeline execution frequency.
- Data freshness.
- Resource utilization.
Monitoring only job status is not enough.
A pipeline can complete successfully and still produce incorrect data.
The monitoring strategy should answer three questions:
Is the pipeline running?
Is the data trustworthy?
Is the pipeline efficient?
Documentation: Amazon CloudWatch
9. Scaling and Cost Optimization
A pipeline that processes one million records today may need to process one billion records tomorrow.
Scalability should be part of the original design.
Amazon S3 provides scalable storage. AWS Glue supports serverless ETL. Amazon Kinesis Data Streams supports continuous event ingestion. Amazon Managed Service for Apache Flink can handle advanced stateful stream processing.
For analytics, Parquet, partition pruning, and appropriate file sizing can reduce the amount of data scanned by Amazon Athena.
Incremental processing reduces unnecessary computation.
S3 lifecycle policies can help manage long-term storage costs.
CloudWatch metrics and AWS cost monitoring can help identify expensive jobs and inefficient processing patterns.
The goal is to balance performance, reliability, and cost rather than simply choosing the largest available compute resources.
10. Data Governance and Security
Data quality and data governance should work together.
A record may be technically valid but contain sensitive information that should not be accessible to every analytics user.
AWS IAM provides permissions for users and services.
AWS Lake Formation helps manage access to data lakes.
AWS Key Management Service supports encryption key management.
Amazon S3 provides encryption and access-control capabilities.
Amazon CloudTrail can provide an audit history of supported AWS API activity.
For production environments, use least-privilege permissions and separate access policies for raw, clean, quarantine, and curated datasets.
11. Measuring Data Quality
A data quality framework needs measurable outcomes.
Consider these important metrics:
| Metric | Purpose |
|---|---|
| Completeness | Measures missing required values |
| Uniqueness | Identifies duplicate business keys |
| Validity | Measures compliance with defined rules |
| Accuracy | Measures agreement with trusted source information |
| Freshness | Measures data availability delay |
| Consistency | Checks agreement across related datasets |
| Rejection Rate | Measures records sent to quarantine |
| Pipeline Success Rate | Measures successful pipeline executions |
For example, if a pipeline receives one million records and quarantines 20,000, the rejection rate is:
Rejection Rate =
(Rejected Records / Total Records) * 100
= (20,000 / 1,000,000) * 100
= 2%
A 2% rejection rate may be acceptable for one workload and unacceptable for another.
Set quality thresholds according to business requirements and the impact of incorrect data.
12. A Practical Implementation Roadmap
Start with an Amazon S3 data lake containing raw, clean, quarantine, and curated zones.
Use AWS Glue Data Catalog to organize datasets and schemas.
Implement ingestion using AWS Glue, Amazon Kinesis Data Streams, or suitable source connectors.
Create DQDL rules for required fields, uniqueness, valid values, and business constraints.
Build AWS Glue ETL transformations to standardize records and separate valid and invalid data.
Use AWS Step Functions to orchestrate the workflow and control downstream publishing.
Integrate EventBridge, CloudWatch, and SNS for operational monitoring and alerts.
Finally, optimize processing through incremental workloads, Parquet, partitioning, file compaction, and compute tuning.
This incremental approach allows teams to improve data reliability without redesigning the entire platform at once.
Conclusion: Build Trust Into Every Data Pipeline
The Garbage In, Garbage Out principle is simple, but its impact on modern organizations is enormous.
A poorly designed pipeline can distribute incorrect information across data warehouses, dashboards, machine learning systems, and business applications.
AWS provides the building blocks to prevent this.
Amazon S3 provides the storage foundation. AWS Glue processes and validates data. AWS Glue Data Quality evaluates business rules and detects anomalies. AWS Step Functions orchestrates the workflow. EventBridge and CloudWatch provide monitoring. Amazon Athena and Amazon Redshift make trusted data available for analytics.
Together, these services help build data platforms that are scalable, optimized, and reliable.
The next time you design a data pipeline, ask yourself:
Are we simply moving data, or are we ensuring that the data is trustworthy?
Because processing bad data faster does not create better analytics.
It only produces incorrect results more quickly.
Garbage In, Garbage Out. Build quality into the pipeline, not as an afterthought, but as a fundamental part of the architecture.
AWS Documentation
- Amazon S3
- AWS Glue
- AWS Glue Data Quality
- AWS Glue DQDL
- AWS Glue Anomaly Detection
- AWS Step Functions
- Amazon EventBridge
- Amazon CloudWatch

Top comments (0)