On this page
Kafka troubleshooting
SerializationException: Schema Registry unreachable
org.
The Confluent serializer or deserializer missed its local cache and had to ask Schema Registry, and no instance answered. The client wraps the ConnectException or IOException in a SerializationException: the producer fails that send, the consumer stops at that record. Clients whose caches already hold the schema keep working through the outage.
Reproduce it in the playground3 steps beforetwo warm producers, one consumer. t+0.000s
p1 and p2 write orders with schema id 1 (p2 runs with auto.register.schemas=false); c1 reads them. All three have the id cached.
Open at this step: step 1, two warm producers, one consumer2 steps beforeO1 written and read. t+1.000s
Steady state: no client talks to Schema Registry.
Open at this step: step 2, O1 written and read1 step beforesr-1 down. t+1.300s
The only SR instance dies. Kafka is healthy.
Open at this step: step 3, sr-1 downThe moment it happensp1 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 failsRight afterc1 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 P1What it means
The Confluent Avro, Protobuf and JSON Schema serializers do not call Schema Registry for every record. The serializer keeps a cache from schema to id and the deserializer a cache from id to schema, both filled on first use. A warm client never calls the registry on the hot path, so a registry outage is invisible to it. The registry matters on a cache miss: the first record a new or restarted producer sends with a schema, the first record a consumer reads with an id it has not seen, or a deploy that brings a new schema version. Then the serializer either registers the schema with POST /subjects/{subject}/versions (auto.register.schemas=true, the default) or looks it up (auto.register.schemas=false with use.latest.version=true or a pinned version), and the deserializer fetches GET /schemas/ids/{id}. Any registry instance can answer a lookup, and a registration of a schema the subject already holds; only a new schema needs the leader. When the client cannot reach any URL in schema.registry.url, the REST client fails with a java.net.ConnectException or another IOException, and the serde wraps it in org.apache.kafka.common.errors.SerializationException, for example "Error serializing Avro message" or "Error retrieving Avro schema for id 7". On the producer the exception comes straight out of send: the record never entered the accumulator, so nothing was written and nothing will be retried. On the consumer it comes out of poll, in recent clients as a RecordDeserializationException that names the partition and offset; the consumer position stays on that record, so every later poll fails the same way until the registry answers or the application seeks past the record and skips it.
Likely causes, most common first
- Every registry instance is down or unreachable. A single registry instance with no standby, a network partition between the clients and the registry, a load balancer with no healthy targets or a wrong schema.registry.url all look the same to the client: no instance answers. Clients that are already warm notice nothing; the next cache miss fails.
- Clients were restarted during the outage. A rolling deploy, an autoscaling event or a crash loop starts clients with empty caches. Each one must reach the registry for its first record, so a registry outage that warm clients ignored stops every restarted producer at its first send and every restarted consumer at its first record.
- A new schema version arrived during the outage. A producer that starts sending a new schema version, or a consumer that reads the first record written with a new id, misses its cache even though it has run for days. The failure starts with the deploy, not with the outage.
- The registry is not deployed where the clients run. In a multi-DC or multi-region setup with registry instances in only one location, losing that location or the link to it leaves clients elsewhere with no instance to ask, even though their Kafka cluster is healthy.
How to fix it
- Run at least two registry instances behind a load balancer, or list several URLs in schema.registry.url, in every data center that has clients, so one instance or one host failing never leaves a client with nobody to ask.
- Check what the client sees: curl the registry URL from the client host, for example GET /subjects, and read the root cause under the SerializationException; a ConnectException or a timeout points at the network or the instances, an HTTP error code points at the registry itself.
- Do not roll, restart or scale out producers and consumers while the registry is down: warm caches are what keep traffic flowing, and a restart throws them away.
- Register schemas ahead of time, in CI or a deploy step, and run production producers with auto.register.schemas=false, so a new release never depends on a registry write at startup.
- In the producer, catch SerializationException from send and retry the send with a backoff once the registry is back, or park the record; in the consumer, alert on a partition stuck at one offset rather than skipping the record.
What not to do
- Raising retries or delivery.timeout.ms on the producer: the record failed before it reached the batch, so the producer never retries it.
- Seeking past the failing record to get the consumer moving: the record is valid, it only needs the registry, and skipping it loses it.
Does the client retry it?
Not by the producer. The serializer throws inside KafkaProducer.send, before the record reaches a batch, so retries and delivery.timeout.ms never apply to it; the application can catch the exception and call send again once a registry instance answers. A consumer fails again on every poll at the same offset until the registry answers, then carries on without losing a record.
Configs involved
retriesHow many times the producer sends a batch again after a transient error (default 2147483647, so in practice delivery.timeout.ms ends the retrying); idempotence needs it above 0.delivery.The upper bound on reporting success or failure after send() returns, covering the wait in a batch, the wait for the acknowledgement and every retry (default 120000, 2 minutes); it should be at least request.timeout.ms plus linger.ms.timeout. ms
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
- Highly available Schema Registry: leader failover (HA Schema Registry: the leader fails over) Open at the moment it happens: Highly available Schema Registry: leader failover
Sources
- Confluent: Schema Registry serializers and deserializers (caching, auto.register.schemas, use.latest.version)
- Confluent: running Schema Registry in production (multiple instances, load balancing)
- Confluent: Schema Registry API reference
- Confluent Schema Registry source: RestClientException.java
- Apache Kafka 4.4 Javadoc: SerializationException
- Apache Kafka 4.4 Javadoc: RecordDeserializationException