Kafka Sink Connector
Schema Error
Error Code 40403
Troubleshooting Kafka
Technology Failures

Kafka sink connector fails: Schema not found; error code: 40403

Codemia Knowledge Hub ·

"Schema not found; error code: 40403" means the Kafka Connect sink connector looked up a schema in Schema Registry and it does not exist under the expected subject. The usual causes are messages produced without registering a schema, a subject naming strategy that differs between producer and connector, or a connector pointed at the wrong Schema Registry instance.

How the connector looks up schemas

A producer using the Avro, Protobuf or JSON Schema serializer registers the schema with Schema Registry and embeds the schema ID in the message payload as a 5-byte header (magic byte plus 4-byte schema ID).

When the sink connector deserializes the message, it reads that ID and fetches the schema from Schema Registry. If there is no schema for that ID, or the subject the connector expects does not exist, you get 40403:

 
org.apache.kafka.connect.errors.DataException:
  my-topic-value - Schema not found; error code: 40403

The <subject>-value part of the message tells you which subject the connector was looking for.

Cause 1: the schema was never registered

No schema gets registered when the producer does not use a schema-aware serializer. This happens when:

  • The producer uses StringSerializer or ByteArraySerializer instead of KafkaAvroSerializer
  • The producer was configured with auto.register.schemas=false and no schema was pre-registered
  • The topic received data from a source that does not interact with Schema Registry

Fix: register the schema manually, or switch the producer to a schema-aware serializer. First see what exists:

bash
1# Check if any schemas exist for the topic
2curl -s http://localhost:8081/subjects | jq .
3
4# Check specific subject
5curl -s http://localhost:8081/subjects/my-topic-value/versions | jq .

If the subject is missing, register the schema:

bash
1curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" \
2  --data '{
3    "schema": "{\"type\":\"record\",\"name\":\"Order\",\"fields\":[{\"name\":\"id\",\"type\":\"long\"},{\"name\":\"amount\",\"type\":\"double\"}]}"
4  }' \
5  http://localhost:8081/subjects/my-topic-value/versions

Cause 2: subject naming strategy mismatch

The subject naming strategy decides which subject name is used for a topic. The default, TopicNameStrategy, uses <topic>-key or <topic>-value. If the producer registered the schema under a different strategy, the connector looks for a subject that does not exist.

StrategySubject Name FormatUse Case
TopicNameStrategy (default)<topic>-valueOne schema per topic
RecordNameStrategy<fully.qualified.RecordName>Multiple record types per topic
TopicRecordNameStrategy<topic>-<fully.qualified.RecordName>Multiple record types, scoped per topic

Fix: use the same strategy on the producer and the connector:

properties
1# Producer configuration
2value.subject.name.strategy=io.confluent.kafka.serializers.subject.TopicNameStrategy
3
4# Sink connector configuration (converter settings take the value.converter. prefix)
5value.converter.value.subject.name.strategy=io.confluent.kafka.serializers.subject.TopicNameStrategy

Then check which subjects actually exist:

bash
1# List all subjects
2curl -s http://localhost:8081/subjects | jq .
3
4# If you see "Order" instead of "my-topic-value",
5# the producer is using RecordNameStrategy

Cause 3: wrong Schema Registry URL

The connector points at a different Schema Registry instance than the producer used:

json
1{
2  "name": "my-sink-connector",
3  "config": {
4    "connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
5    "value.converter": "io.confluent.connect.avro.AvroConverter",
6    "value.converter.schema.registry.url": "http://wrong-host:8081",
7    "topics": "my-topic"
8  }
9}

Fix: check the URL in both the connector configuration and the Connect worker properties, and confirm the registry is reachable from the worker:

bash
1# Check worker-level config
2grep schema.registry /etc/kafka/connect-distributed.properties
3
4# Check connector-level config
5curl -s http://localhost:8083/connectors/my-sink-connector/config | jq '.["value.converter.schema.registry.url"]'
6
7# Verify Schema Registry is reachable from the Connect worker
8curl -s http://schema-registry-host:8081/subjects

The converter-level URL (value.converter.schema.registry.url) overrides the worker-level URL.

Cause 4: the schema was deleted or soft-deleted

A hard or soft delete of the schema makes the lookup fail:

