Level Up Your Kafka Skills in Just 5 Days | Join Season of Streaming On-Demand
A deep dive into achieving excellent command query segregation with ksqlDB and the lessons learnt!
CQRS is a design pattern where the command and query execution could use different data models and databases. Typically any changes from command execution get published to Kafka and updates the query database.
However there are many use cases where command execution needs some of the query execution data. We initially solved this problem by calling the query APIs from the command execution side. However this caused strong dependency between systems that were supposed to work independently.
We solved this problem by publishing the query model changes to Kafka and using ksqlDB to create state stores to store this data locally in command services. Although the data is distributed between instances of ksqlDB, a command service instance can fetch any data from its local instance. We have even created new aggregations from query models that are better suited for command flow.