Schema registry

On this page 7

A schema registry is a central service that stores versioned schemas for the messages flowing through an event platform and checks every new schema version against configurable compatibility rules. In streaming data architectures, it acts as the shared contract between producers and consumers, so that applications written by different teams can evolve independently without breaking each other.

The registry typically works alongside a message broker such as Kafka, Redpanda or Apache Pulsar. Producers register the schema they write with, consumers fetch the schema they need to decode each record, and the registry keeps the full version history of every data structure. The result is safe schema evolution, smaller messages and a governed catalog of the data moving through the platform.

How a schema registry works in a streaming pipeline

A schema registry works by replacing the full schema with a short identifier inside every message. When a producer serializes a record, its client library looks up or registers the schema, receives a numeric schema ID, and writes that ID into a small header in front of the encoded payload. The consumer reads the ID, fetches the matching schema once, caches it locally and decodes the record.

In the widely used Confluent wire format, each message starts with a magic byte followed by a four-byte schema ID, and only then the binary payload. This keeps the per-message overhead to five bytes, instead of repeating a schema that may be several kilobytes long. Because clients cache schemas aggressively, the registry is usually contacted only when a new schema appears, not for every record.

Schemas are grouped into subjects, which are named version histories. A subject usually maps to a topic and to the key or value part of a message, for example orders-value. The table below summarizes the main elements that a registry manages.

ElementWhat it isTypical example
SchemaA formal definition of fields and typesAn Avro record with order ID, amount and timestamp
Schema IDA globally unique number for one schemaID 1042 written into each message header
SubjectA named sequence of schema versionsorders-value
VersionOne entry in a subject’s historyVersion 7 of orders-value
Compatibility levelThe rule applied to new versionsBACKWARD on the orders-value subject
Core elements managed by a schema registry

Supported schema formats

Most registries support three serialization formats: Apache Avro, Protocol Buffers and JSON Schema. The choice affects message size, tooling, code generation and how strictly evolution can be checked, so it is usually made once per platform rather than per topic.

FormatEncodingStrengthsWeaknesses
Apache AvroCompact binaryMature evolution rules, default values, small payloadsRequires the writer schema to decode
Protocol BuffersCompact binary with field numbersStrong code generation, wide language supportField number reuse can silently corrupt data
JSON SchemaText JSONHuman-readable, easy to debugLarger messages, looser compatibility semantics
Comparison of common schema formats

Avro remains the most common choice in Kafka-centric platforms because its resolution rules between a writer schema and a reader schema map directly onto registry compatibility checks. Protocol Buffers is popular where gRPC services already define the data model, while JSON Schema suits teams that value readability over throughput.

Compatibility modes and schema evolution

Compatibility modes define which schema changes are allowed when a new version is registered. The registry compares the proposed schema with one or more earlier versions and rejects the registration if the change would break the agreed rule. This check is the main reason organizations deploy a registry at all.

The distinction between modes depends on which side upgrades first. Backward compatibility lets new consumers read old data, so consumers upgrade before producers. Forward compatibility lets old consumers read new data, so producers can upgrade first. Full compatibility requires both directions and offers the most freedom in deployment order.

ModeGuaranteeSafe changesUpgrade order
BACKWARDNew schema reads data written with the previous oneDelete fields, add optional fieldsConsumers first
FORWARDPrevious schema reads data written with the new oneAdd fields, delete optional fieldsProducers first
FULLBoth directions with the previous versionAdd or delete optional fields onlyAny order
NONENo check is performedAny changeCoordinated manually
Compatibility modes and their consequences

Each mode also has a transitive variant, such as BACKWARD_TRANSITIVE, that checks the new schema against all earlier versions rather than only the latest. Transitive modes matter when topics retain data for months or when consumers may replay history from the beginning, which is common in event sourcing and Kappa architecture designs.

A schema registry is not the only way to handle data structure in an event stream, and comparing it with the alternatives clarifies what it adds. The key difference is enforcement at write time rather than discovery or documentation after the fact.

ApproachWhere the schema livesEnforcementTypical drawback
Schema registryCentral versioned serviceChecked on registration and serializationExtra infrastructure to operate
Embedded schemaInside every messageNone between producersLarge payloads and no shared contract
Schemaless JSONImplicit in application codeNoneBreakage discovered only at runtime
Data catalogMetadata store for discoveryDocumentation onlyCan drift from real messages
Ways to manage message structure

In practice, a registry often feeds a data catalog with authoritative structures, and stream processing engines such as Apache Flink or Kafka Streams use it to derive table schemas automatically for SQL queries over streams.

Operating a schema registry in production

Running a registry well requires treating schemas as code. Mature teams keep schema files in version control, run compatibility checks in continuous integration, and register schemas through a deployment pipeline instead of letting applications auto-register them at startup. Disabling auto-registration in production prevents an untested service from publishing an unexpected version.

  • Choose a subject naming strategy early: topic name, record name or a combination, because changing it later splits version histories.
  • Secure the registry with authentication and access control, since anyone who can register schemas can block or redirect producers.
  • Run several instances behind a load balancer, because a registry outage stops new producers and consumers from starting.
  • Avoid NONE compatibility except for short migrations, and document every exception.

Common failure modes include reusing a deleted Protobuf field number, adding a required Avro field without a default, and serializer mismatches where a consumer expects plain JSON but receives framed binary records. Most of these problems surface as deserialization errors in consumer logs, often far from the team that caused them.

The short version

A schema registry is a shared dictionary for the messages that applications send to each other. Every message follows a layout, such as which fields exist and what kind of value each one holds. The registry stores that layout once, gives it a number, and lets every message carry only the number.

Its most useful job is acting as a gatekeeper. When a team wants to change a layout, the registry checks whether existing readers will still understand the messages. If the change would break them, it is refused. The key benefit is that teams can change their data safely without calling a meeting every time a field is added.

Where it makes a difference

An online retailer streams about 40,000 order events per second through Kafka. A payments service, a fraud detection model and a warehouse system all consume the same orders topic, and each belongs to a different team. The subject for the topic value is set to BACKWARD_TRANSITIVE compatibility, and schemas are registered only through the continuous integration pipeline.

One day the checkout team tries to rename the field amount to total_amount. The pipeline submits the new Avro schema to the registry, which rejects it because existing data could no longer be read with the new definition. The team instead adds total_amount as an optional field with a default and keeps amount for a transition period. No consumer fails in production, and the payload overhead stays at five bytes per message instead of the roughly two kilobytes an embedded schema would add.