top of page
Writer's pictureKieran Mangan

Using Record Name Strategy with Kafka 'Command' Topics

Command topics are a key part of CQRS architecture that helps us clearly separate the initiation of an operation (e.g. make payment, create user), from the result of that operation (which would be an 'Event' topic).


Note that 'Command' and 'Event' topics are not a Kafka concept, rather they are labels you can choose to give types of topics to help architectural design and clarity.


Command Topics:

  • Usually short lived

  • Can contain multiple types of related command (e.g. Create User, Update User)

  • Named with the suffix '-command'

Event Topics:

  • Usually long lived

  • Contain a single schema'd, and often compacted type

  • Named with the suffix '-event'

How can we have more than one type of message on a command topic?


When using Avro with Kafka, the subject naming strategy allows us to tell Avro how to validate records in a topic. For most topics, we use a TopicNameStrategy, which means the record in the topic is associated with the topic name. This effectively limits us to one schema per topic. For 'command' topics, we use RecordNameStrategy, which associates the record in the topic with its name. This means we can have multiple commands on a single topic.

So for example, a user-commands topic can have the commands CreateUser and UpdateUser on the same topic.




2 views0 comments

Recent Posts

See All

Kommentare


bottom of page