blog by OSO

Building Bulletproof Disaster Recovery for Apache Kafka: A Field-Tested Architecture

Sion Smith 14 May 2025
Disaster Recovery for Apache Kafka

Picture this: It’s 3 AM, and your phone is buzzing incessantly. The on-call engineer’s worst nightmare has materialised—your primary Kafka cluster serving millions of transactions has gone down. As you fumble for your laptop, the war room is already assembling virtually. This scenario isn’t hypothetical; it’s a reality the OSO engineering team has encountered while operating Kafka clusters processing over 300 million daily transactions and 60 million messages per second.

The question isn’t whether disasters will strike your Kafka infrastructure—it’s when. Traditional disaster recovery approaches that work for monolithic applications fall woefully short when applied to distributed streaming platforms like Apache Kafka. Through years of battle-testing DR strategies at scale, OSO engineers have developed a comprehensive framework that goes beyond theoretical best practices to deliver practical, production-proven solutions.

Understanding Kafka Failure Modes

Kafka’s distributed nature means failures manifest differently than in traditional systems. Whilst node-level failures are common and generally manageable through Kafka’s built-in replication, cluster-level disasters pose existential threats to your streaming infrastructure.

Not all failures are created equal. OSO’s engineering team categorises Kafka failures into distinct threat levels based on their impact and recovery complexity. Node-level failures, such as individual broker crashes, disk failures, or JVM out-of-memory errors, rarely escalate into disasters thanks to Kafka’s inherent resilience. However, cluster-level disasters present a different challenge entirely.

The most insidious failures occur when you lose multiple brokers simultaneously. Imagine a scenario where your replication factor is three, and through an unfortunate series of events—perhaps a botched rolling upgrade or a rack-level power failure—you lose three brokers hosting the same partition replicas. Your data becomes inaccessible, and your producers start timing out. Network partitions causing split-brain scenarios can be equally devastating, as can cascading failures triggered by seemingly minor misconfigurations.

Beyond technical failures lie environmental disasters that no amount of clever engineering can prevent. Floods, earthquakes, fires, and extended power grid failures demand geographic distribution of your Kafka infrastructure—a complexity that traditional DR planning often overlooks. OSO engineers have witnessed firsthand how a lightning strike can take down an entire datacenter’s power infrastructure, making geographic redundancy not just advisable but essential.

The Economics of Disaster Recovery

One of the most challenging aspects of implementing Kafka DR isn’t technical—it’s financial. OSO engineers have developed a pragmatic framework for justifying DR investments that resonates with both technical and business stakeholders.

When evaluating DR necessity, the fundamental equation appears simple: compare the cost of an outage against the cost of implementing DR. However, calculating the true cost of downtime extends far beyond lost revenue. Direct costs include lost transaction revenue (often measured in millions for financial services), SLA penalties, regulatory fines, emergency response team overtime, and infrastructure replacement costs. Yet these pale in comparison to the hidden costs that materialise over time.

Customer attrition represents perhaps the most significant hidden cost. During a major outage at a financial services client, OSO engineers observed users not just temporarily switching to competitors but permanently uninstalling the application. Brand reputation damage compounds this effect, making future customer acquisition exponentially more expensive. Market share erosion to competitors can take years to recover, if recovery is even possible.

For organisations in regulated industries—particularly financial services where OSO operates—DR isn’t optional. Regulatory frameworks mandate maximum allowable downtime (often less than four hours), specific data locality requirements, comprehensive audit trails for failover procedures, and regular DR testing certification. Non-compliance risks penalties that dwarf the cost of implementing proper DR.

Not every Kafka use case warrants full DR implementation. OSO engineers classify applications into three tiers: mission-critical applications like payment processing systems, fraud detection pipelines, and real-time risk assessment require mandatory DR. Business-critical applications such as customer analytics pipelines and recommendation engines benefit from recommended DR. Non-critical applications like development environments and internal dashboards may operate with optional DR, depending on available resources.

Synchronous vs Asynchronous Replication Trade-offs

The choice between synchronous and asynchronous replication fundamentally shapes your DR architecture. OSO’s production experience reveals nuanced trade-offs that theoretical discussions often miss.

In synchronous replication, Kafka brokers span multiple datacenters, with producers receiving acknowledgments only after data replicates across all locations. Consider a practical example

Producer (Mumbai DC) → Kafka Cluster
                       ├── Broker 1-3 (Mumbai DC)
                       └── Broker 4-6 (Delhi DC)
                       
