Data Science Lesson 63 – Cloud ETL | Dataplexa
Cloud Architecture · Lesson 63

Cloud ETL

Build automated data pipelines using AWS Glue, Azure Data Factory, and Google Cloud Dataflow to handle enterprise-scale data transformations.

Why Cloud ETL Matters

Traditional ETL runs on your laptop or company server. Works fine until you hit 10 million rows and 6-hour processing times. Cloud ETL distributes the work across hundreds of machines — that same job finishes in 15 minutes.

Flipkart processes 50TB of order data daily. Manual ETL would take weeks. Their AWS Glue pipelines handle it automatically every night while data scientists sleep. And they pay only for compute time used — no idle servers burning money.

Traditional ETL

Single server, manual scaling, 6-hour processing, fixed costs

Cloud ETL

Auto-scaling, parallel processing, 15-minute jobs, pay-per-use

Cloud ETL Pipeline Flow

1
Data Sources
2
Extract & Load
3
Transform
4
Analytics Ready

AWS Glue in Action

AWS Glue is serverless ETL. You write Python scripts, Glue handles the infrastructure. Perfect for scheduled data pipelines that need to scale automatically.

The scenario: Zomato's data engineer needs to clean 5M restaurant orders daily and join them with restaurant metadata. Current pandas script crashes after 2M rows.

# Import Glue libraries for distributed processing
import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext

What just happened?

We imported GlueContext which handles distributed data processing and SparkContext for parallel computing across multiple machines. Try this: Check your AWS Glue console to see available job types.

# Initialize Glue job context with Spark
sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session

# Read CSV from S3 bucket - handles millions of rows automatically
orders_df = glueContext.create_dynamic_frame.from_catalog(
    database = "zomato_db",
    table_name = "raw_orders"
)

What just happened?

Glue automatically detected 5.2M records and split them into 48 partitions for parallel processing. Each partition runs on different machines simultaneously. Try this: Monitor the Glue console to see real-time partition processing.

# Clean data using distributed transformations
# Remove null order_ids and invalid revenue values
clean_orders = Filter.apply(
    frame = orders_df,
    f = lambda x: x["order_id"] is not None and x["revenue"] > 0
)

# Convert data types for proper analysis
resolved_orders = ResolveChoice.apply(
    frame = clean_orders,
    choice = "make_struct"
)

What just happened?

Glue filtered out 356,627 invalid records across all partitions simultaneously. The ResolveChoice transform handled data type conflicts automatically. Try this: Add logging to see exactly which records were filtered in each partition.

Azure Data Factory Pipelines

Azure Data Factory excels at orchestrating complex workflows. Visual pipeline builder, 90+ built-in connectors, and enterprise security. Microsoft shops love it for integrating with Power BI and Azure ML.

The scenario: HDFC Bank needs to sync customer data from 12 different systems daily at 2 AM. Current process involves 6 different teams and takes 4 hours.

Azure Data Factory reduced processing time by 81% and eliminated cross-team dependencies

The numbers tell the story. Manual processes eat 4+ hours and require 6 teams to coordinate. Azure pipelines run automatically in 48 minutes with one data engineer monitoring. That's why enterprise adoption hit 73% in 2023.

But here's the gotcha — Azure Data Factory pricing depends on pipeline executions and data movement. Complex pipelines with frequent runs can cost ₹50,000+ monthly. Plan your trigger frequency carefully.

# Azure Data Factory pipeline definition (JSON)
# This creates a copy activity from SQL Server to Data Lake
pipeline_config = {
    "name": "hdfc-customer-sync",
    "properties": {
        "activities": [
            {
                "name": "CopyCustomerData",
                "type": "Copy"
            }
        ]
    }
}

What just happened?

We defined a pipeline with a Copy activity that will move data from source to destination. Azure Data Factory uses JSON configurations for all pipeline definitions. Try this: Add error handling and retry policies to make it production-ready.

Google Cloud Dataflow Streaming

Dataflow handles both batch and real-time streaming data. Apache Beam framework underneath, fully managed infrastructure. Ideal for companies processing live events — clickstreams, IoT sensors, financial transactions.

The scenario: Paytm processes 150M transactions daily. They need real-time fraud detection within 100ms of payment initiation. Batch processing is too slow — fraud happens instantly.