bash
1# Check if the subject exists but has been soft-deleted
2curl -s "http://localhost:8081/subjects/my-topic-value/versions?deleted=true" | jq .
3
4# Restore a soft-deleted subject
5curl -X POST "http://localhost:8081/subjects/my-topic-value/versions" \
6  -H "Content-Type: application/vnd.schemaregistry.v1+json" \
7  --data '{"schema": "..."}'

Cause 5: AvroConverter reading plain JSON

If the connector uses AvroConverter but the messages are plain JSON rather than Avro-encoded, the converter tries to read the 5-byte schema ID header and fails:

json
1{
2  "value.converter": "io.confluent.connect.avro.AvroConverter",
3  "value.converter.schema.registry.url": "http://localhost:8081"
4}

Fix: match the converter to the real message format:

json
1{
2  "value.converter": "org.apache.kafka.connect.json.JsonConverter",
3  "value.converter.schemas.enable": false
4}
Message FormatCorrect Converter
Avro (with Schema Registry)io.confluent.connect.avro.AvroConverter
JSON with schemaorg.apache.kafka.connect.json.JsonConverter (schemas.enable=true)
Plain JSONorg.apache.kafka.connect.json.JsonConverter (schemas.enable=false)
Protobufio.confluent.connect.protobuf.ProtobufConverter
Stringorg.apache.kafka.connect.storage.StringConverter

Step-by-step diagnosis

Work through these checks in order. Consuming a message with kafka-avro-console-consumer verifies the message format and schema ID independently of the connector.

bash
1# 1. Identify the subject the connector is looking for (from error message)
2# Example: "my-topic-value - Schema not found"
3
4# 2. List all subjects in Schema Registry
5curl -s http://localhost:8081/subjects | jq .
6
7# 3. Check if the expected subject exists
8curl -s http://localhost:8081/subjects/my-topic-value/versions | jq .
9
10# 4. If it does not exist, inspect a message from the topic
11kafka-console-consumer --bootstrap-server localhost:9092 \
12  --topic my-topic --from-beginning --max-messages 1 \
13  --property print.headers=true
14
15# 5. Check the schema ID embedded in the message
16kafka-avro-console-consumer --bootstrap-server localhost:9092 \
17  --topic my-topic --from-beginning --max-messages 1 \
18  --property schema.registry.url=http://localhost:8081
19
20# 6. Verify the connector configuration
21curl -s http://localhost:8083/connectors/my-sink-connector/config | jq .
22
23# 7. Check connector status for detailed error
24curl -s http://localhost:8083/connectors/my-sink-connector/status | jq .

A working JDBC sink configuration

A JDBC sink connector with all schema-related settings configured correctly:

json
1{
2  "name": "orders-jdbc-sink",
3  "config": {
4    "connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
5    "tasks.max": "1",
6    "topics": "orders",
7    "connection.url": "jdbc:postgresql://localhost:5432/mydb",
8    "connection.user": "dbuser",
9    "connection.password": "dbpass",
10    "auto.create": "true",
11    "insert.mode": "upsert",
12    "pk.mode": "record_value",
13    "pk.fields": "id",
14    "value.converter": "io.confluent.connect.avro.AvroConverter",
15    "value.converter.schema.registry.url": "http://schema-registry:8081",
16    "value.converter.value.subject.name.strategy": "io.confluent.kafka.serializers.subject.TopicNameStrategy",
17    "key.converter": "org.apache.kafka.connect.storage.StringConverter"
18  }
19}

Mistakes that cause 40403

Mixing serialization formats. Producing JSON and consuming with AvroConverter (or the reverse) breaks deserialization. The converter must match the format actually on the topic.

Forgetting the converter prefix. Set the connector's registry URL as value.converter.schema.registry.url, not just schema.registry.url, which is for the worker-level config. Without the prefix the converter does not know where the schemas are.

Sharing one Schema Registry across environments. If dev and staging topics share a registry, subjects from one environment may be missing in another. Use separate registries or a prefix-based naming convention.

Skipping the connector status API. /connectors/<name>/status in the Connect REST API often holds the full stack trace with the exact subject that failed, which is more useful than the worker logs.

Expecting the consumer to register schemas. auto.register.schemas is a producer-side setting. The sink connector only reads schemas and never registers them, so the schema must exist before the connector reads the message.

Confusing key and value schemas. The subject in the error ends in -key or -value. They are separate subjects, so investigate the right one.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design