acks=all ensures writes to both DCs before confirmation

In this architecture, a producer in Mumbai writes to a Kafka cluster with brokers distributed between Mumbai and Delhi datacenters. With acknowledgment settings configured for maximum durability, the producer waits for confirmation from brokers in both locations before considering the write successful.

Real-world performance metrics tell a sobering story. Baseline latency in a single datacenter typically ranges from one to two milliseconds. Introduce synchronous replication across datacenters separated by 100 kilometres, and latency jumps to 10-20 milliseconds. Throughput suffers proportionally, with reductions of 30-50% compared to single datacenter deployments.

OSO’s production data reveals what we call the “100-kilometre rule”: synchronous replication becomes impractical beyond this distance. Network physics, not infrastructure quality, drives this limitation. The speed of light imposes fundamental constraints that no amount of network optimisation can overcome.

Synchronous replication makes sense in specific scenarios: when transaction rates remain below 10,000 per second, when applications can tolerate latencies exceeding 20 milliseconds, when strong consistency requirements exist (such as financial ledgers), and when datacenters are geographically proximate.

Asynchronous replication, implemented through MirrorMaker, decouples source and target clusters, enabling global distribution. Here’s how OSO implements this pattern:

Mumbai Kafka Cluster → MirrorMaker → Singapore Kafka Cluster
(Primary DC)          (Replicator)   (DR DC)

Replication lag: 100ms - 4 seconds depending on load

In OSO’s production environment, MirrorMaker replicates data from a Mumbai Kafka cluster to Singapore with steady-state lag between two and four seconds. This setup handles peak throughput of 6.5 million messages per second, transferring 700 megabytes of data per second.

Storage economics present another consideration:

 

Single DC (RF=3): 3 copies of data
Async DR (RF=3 both DCs): 6 copies of data
Storage cost multiplier: 2x

This doubling of storage requirements directly impacts infrastructure costs and must be factored into DR planning.

Active-Active vs Active-Passive Patterns

The choice between active-active and active-passive DR patterns significantly impacts operational complexity and resource utilisation. OSO’s preferred pattern for critical systems, active-active deployment enables both datacenters to handle production traffic simultaneously.

In a typical active-active implementation, OSO deploys identical infrastructure across datacenters:

ComponentMumbai DCBangalore DC
Kafka Cluster30 nodes30 nodes
MirrorMaker3 nodes3 nodes
Producers / ConsumersPresentPresent
Topicst1, t2, blr.t1t1, t2, mum.t1

Each location runs three MirrorMaker nodes for cross-datacenter replication. Producers and consumers operate in both locations, processing region-local traffic while maintaining global consistency through replication.

Topic naming strategies prove crucial for successful active-active deployments. OSO employs two primary approaches:

1. Prefixed Replication:

Mumbai: orders → Bangalore: mum.orders
Bangalore: orders → Mumbai: blr.orders

This approach provides clear data lineage and prevents replication loops but requires consumers to handle multiple topic names.

2. Identity Replication:

Mumbai: orders ↔ Bangalore: orders

This maintains consistent topic names across datacenters, simplifying consumer logic but introducing loop prevention challenges.

To prevent replication loops with identity replication, OSO engineers developed a header-based filtering mechanism:

// Producer adds origin header
headers.add("x-origin-dc", "mumbai");

// MirrorMaker checks before replication
if (record.headers().lastHeader("x-origin-dc").value().equals(targetDC)) {
    // Skip replication to prevent loop
    return;
}

This elegant solution allows bidirectional replication whilst preventing infinite loops, enabling true active-active architectures.

Active-passive patterns reduce operational complexity at the cost of resource efficiency. The passive datacenter remains idle during normal operations, activating only during primary datacenter failures. This approach suits organisations with limited operational expertise, stringent recovery time objectives under five minutes, applications requiring session affinity, or regulatory data residency requirements.

Practical Implementation Insights

After years of operating Kafka DR at scale, OSO engineers have distilled essential practices that separate theoretical DR from production-ready implementations. Infrastructure sizing requires careful calculation based on partition counts and available resources. OSO uses this formula:

MirrorMaker Nodes Required = Total Partitions / Cores per Node
Minimum Cores = 1.5x Partition Count (headroom for rebalancing)

Example calculation:
- Source partitions: 1,000
- Cores per MirrorMaker node: 40
- Minimum nodes: 1,000 / 40 = 25
- Recommended nodes: 38 (50% headroom)

