liveBook · Manning

Validation

As explained in Kafka for Architects

Message validation is the checking of a message's structure and content against required validity rules before it is accepted or processed.

In an event-driven service, a malformed event can reach consumers even when it cannot be processed. Message validation checks whether a message conforms to an expected schema before the producer sends it. Kafka brokers treat messages as raw bytes: they do not inspect their contents or enforce a format. section 6.4.1 section 5.1.1

With Schema Registry, a producer uses a registered schema to serialize and validate a message. A nonconforming message raises a producer-side exception and is not sent. The message carries a schema ID so a consumer can obtain the appropriate schema version and deserialize it. This protects the path only when clients are configured correctly: a misconfigured producer can still write invalid data to a topic. section 6.4.1

Figure 6.13 How a message, containing a schema, is serialized. Consumers decode a schema ID and use it to retrieve the schema from the Schema Registry, which they then use to deserialize the data.
A black and white rectangular object with text

Description automatically generated

The schema-ID flow shows how a consumer finds the schema needed to deserialize a message; the broker does not perform this check. section 6.4.1

A message that stops a consumer

A producer sends a message missing a required field. The broker accepts it, but a consumer cannot deserialize it. If the exception is unhandled and the offset remains uncommitted, restarting the consumer reads the same message and repeats the failure. Consumers should be tested against wrong-format messages and have a policy for handling them—for example, routing them to a monitored dead-letter topic. Operators can identify the offending offset from logs or browsing tools and reset a consumer offset with kafka-consumer-groups.sh when necessary. section 6.5.1

Validation rules are also a governance choice. Loosely defined schemas and optional fields can support early experimentation, but growing dependence on shared events calls for stronger schema validation and version control. Client-side validation reduces mistakes; it is not a broker-enforced guarantee. section 6.2.7 section 6.4.1

How Kafka for Architects covers it

How deep it goes
Explains the client-side validation flow, broker limitation, and consumer failure paths without a low-level implementation walkthrough.
Examples
Uses schema-ID retrieval and a missing-field message that repeatedly fails deserialization until the consumer handles or bypasses it.
What it assumes
Builds on Kafka producer and consumer concepts while explaining why validation occurs in clients rather than brokers.
What you can do after
Diagnose/debug with it when invalid messages disrupt consumers, and establish handling policies for dead-letter topics and offset recovery.
How it connects
Connects validation to Schema Registry, serialization, deserialization, data contracts, dead-letter topics, and consumer offsets.

Also explained in

Compare how 30 books explain validation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka for Architects. The section links point to the parts of the book it draws on.