AWS Glue Overview
What is AWS Glue?

AWS Glue is a fully managed serverless ETL (Extract, Transform, Load) service provided by Amazon Web Services. It is mainly used by data engineers to prepare, transform, and move large datasets between different data stores. Glue automatically provisions Spark clusters, runs ETL jobs, and integrates with many AWS services such as S3, Redshift, Athena, and RDS.

AWS Glue is commonly used in data lake architectures where raw data is stored in Amazon S3 and then transformed into analytics-ready datasets.

Typical AWS Glue ETL Flow
S3 Raw Data
     ↓
Glue Crawler (Create Table Metadata)
     ↓
Glue ETL Job (PySpark)
     ↓
Transformed Data
     ↓
Athena / Redshift / BI Tools
Simple Glue PySpark Example
from pyspark.sql import SparkSession

spark = SparkSession.builder
    .appName("Glue ETL Job")
    .getOrCreate()

df = spark.read.csv("s3://my-bucket/input-data", header=True)

result_df = df.groupBy("city").count()

result_df.write.mode("overwrite").parquet("s3://my-bucket/output-data")
AWS Lambda vs AWS Glue
Feature AWS Lambda AWS Glue
Service Type Serverless compute service Serverless data integration (ETL) service
Main Purpose Run backend code and microservices Process and transform large datasets
Best Use Case APIs, automation, event processing Data engineering pipelines
Processing Engine Single function execution Apache Spark distributed processing
Data Size Handling Small to medium workloads Large scale big data workloads
Execution Time Maximum 15 minutes Can run for hours
Languages Python, Node.js, Java, Go PySpark, Scala Spark
Scaling Automatic function scaling Distributed Spark cluster scaling
Typical Data Size MB to few GB GB to TB or PB
Common Integrations API Gateway, SQS, SNS, DynamoDB S3, Athena, Redshift, Glue Data Catalog
Pricing Model Pay per request and execution time Pay per DPU hour
When to Use Lambda vs Glue
Use AWS Lambda when:
- Building APIs
- Processing small files
- Trigger-based automation

Use AWS Glue when:
- Processing large datasets
- Running ETL pipelines
- Transforming data lakes
AWS Glue Job Overview

AWS Glue Job is a serverless ETL component that reads data from a source, transforms it using Apache Spark and loads it into a destination such as Amazon S3, Redshift or a data warehouse. Companies use Glue jobs to automate large scale data pipelines.

Real‑Time Scenario

An e‑commerce company stores raw order files in Amazon S3 every hour. A Glue job runs nightly to read all order files, remove invalid records, aggregate revenue by city and store the processed data in Parquet format. Analysts then query the processed dataset using Amazon Athena to build dashboards.

Name

The name uniquely identifies the Glue job. Engineers usually follow naming conventions such as project_environment_pipeline.

Example

retail_prod_sales_aggregation_job

Real‑Time Scenario

In large organizations hundreds of pipelines run daily. Proper naming helps DevOps teams quickly identify jobs when monitoring failures or performance issues.

IAM Role

IAM role provides the Glue job permission to access AWS resources such as S3 buckets, CloudWatch logs, Redshift or DynamoDB.

Real‑Time Scenario

Suppose a Glue job reads raw data from s3://sales-raw-data and writes processed data to s3://sales-analytics-data. The IAM role must include permissions like s3:GetObject and s3:PutObject. Without these permissions the job fails with an access denied error.

Worker Type

Worker type determines CPU and memory resources allocated for the Spark job.

Example

G.1X → 4 vCPU and 16GB RAM

Real‑Time Scenario

If a company processes 100GB of sales data daily, engineers may configure 4 G.1X workers. For large datasets such as 1TB clickstream data they might use 20 workers or memory optimized R workers.

Auto Scaling Workers

Auto scaling automatically increases or decreases the number of workers during job execution.

Real‑Time Scenario

During a heavy join operation Spark may require additional executors. Glue automatically scales up workers to process the join faster and later scales down to reduce cost.

Job Bookmark

Job bookmarks track previously processed data so that the job only processes new files.

Real‑Time Scenario

An S3 folder receives hourly log files. Without bookmarks the Glue job would reprocess all files each run. With bookmarks enabled the job processes only the newly arrived files, saving time and cost.

Flex Execution

Flex execution runs jobs on spare AWS capacity to reduce cost.

Real‑Time Scenario

A company generates weekly business reports. Since these reports are not urgent the team uses Flex execution to reduce processing cost by running jobs when spare capacity is available.

Retries

Retries allow Glue to automatically rerun the job if temporary failures occur.

Real‑Time Scenario

Sometimes network interruptions or temporary AWS service issues cause job failures. Setting retries to 2 ensures the job automatically restarts instead of failing the entire pipeline.

