Monedula

Scenario 25.1.11 · Backward mode accepts it, an old consumer cannot read it

Kafka consumer cannot read a new schema under BACKWARD

Schema registry · Intermediate · about 3 min · Apache Kafka 4.4 · Confluent Platform feature

Under backward mode a producer removes a field without a default: the registry accepts v2, and a consumer still on v1 stops on a RecordDeserializationException. Upgrading the consumer fixes it.

Run this scenario in the playground

O3 waits behind O2. t+2.000s

O3 is written too, and waits behind O2: the consumer keeps failing at offset 1, so its position and committed offset stay at 1 while the lag grows. Skipping the record would lose it; the reader has to change.

Open at this step: step 5, O3 waits behind O2

What you start with

BACKWARD, the default compatibility mode, promises that a consumer on the new schema can read data written with the old one. It promises nothing about the other direction. Here the consumer reads with a specific reader generated from v1, and the producer's new version removes a field that has no default.

Step by step

  1. v1 · backward mode t+0.000s orders-value holds v1 (schema id 1) under BACKWARD, the default. The consumer reads with a specific reader, a class generated from v1 (specific.avro.reader=true); three Schema Registry instances, sr-1 leads. Open at this step: step 1, v1 · backward mode
  2. O1 read with the v1 reader t+0.900s O1 goes out with schema id 1. The consumer looks id 1 up, resolves the writer schema against its v1 reader and reads O1. Nothing has changed yet. Open at this step: step 2, O1 read with the v1 reader
  3. v2 deployed: a field removed t+1.100s The team deploys the producer with v2, which removes a field that has no default. A reader on v2 can read v1 records, it just ignores the extra field (backward), but a reader on v1 finds the field missing in v2 records with nothing to fall back to (not forward). The producer restarts with a cold schema cache. Open at this step: step 3, v2 deployed: a field removed
  4. v2 accepted · the consumer stops t+1.500s On the send of O2 the serializer registers v2 and the registry leader checks it against v1 under BACKWARD: compatible, so v2 is stored as schema id 2 and O2 reaches Kafka. The consumer fetches id 2, Avro cannot resolve it against the v1 reader, and poll() throws a RecordDeserializationException at offset 1. The group stops there. Open at this step: step 4, v2 accepted · the consumer stops
  5. O3 waits behind O2 t+2.000s O3 is written too, and waits behind O2: the consumer keeps failing at offset 1, so its position and committed offset stay at 1 while the lag grows. Skipping the record would lose it; the reader has to change. Open at this step: step 5, O3 waits behind O2
  6. Consumer upgraded to v2 · caught up t+2.800s The consumer is redeployed with a reader generated from v2. Under BACKWARD a v2 reader reads both versions, so it reads O2 and O3 and the group catches up. This is the upgrade order BACKWARD expects: consumers first, then producers. Open at this step: step 6, Consumer upgraded to v2 · caught up

The takeaway

The registry did its job: under BACKWARD a v2 reader can read every v1 record, so it accepted v2. A consumer still on v1 is the case BACKWARD does not cover, and Avro fails to resolve the v2 writer schema against its v1 reader, so poll() throws a RecordDeserializationException at the first v2 record and the group stops there. Under BACKWARD upgrade consumers first, then producers; under FORWARD the other way round. A generic reader would have read the record with the writer's schema.

Embed this scenario

Paste this into a blog post, a course page or your team's docs. The scenario plays inside your page, and the link under it points readers to this walkthrough.

<iframe src="https://monedula.dev/kafka-simulator/embed/?scenario=25.1.11" title="Kafka Simulator: Backward mode accepts it, an old consumer cannot read it" width="100%" height="520" style="border:1px solid #d0d0d0;border-radius:8px" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
<p><a href="https://monedula.dev/kafka-simulator/scenarios/consumer-reader-incompatible/">Kafka consumer cannot read a new schema under BACKWARD</a></p>

Further reading

Confluent documentation

Troubleshooting

More in Schema registry

All scenarios