Configuration tuning dramatically impacts replication performance. OSO’s production MirrorMaker deployments use these optimised settings:

# Performance optimization
fetch.min.bytes=100000
batch.size=100000
producer.linger.ms=100
compression.type=lz4

# Reliability settings
acks=1
retries=3
max.in.flight.requests.per.connection=5

# Task distribution
tasks.max=<total_partition_count>

These settings balance throughput, latency, and reliability based on extensive production testing.

Monitoring proves critical for maintaining DR health. OSO tracks four essential metric categories:

1. Replication Lag (P50, P95, P99)
   - Alert threshold: > 30 seconds
   - Expected values: 2-4 seconds steady state
   
2. Message Throughput Differential
   - Source vs Target message rates
   - Alert: > 10% divergence
   - Example: 6.5M msg/sec source, 6.3M target = investigate
   
3. Consumer Group Offset Translation
   - Lag between checkpointing
   - Alert: > checkpoint interval
   - Critical for accurate failover
   
4. Network Utilisation
   - Inter-DC bandwidth usage
   - Alert: > 80% capacity
   - Example: 700 MB/sec on 1 Gbps link = 56% utilisation

These metrics provide early warning of replication issues before they impact recovery capabilities.

Failover procedures demand meticulous planning and regular practice. OSO’s battle-tested sequence:

1. Verify Primary Failure

# Check cluster health
kafka-cluster-health --cluster primary-mumbai
# Verify network connectivity
ping -c 10 primary-kafka-broker-1.mumbai.internal
# Confirm monitoring accuracy
check-prometheus-alerts --cluster primary-mumbai

2. Initiate Producer Failover

# Update producer configs
sed -i 's/kafka.mumbai.internal/kafka.bangalore.internal/g' producer.properties
# Restart producer applications
systemctl restart kafka-producer-service

3. Execute Consumer Migration

# Export current offsets
kafka-consumer-groups --bootstrap-server mumbai:9092 \
  --group myapp --describe > current-offsets.json

# Translate offsets for DR cluster  
kafka-consumer-offset-translator \
  --source-cluster mumbai \
  --target-cluster bangalore \
  --input current-offsets.json \
  --output translated-offsets.json

# Apply translated offsets
kafka-consumer-groups --bootstrap-server bangalore:9092 \
  --group myapp --reset-offsets --from-file translated-offsets.json

4. Validate Data Integrity

# Compare message counts
kafka-run-class kafka.tools.GetOffsetShell \
  --broker-list bangalore:9092 \
  --topic orders --time -1

# Check for duplicates
kafka-console-consumer --bootstrap-server bangalore:9092 \
  --topic orders --from-beginning \
  | sort | uniq -d | wc -l

This systematic approach minimises data loss and ensures rapid recovery during actual disasters.

Testing methodology determines DR readiness. OSO conducts monthly tests of single broker failures, network partition scenarios, and rolling upgrade procedures. Quarterly tests escalate to full datacenter failovers, multi-region failback procedures, and cross-team coordination exercises. Annual unannounced failover drills test the entire organisation’s readiness, including executive stakeholder participation.

Conclusion

Building bulletproof disaster recovery for Apache Kafka requires more than understanding the technology—it demands a holistic approach combining architectural patterns, economic analysis, and operational excellence. Through years of operating Kafka at massive scale, OSO engineers have learned that the best DR strategy is one that’s regularly tested, economically justified, and architecturally sound.

The journey from reactive firefighting to proactive resilience isn’t simple, but it’s essential. Start by assessing your current Kafka deployment against the patterns outlined here. Identify gaps in your DR readiness. Most importantly, remember that disaster recovery isn’t a destination—it’s an ongoing process of preparation, testing, and refinement.

As streaming architectures become increasingly critical to business operations, the question isn’t whether you need Kafka DR—it’s whether you can afford to operate without it. The next time your phone buzzes at 3 AM, make sure you’re reaching for a well-rehearsed runbook, not scrambling for solutions.

Ready to assess your Kafka DR readiness? Start with a simple question: If your primary Kafka cluster disappeared right now, how long would recovery take, and what would be the impact? If the answer makes you uncomfortable, it’s time to act.

Need support with Kafka DR

Have a conversation with one of our experts to discover how we can work with you to plan and test your Apache Kafka disaster recovery playbook

CONTACT US
OSO
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.