liveBook · Manning

Topic record name strategy

As explained in Kafka Streams in Action, Second Edition

TopicRecordNameStrategy is a schema subject naming strategy that derives subjects from both the topic name and the record schema, isolating schemas by topic.

TopicRecordNameStrategy names a schema subject from both the Kafka topic and the record schema. It permits multiple event types in one topic while isolating each record type’s schema within that topic. section 3.3.3 section 3.3

Use this strategy when you need both kinds of flexibility:

  • Place multiple logically related record types on one topic. section 3.3.3
  • Use different schema versions for the same record type on different topics. section 3.3.3 section 3.6
  • Accept that the strategy does not restrict a topic to a fixed set of record types; schema references are the alternative when that policy is required. section 3.3.3 section 3.6

Separate legacy and current purchase schemas

An interactions topic can contain the current CustomerPurchaseEvent schema alongside other customer events, while a legacy purchases topic can contain an older CustomerPurchaseEvent schema with different fields. TopicRecordNameStrategy keeps compatibility checks scoped to each topic. Configure the producer and consumer with the strategy for values; configure keys only when keys use schemas, and key and value strategies do not need to match. section 3.3.3 section 3.3

Java configuration

Set the serializer and deserializer subject strategies explicitly: producerConfig.put(KafkaAvroSerializerConfig.VALUE_SUBJECT_NAME_STRATEGY, TopicRecordNameStrategy.class); consumerConfig.put(KafkaAvroDeserializerConfig.VALUE_SUBJECT_NAME_STRATEGY, TopicRecordNameStrategy.class);. Apply the corresponding key settings only when serialized keys use schemas. section 3.3.3 section 3.3.3

Figure 3.8 TopicRecordNameStrategy allows different schemas for the same domain object across different topics.
figure

Compare the same record type across topics: TopicRecordNameStrategy allows topic-A and topic-B to register different schemas for that type. section 3.3.3

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains naming scope, trade-offs, and producer-consumer configuration but stops short of implementation internals.
Examples
Uses CustomerPurchaseEvent across current and legacy topics plus Java producer and consumer configuration.
What it assumes
Assumes Kafka topics and schemas, while introducing subject naming and its compatibility-check scope.
What you can do after
Operate/configure producers and consumers to isolate per-topic record schemas while supporting multiple event types.
How it connects
Contrasts TopicNameStrategy and RecordNameStrategy, and connects to schema evolution, compatibility modes, and schema references.

Also explained in

Compare how 2 books explain topic record 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.