Job Timeout

Timeout defines the maximum runtime allowed for the job.

Real‑Time Scenario

If a poorly optimized join query causes the job to run indefinitely the timeout setting automatically stops the job after the configured limit to prevent excessive AWS charges.

Continuous Logging

Continuous logging sends job logs to Amazon CloudWatch.

Real‑Time Scenario

If a transformation fails because of a schema mismatch engineers inspect CloudWatch logs to quickly identify the failing stage and fix the issue.

Spark UI

Spark UI provides execution details such as stages, tasks and shuffle metrics.

Real‑Time Scenario

If a job takes longer than expected engineers open the Spark UI to identify which stage is slow. For example a skewed join might cause one executor to process significantly more data.

Temporary Path

Temporary path is an S3 location used by Spark for intermediate files.

Real‑Time Scenario

During operations like groupBy or join, Spark performs shuffle operations and writes intermediate files to this temporary path.

Job Parameters

Job parameters allow passing dynamic values to the Glue script such as input path or processing date.

Example Parameters
--input_path s3://sales-data/raw/
--output_path s3://sales-data/processed/
--process_date 2026-03-04
Real‑Time Scenario

Instead of creating multiple Glue jobs for different datasets engineers create one reusable job and pass different S3 paths through job parameters.

Example PySpark ETL Code
from pyspark.sql import SparkSession

spark = SparkSession.builder.appName("Sales ETL").getOrCreate()

df = spark.read.csv("s3://company-sales/input/", header=True)

result = df.groupBy("city").sum("amount")

result.write.mode("overwrite").parquet("s3://company-sales/output/")
Complete Real‑Time Data Engineering Pipeline

1. Application servers generate logs and upload them to Amazon S3 every hour.

2. AWS Glue crawler scans the raw files and updates the Glue Data Catalog.

3. A scheduled Glue job reads the raw data and performs transformations.

4. The processed data is written to an optimized Parquet dataset in S3.

5. Amazon Athena queries the processed dataset.

6. Amazon QuickSight builds dashboards for business analytics.

AWS Glue Architecture (Typical Production Setup)

In most real production systems AWS Glue is used as the ETL processing engine inside a modern data lake architecture.

Application Systems
        |
        v
Amazon S3 (Raw Layer)
        |
        v
AWS Glue Crawler
        |
        v
Glue Data Catalog
        |
        v
AWS Glue ETL Job (Spark)
        |
        v
Amazon S3 (Processed / Curated Layer)
        |
        v
Amazon Athena
        |
        v
Amazon QuickSight Dashboards

This architecture is commonly used in retail, fintech and SaaS companies to process data lakes.

Glue Job Execution Flow (Step by Step)

The following steps explain how a Glue job runs internally when triggered.

1. A trigger (schedule, workflow, API or event) starts the Glue job.

2. AWS Glue allocates the required workers and creates the Spark cluster.

3. The ETL script is downloaded from the S3 script location.

4. Spark executors read source data from S3 or other data sources.

5. Transformations such as filtering, joins, and aggregations are executed.

6. Intermediate shuffle data is written to the temporary S3 path.

7. The final dataset is written to the output destination (S3, Redshift etc).

8. Logs and metrics are sent to CloudWatch.

9. Spark UI information is stored for debugging.

10. The cluster shuts down automatically after job completion.

Example Cost Calculation

AWS Glue charges based on DPU usage. One G.1X worker equals 1 DPU.

Example Scenario

Workers : 5
Worker Type : G.1X
Execution Time : 10 minutes

1 DPU cost ≈ $0.44 per hour

Cost Calculation

5 workers × 10 minutes
= 5 × (10/60) × 0.44
≈ $0.36 per job

In large organizations running hundreds of ETL jobs daily cost optimization using partitioning, auto scaling and flex execution becomes very important.

Spark UI Stage Explanation

Spark UI helps engineers debug performance issues. It shows stages, tasks and shuffle operations.

Stage 1 – Reading data from S3

Stage 2 – Filtering invalid records

Stage 3 – Join or aggregation operations

Stage 4 – Writing processed dataset to S3

If a stage runs much slower than others engineers inspect partition sizes or skewed keys.

Common AWS Glue Interview Questions

1. What is AWS Glue?
A serverless ETL service used to prepare and transform data for analytics.

2. What is a Glue Crawler?
A service that scans data sources and automatically creates metadata tables in the Glue Data Catalog.

3. What is Job Bookmark?
A feature that tracks processed files so incremental jobs process only new data.

4. What is the difference between G workers and R workers?
G workers are general purpose while R workers are memory optimized for heavy joins.

5. How does Glue reduce ETL infrastructure management?
Glue automatically provisions and manages Spark clusters so engineers only focus on writing ETL logic.