On this page
Kafka troubleshooting
SerializationException: Schema not found (40403)
org.
Every record written by a Confluent serializer carries a schema id, and the reader asked Schema Registry for an id it does not know, or a producer asked for a schema that was never registered. The usual causes are a schema registered nowhere, records mirrored from a cluster that uses a different registry, and a registry rebuilt from the wrong _schemas topic.
Reproduce it in the playground3 steps beforep1 restarted: its send fails. t+1.900s
p1 restarted with an empty schema cache. Its next send must ask SR for the id of orders-value v1, no instance answers, and the serializer throws before the record reaches the batch. Nothing is appended.
Open at this step: step 4, p1 restarted: its send fails2 steps beforec1 restarted: stuck at P1. t+2.900s
c1 restarted too. p2, still warm, keeps writing P1 and P2, but c1 cannot look up the id of P1: it stops at that record. It stays in the group (no rebalance) while its lag grows.
Open at this step: step 5, c1 restarted: stuck at P11 step beforeSR back: both recover. t+4.000s
sr-1 is back. c1 looks up id 1, reads P1 and P2 and catches up; p1 resolves the id and its O2 goes through. Both caches are warm again.
Open at this step: step 6, SR back: both recoverThe moment it happensp2 deploys v2: not registered. t+4.700s
p2 runs with auto.register.schemas=false and is redeployed with schema v2, which nobody registered. SR is up, but its serializer only looks the schema up, finds no such version and throws: schema not found. Register the version first, from CI.
Open at this step: step 7, p2 deploys v2: not registeredWhat it means
The Confluent serializers write a magic byte and a four-byte schema id in front of each record. The id is only meaningful in the registry that assigned it: the leader hands out ids in order and stores them in its _schemas topic, and every instance reading that topic knows the same ids. The deserializer turns the id back into a schema with GET /schemas/ids/{id}; if the registry has no schema with that id it answers HTTP 404 with error code 40403, schema not found, and the client throws a RestClientException wrapped in a SerializationException from poll, in recent clients as a RecordDeserializationException naming the partition and offset. On the producer side, a serializer with auto.register.schemas=false looks the schema up under its subject instead of registering it; a schema that was never registered fails with 40403, or with 40401 subject not found when the subject itself does not exist, and 40402 version not found when a pinned version is missing. The more dangerous case does not raise an error. Two independent registries assign ids independently, so id 7 can mean an orders schema in one region and a payments schema in another. A record mirrored between clusters keeps its bytes, id included, and a consumer that asks the other registry either gets 40403 or, when that id happens to exist there, decodes the record with the wrong schema.
Likely causes, most common first
- The schema was never registered. A producer with auto.register.schemas=false, use.latest.version=false and no pinned version sends a schema version that CI never registered, or registered under a different subject because the subject name strategy differs. The lookup fails before any record is written.
- Records were mirrored between independent registries. MirrorMaker 2, Cluster Linking or another replicator copies records from a cluster whose producers use one registry to a cluster whose consumers use another. The ids in the copied records belong to the source lineage, so the target registry does not know them, or knows them as different schemas.
- The registry was rebuilt or points at the wrong _schemas topic. A registry started with a new kafkastore.topic, on a new backing cluster, or after _schemas was lost, begins numbering again from scratch. Every record written before it carries an id from the old lineage.
- The schema was deleted. A hard delete of a subject version removes it from the registry. Records written with that id are still on the topic, and a consumer reading them from an earlier offset, or a new consumer reading from the beginning, gets 40403.
How to fix it
- Ask the registry the consumer uses for the id directly, GET /schemas/ids/7 against its URL, and compare with the registry the producer used; a 40403 in one and a schema in the other confirms two lineages.
- Register schemas in CI before the producer that needs them is deployed, under the subject name the producer will use, and keep auto.register.schemas=false in production.
- For one id lineage across regions, run a follower-only registry in the disaster recovery site on a mirrored _schemas topic, with leader.eligibility=false, or use Schema Linking, or a single global registry that every region writes to.
- Back up the _schemas topic and give it replication factor 3 and min.insync.replicas=2, so a registry never has to be rebuilt from nothing.
- Prefer soft deletes, and only hard delete a schema once no topic still holds records written with it.
What not to do
- Re-registering the schema in the other registry and hoping for the same id: it gets the next free id there, which does not match the records.
- Pointing consumers at a registry from another lineage because it happens to answer: ids that exist in both decode silently with the wrong schema.
Does the client retry it?
No. The registry answers 40403 every time until the schema with that id exists in the registry the client asks. A producer must register the schema or change its configuration; a consumer stays on the record until the right registry answers for its id, or until the application seeks past it and skips the record.
Configs involved
min.The fewest in-sync replicas, leader included, that must have a write for an acks=all produce to succeed (default 1); with fewer in the ISR the leader rejects the write with NOT_ENOUGH_REPLICAS.insync. replicas
Reproduce it in the simulator
- Kafka Schema Registry down: a restarted client stops (Schema Registry down: a restart stops the client) Open at the moment it happens: Kafka Schema Registry down: a restarted client stops
- Two independent Schema Registries break mirrored Kafka data (Two independent registries break mirrored data) Open at the moment it happens: Two independent Schema Registries break mirrored Kafka data
Sources
- Confluent: Schema Registry serializers and deserializers (wire format, auto.register.schemas, use.latest.version)
- Confluent: Schema Registry API reference (40401, 40402, 40403)
- Confluent: multi-datacenter Schema Registry
- Confluent: Schema Registry configuration reference (kafkastore.topic, leader.eligibility)
- Confluent Schema Registry source: Errors.java
- Confluent Schema Registry source: RestClientException.java
- Apache Kafka 4.4 Javadoc: RecordDeserializationException