{"record":{"id":"cd867909e98566e3","repo":"apache/druid","slug":"failed-to-find-schema-for-id-s","errorCode":null,"errorMessage":"Failed to find schema for id[%s]","messagePattern":"Failed to find schema for id\\[(.+?)\\]","errorType":"exception","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"extensions-core/avro-extensions/src/main/java/org/apache/druid/data/input/avro/InlineSchemasAvroBytesDecoder.java","lineNumber":114,"sourceCode":"  // byte 1 : version, static 0x1\n  // byte 2-5 : int schemaId\n  // remaining bytes would have avro data\n  @Override\n  public GenericRecord parse(ByteBuffer bytes)\n  {\n    if (bytes.remaining() < 5) {\n      throw new ParseException(null, \"Record must have at least 5 bytes carrying version and schemaId\");\n    }\n\n    byte version = bytes.get();\n    if (version != V1) {\n      throw new ParseException(null, \"Found record of arbitrary version[%s]\", version);\n    }\n\n    int schemaId = bytes.getInt();\n    Schema schemaObj = schemaObjs.get(schemaId);\n    if (schemaObj == null) {\n      throw new ParseException(null, \"Failed to find schema for id[%s]\", schemaId);\n    }\n\n    DatumReader<GenericRecord> reader = new GenericDatumReader<>(schemaObj);\n    try (ByteBufferInputStream inputStream = new ByteBufferInputStream(Collections.singletonList(bytes))) {\n      return reader.read(null, DecoderFactory.get().binaryDecoder(inputStream, null));\n    }\n    catch (Exception e) {\n      throw new ParseException(null, e, \"Failed to read Avro message with schema id[%s]\", schemaId);\n    }\n  }\n}\n","sourceCodeStart":96,"sourceCodeEnd":126,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/avro-extensions/src/main/java/org/apache/druid/data/input/avro/InlineSchemasAvroBytesDecoder.java#L96-L126","documentation":"After validating the version byte and reading the 4-byte schema id, the decoder looks the id up in the schemas configured inline in the ingestion spec. If no schema is registered for that id, decoding is impossible and a ParseException naming the id is thrown.","triggerScenarios":"A message on the topic carries a schema id that is not listed in the decoder's \"schemaInfos\"/inline schema list — e.g. the producer registered a new schema version and started stamping its id while the Druid spec still lists only older ids.","commonSituations":"Producers evolve the schema (new versions) after the ingestion spec was authored; multiple topics share a decoder whose id list covers only one topic; ids copied from the schema registry don't match the inline-listed ids.","solutions":["Add the missing schema (matching the id in the error) to the multiple_schemas decoder's schema list in the ingestion spec and restart/redo the supervision.","Prefer the schema_registry decoder so ids resolve dynamically against the registry instead of a static inline list.","Coordinate schema evolution: register the new version, update the ingestion spec, then switch producers to it.","Log/alert on schema-id drift and validate the failing message's id against the registry to confirm which schema to add."],"exampleFix":"// before\n{\"type\":\"multiple_schemas\",\"schemaInfos\":[{\"schema\":\"...v1...\",\"id\":1}]}\n// after\n{\"type\":\"multiple_schemas\",\"schemaInfos\":[{\"schema\":\"...v1...\",\"id\":1},{\"schema\":\"...v2...\",\"id\":2}]}","handlingStrategy":"validation","validationCode":"// Verify every schema id in use is registered in the decoder spec\nint schemaId = ByteBuffer.wrap(msg, 1, 4).getInt();\nif (!declaredSchemaIds.contains(schemaId)) {\n  throw new IllegalStateException(\"Schema id \" + schemaId + \" missing from multiple_schemas spec; add it before producing with that schema\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  GenericRecord r = decoder.parse(ByteBuffer.wrap(msg));\n} catch (ParseException e) {\n  if (String.valueOf(e.getMessage()).contains(\"Failed to find schema for id\")) {\n    alert(\"Producer using unregistered schema id — update ingestion spec\");\n    deadLetter(msg);\n  }\n}","preventionTips":["Keep the decoder's inline schema list in sync with all schema versions producers use.","Prefer schema_registry decoding to resolve ids dynamically.","Gate schema evolution: update the Druid spec (and restart tasks) before switching producers to a new schema id.","Alert on \"Failed to find schema for id\" parse exceptions to catch drift early."],"tags":["java","avro","schema-registry","schema-evolution"],"backgroundTag":"schema-validation-failed","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}