AWS Glue
Apache Avro
schema evolution
data transformation
cloud ETL

using AWS Glue with Apache Avro on schema changes

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Glue can read Avro data across schema versions, but only when the schema changes are compatible with Avro's evolution rules. Glue helps with discovery and ETL, yet it does not automatically make incompatible producer changes safe for your jobs, crawlers, or downstream analytics.

What Avro Schema Evolution Actually Promises

Avro data is written with one schema and read with another. That works well for certain changes, especially:

  • adding a field with a default value
  • removing a field that readers no longer need
  • widening some compatible types carefully

It works badly for changes such as:

  • renaming a field without aliases or migration planning
  • changing field meaning while keeping the same name
  • removing fields consumers still require
  • introducing non-nullable fields with no default for old data

So the first rule is simple: Glue is not a substitute for schema-governance discipline.

A Safe Example: Add a Field With a Default

Old schema:

json
1{
2  "type": "record",
3  "name": "UserEvent",
4  "fields": [
5    { "name": "user_id", "type": "string" },
6    { "name": "event_type", "type": "string" }
7  ]
8}

New schema:

json
1{
2  "type": "record",
3  "name": "UserEvent",
4  "fields": [
5    { "name": "user_id", "type": "string" },
6    { "name": "event_type", "type": "string" },
7    { "name": "source", "type": "string", "default": "unknown" }
8  ]
9}

That is the kind of change Avro handles well. Old files do not contain source, but readers using the new schema can still work because the field has a default.

Where Glue Fits

Glue contributes at three layers:

  • crawlers can discover Avro files and update catalog metadata
  • Glue jobs can read Avro from S3 into Spark DataFrames
  • catalog tables give a shared schema surface for ETL and query tools

Those are useful capabilities, but they do not validate your business compatibility rules. If two producers change the same field differently, the Glue Data Catalog will not understand the semantic mistake for you.

Write Glue Jobs Defensively

A Glue job should tolerate missing columns while the lake is in transition between schema versions.

python
1from awsglue.context import GlueContext
2from pyspark.context import SparkContext
3from pyspark.sql.functions import col, coalesce, lit
4
5sc = SparkContext()
6glue_context = GlueContext(sc)
7spark = glue_context.spark_session
8
9df = spark.read.format("avro").load("s3://my-bucket/events/")
10
11if "source" not in df.columns:
12    df = df.withColumn("source", lit("unknown"))
13
14normalized = df.select(
15    col("user_id"),
16    col("event_type"),
17    coalesce(col("source"), lit("unknown")).alias("source")
18)
19
20normalized.show()

This kind of normalization keeps ETL jobs working while producers roll forward gradually.

Why Crawlers Alone Are Not Enough

Many teams let Glue Crawlers auto-update schema metadata and assume that means evolution is handled. That is risky.

A crawler can detect that files now contain a new column. It cannot decide whether that new column is compatible with old readers, whether an old field name was semantically renamed, or whether downstream Athena queries will still behave correctly.

For critical datasets, explicit schema rollout is safer than uncontrolled metadata drift.

A Better Operational Pattern

A robust rollout usually looks like this:

  • update readers so they tolerate old and new fields
  • deploy the new producer schema
  • backfill or normalize raw data if needed
  • only then remove old-field assumptions from the pipeline

That pattern is slower than "let the crawler discover it," but it prevents analytics and ETL breakage when several consumers depend on the same data lake zone.

Common Pitfalls

The biggest mistake is treating the Glue Data Catalog as a full schema-compatibility system. It is metadata, not policy.

Another mistake is renaming Avro fields and assuming Glue will preserve intent automatically.

A third issue is adding fields without defaults and expecting old Avro data to read cleanly under the new schema.

Finally, jobs that assume every partition has the latest schema tend to fail or silently produce wrong null-heavy outputs during transitions.

Summary

  • Avro schema changes are safe only when they follow Avro compatibility rules.
  • Glue helps discover and process evolving Avro, but it does not guarantee semantic safety.
  • Adding fields with defaults is usually much safer than renaming or narrowing fields.
  • Write Glue jobs defensively so they can normalize old and new versions together.
  • Use crawlers for discovery, not as your only schema-evolution strategy.
  • Treat schema rollout as an application change, not just a storage-format tweak.

Course illustration
Course illustration

All Rights Reserved.