0
0
Kafkadevops~5 mins

Active-passive vs active-active in Kafka - CLI Comparison

Choose your learning style9 modes available
Introduction
When running systems that need to be always available, you can set them up so only one server works at a time (active-passive) or so multiple servers work together at the same time (active-active). This helps keep your data safe and your service running without interruptions.
When you want a simple backup server that takes over only if the main server fails.
When you need to balance the load by having multiple servers handle requests simultaneously.
When you want to avoid downtime during maintenance by having all servers active.
When you want to reduce the risk of data loss by replicating data across active servers.
When you want to improve performance by distributing work across several servers.
Commands
Create a Kafka topic with 3 partitions and replication factor 2 to support active-active setup with data replicated across brokers.
Terminal
kafka-topics --create --topic example-topic --partitions 3 --replication-factor 2 --bootstrap-server localhost:9092
Expected OutputExpected
Created topic example-topic.
--partitions - Number of partitions to split the topic into for parallel processing.
--replication-factor - Number of copies of each partition for fault tolerance.
--bootstrap-server - Kafka server address to connect to.
Check the details of the topic to verify partitions and replication, confirming active-active setup.
Terminal
kafka-topics --describe --topic example-topic --bootstrap-server localhost:9092
Expected OutputExpected
Topic: example-topic PartitionCount: 3 ReplicationFactor: 2 Configs: Topic: example-topic Partition: 0 Leader: 1 Replicas: 1,2 Isr: 1,2 Topic: example-topic Partition: 1 Leader: 2 Replicas: 2,3 Isr: 2,3 Topic: example-topic Partition: 2 Leader: 3 Replicas: 3,1 Isr: 3,1
--describe - Show detailed information about the topic.
Start a producer to send messages to the topic, which will be handled by active brokers in active-active mode.
Terminal
kafka-console-producer --topic example-topic --bootstrap-server localhost:9092
Expected OutputExpected
No output (command runs silently)
--topic - Specify the topic to send messages to.
--bootstrap-server - Kafka server address to connect to.
Start a consumer to read all messages from the topic, showing how active-active setup allows continuous data flow.
Terminal
kafka-console-consumer --topic example-topic --bootstrap-server localhost:9092 --from-beginning
Expected OutputExpected
No output (command runs silently)
--from-beginning - Read messages from the start of the topic.
--topic - Specify the topic to read messages from.
--bootstrap-server - Kafka server address to connect to.
Key Concept

If you remember nothing else, remember: active-passive means one server works while the other waits, active-active means multiple servers work together at the same time for better availability and performance.

Common Mistakes
Setting replication-factor to 1 when expecting active-active behavior.
Without replication, data is not copied to other brokers, so failover and load sharing won't work.
Set replication-factor to at least 2 to enable data replication across brokers.
Using only one partition for a topic in active-active setup.
One partition limits parallelism and load distribution, reducing benefits of active-active.
Create multiple partitions to allow parallel processing across brokers.
Not verifying topic details after creation.
You might miss misconfigurations that prevent active-active operation.
Always describe the topic to confirm partitions and replication settings.
Summary
Create Kafka topics with multiple partitions and replication to enable active-active setups.
Use kafka-topics --describe to verify topic configuration.
Producers and consumers work with all active brokers to share load and provide fault tolerance.