Monedula

Markdown

Part VI · Reference

Kafka troubleshooting

SerializationException: Schema Registry has no leader (50004, 50003)

Kafka error · 50004 / 50003 / 50002 / 50001 · not retriable

org.apache.kafka.common.errors.SerializationException

Only the Schema Registry leader writes new schemas, and it writes them to the _schemas topic on Kafka. With no leader elected (50004), a leader the instance cannot forward to (50003), or a leader that cannot write _schemas in time (50002, 50001), registering a genuinely new schema fails. Lookups and already registered schemas keep working.

Reproduce it in the playground

The moment it happensa new schema cannot register. t+3.100s

p1 is redeployed with schema v2. Registering it needs a leader, none can be elected in dc-b, and the serializer fails. Old schemas keep flowing; new ones wait for dc-a.

Open at this step: step 5, a new schema cannot register

What it means

A Schema Registry cluster is a set of instances that elect one leader through the Kafka group protocol: they join a group on the backing Kafka cluster, named schema-registry by default, and only instances with leader.eligibility=true can win. The leader is the only writer. It appends each new schema to the compacted topic named by kafkastore.topic, _schemas by default, producing with acks=all, and every instance, the leader included, rebuilds its in-memory registry by reading that topic. Reads are therefore local: any instance answers GET /schemas/ids/{id} or a lookup under a subject from memory. A registration, POST /subjects/{subject}/versions, first looks the schema up under the subject, so a schema that is already registered gets its existing id from whichever instance received the request, without the leader. Only a genuinely new schema, or a new subject, is forwarded to the leader. That is where it breaks. With no eligible instance alive, or with the instances unable to reach Kafka to run the election, there is no leader and the registry answers error code 50004, unknown leader. If a leader exists but the instance cannot forward the request to it, the answer is 50003. If the leader cannot get its write acknowledged on _schemas within kafkastore.timeout.ms, for example because _schemas has fewer in-sync replicas than its min.insync.replicas, it answers 50002, operation timed out, or 50001 for another backend store error. The client receives a RestClientException carrying the code, and the serializer wraps it in a SerializationException thrown from send.

Likely causes, most common first

  1. No leader-eligible instance is running. All instances with leader.eligibility=true are down, or every instance in the surviving location was deployed with leader.eligibility=false, as a follower-only standby. The followers keep answering lookups from memory, but nothing can register a new schema.
  2. The registry cannot reach its Kafka cluster. The election runs through a group on the backing Kafka cluster and the leader writes to _schemas on it. Lose that cluster, or the network to it, and no leader can be elected or write, even if every registry instance is healthy.
  3. The _schemas topic cannot take an acks=all write. If _schemas was created with replication factor 1, or its in-sync replicas fall below its min.insync.replicas after a broker failure, the leader write is not acknowledged within kafkastore.timeout.ms and registration fails with 50002 or 50001.
  4. Followers cannot forward to the leader. A request that lands on a follower is forwarded over HTTP to the leader. A leader that advertises an address the followers cannot reach, through host.name or listeners, or a firewall between instances, gives 50003 while the leader itself works.

How to fix it

  • Run more than one leader-eligible instance wherever registration must survive a failure, and check which instance is leader; the registry logs the election result, and the leader is the one whose writes reach _schemas.
  • Check the backing cluster and the topic: kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic _schemas shows the replicas and the ISR. Give _schemas replication factor 3 and set min.insync.replicas=2 on it yourself; Schema Registry does not set min.insync.replicas.
  • Register schemas in CI or a deploy step and run production producers with auto.register.schemas=false, so a leader outage never blocks a release that only uses schemas registered earlier.
  • For a planned failover to a standby location, make its _schemas copy writable and restart the standby instances with leader.eligibility=true, so one of them becomes leader there.
  • Make sure every instance advertises an address the others can reach, so a follower can forward a registration to the leader.

What not to do

  • Pointing a second registry at a different _schemas topic to get writes working again: it starts its own id lineage, and its ids collide with the old ones.
  • Treating the outage as total: lookups and warm clients still work, so restarting healthy producers only adds cache misses.

Does the client retry it?

Not by the producer: the serializer throws inside send, before the record is batched. The registration succeeds once an instance is leader again and can write to _schemas, so the application can retry the send then. Records with schemas the registry already holds keep flowing the whole time.

Configs involved

  • min.insync.replicas 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.
  • acks How many replicas must have a write before the producer counts it as sent: 0 (none), 1 (the leader only) or all (every in-sync replica, the default, and required for idempotence).

Reproduce it in the simulator

Sources

All troubleshooting pages