liveBook · Manning

Schema id

As explained in Kafka Streams in Action, Second Edition

A schema identifier is a unique numeric identifier assigned by Schema Registry to a registered schema.

A schema ID is the unique numeric identifier Schema Registry assigns when a schema is registered. Registration stores schemas under a subject and version, while the returned ID identifies the registered schema for later lookup. section 3.2.5

Use a schema ID when an application must select an exact registered schema rather than accepting the latest version. This is especially important for topics shared by multiple applications: matching schemas avoids data-formatting errors and lets supported clients infer fields and types from the schema. section 11.2

Work with schema IDs in a practical flow:

  • Register a schema by posting it to a subject’s versions endpoint; Schema Registry responds with an id. section 3.2.5
  • Inspect a subject’s versions or retrieve a particular version when checking what was registered. section 3.2.5
  • Set value_schema_id in a ksqlDB stream definition to use that exact Avro value schema. section 11.2
  • Omit the ID only when using the latest schema version is appropriate; ksqlDB otherwise assumes a topic-name key or value subject. section 11.2

Pin an Avro stream to schema ID 1

CREATE STREAM user_activity WITH (kafka_topic = 'user_activity', value_format = AVRO, value_schema_id = 1); This tells ksqlDB to retrieve the precise registered value-schema version, without separately declaring columns. section 11.2

Listing 3.6 Expected response from uploading a schema
{
  "id": 1
}

The registration response shows the numeric ID returned after a schema is uploaded. section 3.2.5

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Defines IDs through registration responses and demonstrates supplying one in a ksqlDB WITH clause, deferring broader format details.
Examples
Uses an Avengers schema registration returning id 1 and a user_activity Avro stream configured with value_schema_id = 1.
What it assumes
Introduces registration and basic Avro, Protobuf, and JSON Schema forms while deferring in-depth Protobuf and JSON Schema coverage.
What you can do after
Operate/configure ksqlDB to retrieve a precise registered schema version for an Avro stream.
How it connects
Connects Schema Registry IDs with schema subjects, schema versions, Avro, Protobuf, JSON Schema, and ksqlDB.

Also explained in

Compare how 2 books explain schema id →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka Streams in Action, Second Edition. The section links point to the parts of the book it draws on.