On this page
Kafka troubleshooting
RecordDeserializationException: Error deserializing VALUE (Avro schema resolution)
org.
The consumer fetched a record its value deserializer could not turn into an object, and poll() threw at that offset. With Avro and Schema Registry the usual cause is a schema change the registry accepted that the consumer's reader schema cannot read: under BACKWARD, the default, a producer upgraded before its consumers. Upgrade the consumer's schema, or read with a generic reader.
Reproduce it in the playground3 steps beforev1 · 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 mode2 steps beforeO1 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 reader1 step beforev2 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 removedThe moment it happensv2 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 stopsRight afterO3 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 O2What it means
KafkaConsumer runs the key and value deserializers inside poll(). When one throws, the client wraps the failure in a RecordDeserializationException with a message like Error deserializing VALUE for partition orders-0 at offset 1. If needed, please seek past the record to continue consumption. The consumer's position stays at that offset, so the next poll() fails on the same record and the group stops there while lag grows behind it. The cause is the deserializer's own exception. A Confluent Avro deserializer reads the schema id in front of the record, fetches the writer's schema from Schema Registry, and resolves it against the reader schema: the writer's schema itself for a generic reader, the generated class with specific.avro.reader=true, or the subject's latest version with use.latest.version=true. If Avro cannot resolve the two, the deserializer throws a SerializationException, Error deserializing Avro message for id 2, whose cause names the problem, for example Found orders.Order, expecting orders.Order, missing required field note. The registry's compatibility mode only guarantees one direction: BACKWARD, the default, means a consumer on the new schema can read old data, and says nothing about a consumer still on the old schema reading new data. Since Kafka 3.9 the exception also carries the origin (KEY or VALUE), the timestamp and the raw key and value bytes, so a handler can log or dead-letter the record before it seeks past it.
Likely causes, most common first
- Producers were upgraded before consumers under BACKWARD. BACKWARD accepts a change that removes a field without a default, because a reader on the new schema simply ignores it in old records. A consumer still on the old generated class expects that field in every record and has nothing to fall back to, so it fails at the first record written with the new version.
- The subject runs under NONE. With compatibility switched off the registry stores any change, renames and type changes included. Every consumer with a specific reader that does not match fails on the first new record.
- The consumer pins the latest version. With use.latest.version=true the reader is whatever the subject's latest version is. A new version that cannot read older records breaks a consumer reading from an earlier offset, even though nothing in the consumer was deployed.
- The bytes are not what the deserializer expects. A record written with a different serializer, plain JSON or a string on a topic read with an Avro deserializer, fails before any schema is involved, typically with Unknown magic byte. A schema id the consumer's registry does not know fails with schema not found, also wrapped in a RecordDeserializationException.
How to fix it
- Upgrade the consumer to a reader schema that reads the new version: regenerate the classes from the latest schema and redeploy. Under BACKWARD a consumer on the new schema reads both old and new records, so the group resumes at the offset it stopped on without losing anything.
- Follow the upgrade order the mode implies: under BACKWARD deploy consumers first and producers after, under FORWARD producers first, and under FULL either order works.
- Read with a generic reader (specific.avro.reader=false, the default) where the code does not need generated classes: it decodes each record with the writer's own schema.
- Test a change against the readers you run, not just the registry: a FULL or FULL_TRANSITIVE subject rejects changes that one side cannot read, at the cost of fewer allowed changes.
- Handle the exception in the poll loop: log the partition and offset from the RecordDeserializationException, send the raw bytes to a dead letter topic if the record must be kept, and only then call seek(partition, offset + 1). Do it on purpose, for a record you know is bad, not to get past a reader that is out of date.
What not to do
- Seeking past the failing offset to unblock the group after a schema change: every record written with the new version fails the same way, so the consumer skips all of them, not one.
- Switching the subject to NONE so that a change goes through: it removes the check that would have caught the next change a consumer cannot read.
Does the client retry it?
No. The consumer's position does not move past a record it cannot deserialize, so every poll() fetches the same record and throws again. Only a reader that can read it, or an application that deliberately seeks past the offset, gets the group moving.
Reproduce it in the simulator
- Kafka consumer cannot read a new schema under BACKWARD (Backward mode accepts it, an old consumer cannot read it) Open at the moment it happens: Kafka consumer cannot read a new schema under BACKWARD
Sources
- Apache Kafka source: CompletedFetch.java (the RecordDeserializationException message)
- KIP-1036: Extend RecordDeserializationException exception
- Confluent: schema evolution and compatibility (upgrade order per mode)
- Confluent: Avro serializer and deserializer (specific.avro.reader, use.latest.version)
- Confluent Schema Registry source: AbstractKafkaAvroDeserializer.java
- Apache Avro source: Resolver.java (missing required field)