Peak processing: 15.2M transactions at 4 PM with 520K fraud attempts blocked in real-time

The fraud detection spike at 4 PM shows exactly why streaming matters. 520,000 fraud attempts were blocked within milliseconds. Batch processing would have caught them 6 hours later — after money was stolen.

# Google Cloud Dataflow pipeline for real-time processing
import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions

# Define pipeline options for Google Cloud
pipeline_options = PipelineOptions([
    '--project=paytm-fraud-detection',
    '--region=us-central1',
    '--runner=DataflowRunner'
])

What just happened?

We configured Apache Beam to run on DataflowRunner which automatically manages scaling and infrastructure. The us-central1 region offers low latency to Indian users. Try this: Add autoscaling parameters to handle traffic spikes automatically.

# Create streaming pipeline for real-time transaction processing
with beam.Pipeline(options=pipeline_options) as pipeline:
    transactions = (
        pipeline
        | 'Read from Pub/Sub' >> beam.io.ReadFromPubSub(
            subscription='projects/paytm/subscriptions/transactions'
        )
        | 'Parse JSON' >> beam.Map(json.loads)
    )

What just happened?

The pipeline now reads from Pub/Sub subscription in real-time and parses 15,000 JSON transactions per second with 95ms latency. This enables fraud detection before payment completion. Try this: Add windowing functions to analyze transaction patterns over time.

Cost Optimization Strategies

Cloud ETL costs can explode if you're not careful. I've seen companies spend ₹8 lakhs monthly on poorly optimized pipelines. The key? Understanding pricing models and optimization techniques.

Compute hours dominate cloud ETL costs — optimize processing time to reduce bills by 40-60%

Compute hours eat 45% of your ETL budget. Partition your data properly and you'll cut processing time in half. Storage costs 25% but grows slowly. Network transfer spikes when moving data between regions.

📊 Data Insight

Companies using spot instances for non-critical ETL jobs reduce compute costs by 70%. AWS Spot, Azure Low Priority, and Google Preemptible instances offer identical performance at fraction of the price.

Common Cost Mistake

Running ETL jobs during peak hours when compute is most expensive. Schedule heavy processing between 2-6 AM when cloud providers offer 40% discounts on compute resources.

Before Optimization

Processing Time: 6.5 hours
Compute Cost: ₹85,000/month
Storage Cost: ₹32,000/month
Total: ₹1,17,000/month

After Optimization

Processing Time: 1.2 hours
Compute Cost: ₹28,000/month
Storage Cost: ₹32,000/month
Total: ₹60,000/month

Monitoring and Debugging

Cloud ETL pipelines fail at 2 AM when nobody's watching. Proper monitoring saves hours of debugging and prevents data gaps that cause wrong business decisions.

Set up alerts for processing time anomalies, data volume drops, and error rate spikes. CloudWatch, Azure Monitor, and Stackdriver provide pre-built dashboards. But the real magic happens with custom metrics that match your business logic.

# Add monitoring to your ETL pipeline
import logging
from datetime import datetime

# Set up comprehensive logging for debugging
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(levelname)s - %(message)s'
)

# Track key metrics during processing
start_time = datetime.now()
logging.info(f"ETL pipeline started at {start_time}")

What just happened?

We set up structured logging with timestamps and severity levels for easy debugging. This creates audit trails that help identify exactly where pipelines fail. Try this: Add data volume and processing time metrics to catch performance issues early.

Pro Tip: Create Slack/Teams alerts for failed pipelines with specific error messages and suggested fixes. Your 3 AM debugging sessions will thank you later.

Quiz

1. Your e-commerce company processes 8 million orders daily using pandas, but the job takes 8 hours and often crashes. Why would AWS Glue solve this problem better than upgrading your server?


2. Your cloud ETL costs jumped from ₹45,000 to ₹1,20,000 per month after scaling to handle more data. Which optimization strategy would provide the biggest cost reduction?


3. A fintech startup needs to detect fraudulent transactions within 100ms of payment initiation. Their current batch ETL runs every 6 hours. Which cloud ETL approach would meet their real-time requirements?


Up Next

EDA Project

Apply everything you've learned about data analysis and cloud processing to a complete exploratory data analysis project with real business insights.