Apache Kafka Tutorial 0/111 lessons ~6 min read Lesson 79
CQRS
What is CQRS?
Course progress0%
Focus
9 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
What is CQRS? CQRS separates command writes from query reads.
Understanding the topic
What happens — CQRS:
- Define RPO/RTO and data sovereignty.
- Replicate selected topics cross-cluster.
- Plan failover and conflict handling.
- Capacity-plan for peak + replay.
| Term | Description |
|---|---|
| MirrorMaker 2 | Cluster-to-cluster replication. |
| RPO/RTO | Recovery point/time objectives. |
| Event sourcing | State from event replay. |
| CQRS | Separate write and read models. |
Visual explanation
Pipeline view:
text
Region A Kafka↓ replicate selected topicsRegion B Kafka↓local consumers + DR planTrade-off: latency, cost, consistency
Step-by-step explanation
- Design — Clusters, topics, mapping.
- Replicate — MM2 or cluster link.
- Failover — Test DR runbooks.
- Govern — Schema and ownership.
Informative example
Example:
bash
kafka-topics --bootstrap-server localhost:9092 --create --topic cqrs --partitions 6 --replication-factor 3kafka-console-producer --bootstrap-server localhost:9092 --topic cqrskafka-console-consumer --bootstrap-server localhost:9092 --topic cqrs --from-beginningkafka-consumer-groups --bootstrap-server localhost:9092 --describe --group cqrs-service
Execution workflow
1CQRS workflow
1 / 4Design
Clusters, topics, mapping.
Best practices
- Define RPO/RTO before choosing replication design.
- Replicate only topics with clear ownership and purpose.
- Document failover and failback procedures.
- Model event sourcing around immutable business facts.
Common mistakes
- Bi-directional replication without loop/conflict strategy.
- Event sourcing every table instead of meaningful domain events.
- Ignoring replay cost during capacity planning.
Summary
CQRS — Make trade-offs explicit: RPO/RTO, ordering, sovereignty, replay cost, schema governance, and operational ownership.
Ready to mark this lesson complete?Track your journey across the entire course.