Schema registry
a store of identifiable versions of data schemas
What it is
A schema registry stores and identifies versions of the structures used to exchange data. A program can register a schema, retrieve it by an identifier, and compare a proposed version with earlier versions. In a message pipeline, a writer can associate data with the schema that produced it, and a reader can use that identity when decoding the stored bytes.
The exact arrangement depends on the chosen registry, serializer and encoding. A serializer can put a schema identifier into a message envelope, then write the encoded payload. A consumer that already knows that identifier can reuse its cached schema. Otherwise it needs a way to retrieve the schema that matches the message. The registry’s version history and the message’s schema identifier are both useful. One tells you how the structure evolved. The other tells you what a particular writer used.
Registries can check compatibility when a schema changes. A backward compatibility policy can ask whether a reader using the new schema can read data written with a schema from before the change. A forward policy asks about the other direction. Full compatibility checks both directions, and a transitive policy can check against a longer version history. The details of permitted changes depend on the data format and the configured policy. Understanding those details is important when several consumer versions run at once.
Why it matters
Messages can remain in a stream long after a writer has been upgraded. A consumer doing recovery might start at an earlier point in the stream. It will then encounter old records followed by records from several newer deployments. A schema registry links older and newer records to their respective schema versions so that a reader can decode each record correctly.
A compatibility decision determines who can upgrade first. Suppose a shipment event gains a tracking reference that older producers do not send. A new reader needs an agreed behaviour for older records. An older reader handling records from a newer producer has a separate compatibility question. Test the actual encoded variants with the versions that may meet in production. Include records retained for replay and use the distinctions the application cares about, such as an absent field and an explicitly empty value.
A structural check gives useful early feedback but has a specific scope. A proposed schema can keep a number field and still change what that number represents. A new interpretation of a shipping weight may need a new field or a coordinated transition. Capture such decisions outside the encoding check too. Business examples and consumer contract tests can establish the meaning that the registry’s type system cannot express.
What it looks like in practice
Imagine three applications reading shipment events. One produces alerts, another refreshes a dashboard, and the third rebuilds a historical projection after outages. Give a new schema a compatibility policy that reflects those lifetimes. Include a sample encoded by the oldest supported writer and one produced by the candidate writer. Exercise each supported reader, check the decoded values and record what happens when the registry cannot serve a schema briefly.
Keep the operation recoverable. Record how the registry is backed up and what registry data must accompany a stream restored in another environment. Some implementations assign identifiers that are meaningful within one registry. An unfamiliar registry can associate the wrong schema with an identifier unless the data and identity mappings migrate consistently. Restore a small historical sample and check what each payload actually decodes to. A successful backup command says little on its own about whether identifiers still refer to the right definitions.
Engineer’s database-to-API contract case study illustrates the value of sharing definitions between independent release paths. It documents generated API and client artefacts and checks for optional fields and enums. A stream registry solves a related coordination problem for serialized records. The example here uses message identities and versioned decoding so a maintainer can relate a delivered payload to the specific schema that produced it.
Where it goes wrong
Teams sometimes treat a successful registration as proof that every deployed consumer can handle the new records. Compatibility checks follow the configured mode and format. A policy that compares only with the last version may leave a much older consumer behind. Keep supported versions explicit and choose the registration policy to cover their overlap. Run the older consumer tests on the new records where its contribution matters.
Availability needs attention too. A producer may need registry access to resolve or register a schema under a new version. A consumer encountering an unfamiliar identifier may need its first lookup before decoding. Plan for caching, connection failures and clear diagnostics. Warm caches change what a load test observes, so exercise a process that starts with no cached schemas. Check the intended response to an unavailable registry and to an identifier that has no entry.
Review how writers select where to register. Applications that decode several event types from one stream might organize compatibility by event type. Another team might use one definition for the entire stream. Test what the serializer actually sends to the registry from each environment. A newly created registration group with a permissive default can let a change through without comparing it against the definitions consumers use. Reader and writer fixtures should check that they refer to the intended version history.
Finally, plan how definitions are retired. Old versions can remain important while records are retained or archived. A compatible change in a field definition also may have consequences for storage, application defaults or business rules. Keep schema history discoverable, test a replay near the oldest supported boundary, and require a documented decision before removing access to an identity used by existing records.
Further reading
- Confluent schema evolution and compatibility. Explains compatibility directions and policies for common formats.
- Introduction to Apicurio Registry. Documents an alternative registry’s artefacts and lifecycle.
- The Apache Avro specification. Describes writer and reader schema resolution and field defaults.