Kafka Schema Evolution Demo (Avro)

This demo mirrors the schemas used by the runnable spring-kafka-contract-demo and shows what the starter validates before the application is allowed to start.

Compatibility modes

The 0.2.0 starter supports Confluent modes NONE, BACKWARD, BACKWARD_TRANSITIVE, FORWARD, FORWARD_TRANSITIVE, FULL, and FULL_TRANSITIVE.

Schema v1 – Baseline
{
  "type": "record",
  "name": "OrderEvent",
  "namespace": "io.github.mathias82.avro",
  "fields": [
    { "name": "orderId", "type": "string" },
    { "name": "amount", "type": "double" },
    { "name": "createdAt", "type": "string", "default": "" }
  ]
}
Schema v2 – Compatible
{
  "type": "record",
  "name": "OrderEvent",
  "namespace": "io.github.mathias82.avro",
  "fields": [
    { "name": "orderId", "type": "string" },
    { "name": "amount", "type": "double" },
    { "name": "createdAt", "type": "string", "default": "" },
    { "name": "customerNote", "type": ["null", "string"], "default": null }
  ]
}

Adds an optional field with a default, so old data can still be read and old readers can ignore the new field.

Schema v3 – Breaking
{
  "type": "record",
  "name": "OrderEvent",
  "namespace": "io.github.mathias82.avro",
  "fields": [
    { "name": "orderId", "type": "string" },
    { "name": "status", "type": "string" }
  ]
}

Removes required fields and adds a required field without a default, so it breaks the contract.

Select schemas and run the compatibility check.

What CI now proves

The repository CI starts Kafka and Schema Registry, builds the starter under test, starts the Spring Boot demo, POSTs a unique order, and waits until the consumer exposes that exact event. This validates the full producer → Kafka → consumer path.

spring-kafka-contract-starter · demo source