0
0
Kafkadevops~10 mins

Cross-datacenter replication in Kafka - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Cross-datacenter replication
Produce message in DC1
Message stored in DC1 Kafka cluster
Replication process reads message
Send message over network to DC2
Message stored in DC2 Kafka cluster
Consumer reads message from DC2
Messages produced in one data center are stored locally, then replicated over the network to another data center's Kafka cluster for consumption.
Execution Sample
Kafka
producer.send('topic', 'message1')
# Message stored in DC1
replicator.replicate('topic')
# Message sent to DC2
consumer.read('topic')
# Consumer reads replicated message
This code simulates producing a message in one data center, replicating it to another, and consuming it there.
Process Table
StepActionSource DCMessage StateReplication StatusConsumer Output
1Produce message 'message1'DC1Stored in DC1Not startedNone
2Start replicationDC1Stored in DC1Sending to DC2None
3Message received in DC2DC2Stored in DC2CompletedNone
4Consumer reads messageDC2Stored in DC2Completed'message1' read
5No new messagesDC1 & DC2No changeIdleNo output
💡 Replication completes after message is stored in DC2 and consumed.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
message_storage_DC1emptymessage1message1message1message1message1
message_storage_DC2emptyemptyemptymessage1message1message1
replication_statusidleidlesendingcompletedcompletedidle
consumer_outputnonenonenonenonemessage1 readnone
Key Moments - 3 Insights
Why does the message appear in DC2 only after replication starts?
Because the message is first stored locally in DC1 (see Step 1), and only after replication begins (Step 2) is it sent and stored in DC2 (Step 3).
Can the consumer read the message before replication completes?
No, the consumer in DC2 reads the message only after it is stored there (Step 4), so before replication completes, there is no message to read.
What happens if no new messages are produced?
Replication stays idle (Step 5), and consumers have no new messages to read, so no output occurs.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the replication status at Step 3?
ACompleted
BSending
CIdle
DNot started
💡 Hint
Check the 'Replication Status' column at Step 3 in the execution_table.
At which step does the consumer read the replicated message?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look at the 'Consumer Output' column in the execution_table to find when 'message1 read' appears.
If the producer sends a second message before replication starts, what changes in the variable_tracker?
Amessage_storage_DC2 will have two messages immediately
Bmessage_storage_DC1 will have two messages after Step 1
Creplication_status will be 'completed' at Step 1
Dconsumer_output will show both messages read at Step 2
💡 Hint
Check how message_storage_DC1 changes after Step 1 in variable_tracker.
Concept Snapshot
Cross-datacenter replication in Kafka:
- Messages produced in one data center (DC1) are stored locally.
- A replication process sends messages over the network to another data center (DC2).
- Messages are stored in DC2's Kafka cluster.
- Consumers in DC2 read replicated messages.
- Replication ensures data availability across locations.
Full Transcript
Cross-datacenter replication means sending Kafka messages from one data center to another. First, a message is produced and stored in the first data center's Kafka cluster. Then, a replication process reads this message and sends it over the network to the second data center. The message is stored there, and consumers in the second data center can read it. This process ensures that data is available in multiple locations for reliability and faster access. The execution table shows each step: producing, replicating, storing, and consuming. Variables track message storage and replication status. Key moments clarify when messages appear and can be read. The quiz tests understanding of replication status and message flow.