Protocol Buffers (Protobuf) defines structured event data in .proto schemas for serialization. A schema declares messages and fields; each field carries a number used to identify it in the binary message format. In proto3, fields are optional and receive type-based defaults: numeric fields default to 0, strings to empty strings, and repeated fields to empty lists. section 3.2.5
Define an event message
Model an Avenger event as a message with numbered fields. The package and Java options guide generated Java types; `repeated` represents a list. Keep field numbers stable because they identify fields in serialized messages. `syntax = "proto3";` `package bbejeck.chapter_3.proto;` `option java_multiple_files = true;` `message Avenger { string name = 1; string real_name = 2; repeated string movies = 3; }` section 3.2.5
Listing 3.3 Protobuf schema for Avengers
syntax = "proto3"; #1
package bbejeck.chapter_3.proto; #2
option java_multiple_files = true; #3
message Avenger { #4
string name = 1; #5
string real_name = 2;
repeated string movies = 3; #6
}
Inspect a compact proto3 message that contrasts Protobuf’s code-like syntax and numbered fields with JSON-based schema formats. section 3.2.5
Generate domain objects from Protobuf schemas rather than hand-writing repetitive model classes. Generated code keeps applications aligned with schemas stored in Git: after a schema change, teammates can pull the update and regenerate the corresponding types. Gradle plugins can support code generation and Schema Registry work in the build cycle. section 3.2.6 section 3.9
For Kafka records, configure `KafkaProtobufSerializer` and `KafkaProtobufDeserializer` with the Schema Registry URL. Set `java_outer_classname` and `java_multiple_files` when using Schema Registry, particularly with `RecordNameStrategy`. Configure the deserializer with the generated value class to receive that specific type; without it, it returns `DynamicRecord`. Schema-aware serializers can register imported Protobuf schemas automatically, unless automatic registration is disabled. section 3.7.2
Split reused message definitions into separate proto files and import them. A Protobuf schema reference must point to another Protobuf schema, not Avro or JSON Schema. In a topic carrying several event types, a generated wrapper with a `oneof` field lets consumers identify the active event through generated `hasXXX` methods or the `TypeCase` enum. section 3.5 section 4.6.2
ksqlDB can use Protobuf through Schema Registry when defining streams and tables. With a Protobuf value schema, it can infer value column names and types, though a basic Kafka key still requires an explicit primary-key definition. Declare columns when selecting only a subset; persistent queries inherit their source format unless overridden. section 11.5









