liveBook · Manning

Topic name strategy

As explained in Kafka Streams in Action, Second Edition

TopicNameStrategy is a Schema Registry subject naming strategy that derives separate key and value subject names from a Kafka topic name.

TopicNameStrategy is Schema Registry’s default subject naming strategy. It derives separate subjects from the Kafka topic name: <topic>-key for keys and <topic>-value for values. section 3.3.1

Because the subject is scoped to a topic, each topic supports one data type per key or value subject. This fits topics named for the event type they contain. section 3.3.1

Use the strategy when:

  • Keep one record type on a topic and let Schema Registry enforce compatible changes within that topic. section 3.3.1 section 3.3
  • Reuse the same record type on different topics while allowing each topic to register a different schema. section 3.3.1
  • Choose another strategy when closely related event types must share one topic without a fixed single type. section 3.3.1

Subjects for an inventory topic

For a topic named inventory-events, register the value schema under inventory-events-value and a key schema under inventory-events-key. No additional strategy configuration is required because TopicNameStrategy is the default. To place PlaneEvent, TruckEvent, and DeliveryEvent together while retaining an allowed set of types, use an Avro union registered under the topic’s value subject with schema references. section 3.3.1 section 3.6

Figure 3.6 TopicNameStrategy enforces having the same type of domain object represented by the registered schema for the value and or the key.
figure

Use the figure to compare how topic-scoped subjects constrain the domain-object type represented by a key or value schema. section 3.3.1

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains subject naming, topic-level type constraints, cross-topic schema independence, and schema-reference composition, but defers client implementation details.
Examples
Uses key/value subject names, event-type-named topics, and a retailer’s PlaneEvent, TruckEvent, and DeliveryEvent union.
What it assumes
Assumes Kafka topics and Schema Registry subjects while establishing key-versus-value schemas and compatibility scope.
What you can do after
Apply it via Schema Registry by deriving <topic>-key and <topic>-value subjects and choosing references when one topic needs related event types.
How it connects
Connects Schema Registry subjects, schema compatibility, schema references, Avro unions, RecordNameStrategy, and TopicRecordNameStrategy.

Also explained in

Compare how 2 books explain topic name strategy →

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.