Monedula

Markdown

Part VI · Reference

Kafka troubleshooting

SerializationException: Schema being registered is incompatible with an earlier schema (409)

Kafka error · 409 · not retriable

org.apache.kafka.common.errors.SerializationException

The producer's serializer tried to register a new schema version, and Schema Registry refused it because it breaks the subject's compatibility mode. Under BACKWARD, the default, the usual cause is a new field without a default. The send fails before anything reaches Kafka: give the field a default and redeploy.

Reproduce it in the playground

The moment it happensv2 rejected · 409. t+1.600s

On the send of O2 the serializer registers v2 and the registry leader checks it against v1 under BACKWARD: incompatible. It answers HTTP 409 and the send throws a SerializationException. O2 never reaches Kafka, the subject stays at v1, and the consumer is unaffected: it read O1 and waits for more.

Open at this step: step 4, v2 rejected · 409

What it means

A Confluent serializer with auto.register.schemas=true, the default, registers its schema under the subject the first time it serializes a record, with POST /subjects/{subject}/versions. The Schema Registry leader checks the new schema against the subject's compatibility mode before it stores anything: BACKWARD, the default, means a consumer on the new schema can read data written with the previous one; FORWARD means a consumer on the previous schema can read data written with the new one; FULL means both. Plain modes compare with the latest version only, the _TRANSITIVE variants with every version. A schema that fails the check is answered with HTTP 409 Conflict and the message Schema being registered is incompatible with an earlier schema for subject "orders-value", followed by details naming the broken rule. The error_code in the response body is 409 up to Confluent Platform 8.1 and 40901 from 8.2. The client raises it as a RestClientException ending in "; error code: 409", and the Avro serializer wraps it in a SerializationException, Error registering Avro schema, which KafkaProducer.send throws to the caller. No record is written, no version is created, and consumers keep reading what is already on the topic.

Likely causes, most common first

  1. A field was added without a default under BACKWARD. A consumer upgraded to the new schema would find no value for the new field in records written before it. Confluent's schema evolution guide calls out exactly this case: without the default the new schema is not backward compatible. The same change passes under FORWARD, where old readers simply ignore the new field.
  2. A field was removed under FORWARD. A consumer still on the old schema expects the field in every record. Removing a field is fine under BACKWARD and fails under FORWARD unless the old schema gave that field a default.
  3. A field was renamed or its type changed. A rename without an alias or an incompatible type change breaks both directions, so every mode except NONE rejects it. It is the change that most often needs a new field or a new topic instead of an edit.
  4. A transitive mode compared against an older version. Under BACKWARD_TRANSITIVE, FORWARD_TRANSITIVE or FULL_TRANSITIVE the new schema must be compatible with every registered version, not just the latest. A change that is fine against v4 can still break against v1.
  5. The subject has a stricter mode than the team expected. A subject-level mode overrides the registry-wide default. A subject set to FULL rejects changes that the global BACKWARD would accept.

How to fix it

  • Change the schema, not the registry: give the new field a default (for Avro a nullable field with default null is the usual choice) and redeploy the producer. Its next send registers the version.
  • Test a schema before deploying it: POST /compatibility/subjects/{subject}/versions/latest?verbose=true returns is_compatible and the messages explaining why, and the Schema Registry Maven plugin runs the same check in CI.
  • Register schemas from CI and keep auto.register.schemas=false in production, so an incompatible schema fails a pipeline instead of a live producer.
  • For a change that genuinely breaks compatibility, write it to a new subject or a new topic and migrate consumers, rather than editing the schema in place.
  • If the mode itself is wrong for the subject, change it on purpose with PUT /config/{subject}, and match the upgrade order to it: under BACKWARD upgrade consumers first, under FORWARD upgrade producers first.

What not to do

  • Setting the subject to NONE to get one deploy through: it removes the protection for every later change, and consumers on the old schema can start failing to deserialize.
  • Hard deleting the subject's versions to start a fresh history: records already on the topic still carry the old schema ids, and a reader that needs them gets schema not found.

Does the client retry it?

No. The registry checks the same schema against the same history and rejects it again on every send. Only a different schema or a different compatibility mode changes the answer, so the producer needs a redeploy or the subject a deliberate mode change.

Reproduce it in the simulator

Sources

All troubleshooting pages