Designing Resilient Infrastructure to Prevent Order Data Loss During Kafka Failures

CK CK 3788 
Created at  
156 0 0

To prevent order data loss during Kafka failures from an infrastructure design perspective, a multi-layered resilience strategy must be implemented. First, Kafka brokers should be deployed across multiple availability zones with a replication factor of three and a min.insync.replicas configuration of two, combined with producer settings configured to acks=all and idempotence enabled to guarantee zero-loss ingestion. Additionally, a transactional outbox pattern or a fallback storage mechanism, such as writing failed payloads to a highly available database or an alternative queuing service like Amazon SQS, must be established at the gateway level to buffer order data if the Kafka cluster becomes completely unreachable. Finally, active-passive cross-region replication and automated failover monitoring should be integrated to ensure continuous data availability and disaster recovery during catastrophic cluster-wide outages.

Designing Resilient Infrastructure to Prevent Order Data Loss During Kafka Failures

 

1. Kafka Cluster High Availability (HA) & Configuration

To prevent data loss (zero-data-loss architecture) at the infrastructure level, the Kafka cluster itself must be configured for high durability and fault tolerance across physical boundaries.

Designing Resilient Infrastructure to Prevent Order Data Loss During Kafka Failures

Multi-AZ (Availability Zone) Deployment

  • Broker Distribution: Deploy Kafka brokers across at least three distinct Availability Zones (AZs) within a cloud region.
  • Rack Awareness: Configure broker.rack to map to the respective AZ. Kafka will automatically distribute partition replicas across different physical racks (AZs), ensuring that even if an entire AZ goes down, the data remains accessible.

 

Topic & Broker Configurations for Durability

  • Replication Factor (RF): Set the replication factor for the order topic to at least 3 (replication.factor=3).
  • Minimum In-Sync Replicas (min.insync.replicas): Set this value to 2. This ensures that a write is only considered successful if at least two replicas (the leader and one follower) have acknowledged the write.
  • Unclean Leader Election: Disable unclean leader election (unclean.leader.election.enable=false). This prevents an out-of-sync follower from becoming the leader if the leader fails, avoiding data loss at the cost of temporary unavailability for that partition.

 

 

2. Producer-Side Reliability & Fallback Architecture

If Kafka suffers a complete outage, the producer (the Order Service) must have mechanisms to prevent order data from being lost in memory.

Designing Resilient Infrastructure to Prevent Order Data Loss During Kafka Failures

Robust Producer Configurations

  • Acks Configuration: Set acks=all (or acks=-1). The producer will wait for the full set of in-sync replicas to acknowledge the record.
  • Idempotent Producer: Enable enable.idempotence=true. This assigns a unique sequence number to each message, preventing duplicates in case of retries due to network timeouts.
  • Retries and Timeouts: Configure high retry limits (retries=MAX_INT) and appropriate timeouts (delivery.timeout.ms) to allow the producer to recover from transient Kafka network blips.

 

Transactional Outbox Pattern (Local Database Backup)

  • Design: Instead of sending the order directly to Kafka, the Order Service saves both the "Order Record" and an "Outbox Event Record" into its local Relational Database (RDBMS) within a single, ACID-compliant database transaction.
  • Message Relay (CDC): A separate worker process (e.g., Debezium, Kafka Connect, or a custom polling publisher) reads the Outbox table and publishes the messages to Kafka.
  • Kafka Down Scenario: If Kafka is down, the database transaction still succeeds. The orders are safely stored in the RDBMS. Once Kafka recovers, the publisher resumes sending messages from the Outbox table.

 

Temporary Failover Buffer (Secondary Queue)

  • Design: Implement an in-memory or secondary storage fallback mechanism in the producer application.
  • Implementation: If the Kafka producer fails to send a message after retries, the application routes the message to a lightweight, highly available secondary storage such as AWS SQS, Redis, or a local RocksDB/disk file.
  • Recovery: A background thread monitors Kafka's health and flushes the fallback storage back into Kafka once the cluster is healthy.

 

 

3. Consumer-Side Data Consistency

Preventing data loss on the consumer side means ensuring that messages are not marked as "processed" if the consumer crashes mid-transaction.

Designing Resilient Infrastructure to Prevent Order Data Loss During Kafka Failures

Manual Offset Management

  • Disable Auto-Commit: Set enable.auto.commit=false.
  • Manual Commit Sync/Async: Commit the offsets only after the consumer has successfully processed the order data (e.g., writing to the database, invoking the payment gateway). This ensures "at-least-once" delivery.

 

Idempotent Consumers

  • Because manual commits can lead to duplicate message processing (e.g., if a consumer crashes after processing but before committing), the downstream services must be idempotent.
  • Implementation: Use the order_id as a unique key in the target database to prevent processing the same order multiple times.

 

Dead Letter Queue (DLQ) & Error Handling

  • If a consumer encounters a non-recoverable error (e.g., bad data format), it should send the message to a Dead Letter Queue (DLQ) rather than discarding it or halting the partition processing.
  • This allows operators to inspect and re-drive failed order messages later.

 

 

4. Disaster Recovery (DR) & Monitoring Infrastructure

For catastrophic Kafka failures (e.g., regional outages), a multi-cluster disaster recovery plan is required.

Designing Resilient Infrastructure to Prevent Order Data Loss During Kafka Failures

Multi-Region Replication (Active-Passive / Active-Active)

  • MirrorMaker 2 / Confluent Cluster Linking: Continuously replicate the order topic from the primary region's Kafka cluster to a secondary region's Kafka cluster in near real-time.
  • Global Failover: If the primary Kafka cluster is unrecoverable, route the Producer/Consumer traffic to the secondary Kafka cluster.

 

Backup to Cold Storage (Data Lake archiving)

  • Use Kafka Connect (S3 Sink Connector) to stream all order messages from Kafka to highly durable object storage (e.g., AWS S3, Google Cloud Storage) in real-time.
  • In a worst-case scenario where the Kafka cluster is completely lost without backup, the historical order data can be rehydrated from the object storage.

 

Observability and Alerting

  • Consumer Lag Monitoring: Monitor consumer lag using tools like Prometheus, Grafana, or Burrow. An increasing lag indicates consumer issues.
  • Under-Replicated Partitions (URP): Set up immediate alerts for UnderReplicatedPartitions > 0. This is the first indicator of broker failure or replication issues.
  • Producer Error Rates: Monitor producer retry rates and failed send rates to trigger auto-scaling or fallback routing.
Tags Amazon SQS Apache Kafka CDC Relay DR Data Durability Data Loss Prevention Disaster Recovery High Availability Infrastructure Design Kafka Failure Recovery Kafka Fault Tolerance Message Queue Message Relay Multi-AZ Replication Factor System Architecture 쇼핑몰 Facebook X
Comments 0
Similar posts
  1. Real-Time Inventory & WMS System Design
    244
  2. Enterprise-Scale 100k+ TPS Order Tracking System Architecture
    204
  3. Is AWS API Gateway Disaster-Proof? DR, Benefits, and Multi-AZ Architecture Explained
    143
  4. Architecting for Resilience: AWS High Availability Components Including API Gateway
    139
  5. Enterprise-Scale 100k+ TPS Order Processing System Architecture
    178
  6. Architecting Dynamic Scale-Out and Scale-In with Docker Containers
    134
  7. How to Design Redis Caching in Infrastructure Architecture
    158
  8. Architecture Design - Database Partitioning vs. Sharding
    153
  9. Stateful Databases: A Deep Dive with Cassandra & TiDB
    189
  10. Multi-AZ Kafka Architecture
    148
  11. System Design: High-Traffic Time-Deal Promotion System
    175
  12. Fault Tolerance & High Availability based on multi Availability zones in AWS
    10,809
  13. Synchronous online gaming architecutre in AWS - Highly Available, Scalable & Elastic to support Millions of Players
    10,417
  14. Time series processing architecture in AWS
    10,559
  15. Web Application Hosting provides the reliable, scalable, secure, and high-performance infrastructure
    10,615
  16. Cadence Programming Model - A Distributed, Fault-Tolerant, Stateful Workflow Orchestration Framework
    294
  17. Optimize the performance of a search results page that experiences high traffic
    143
  18. Temporal Programming Model - Robust, Long-Running, Fault-Tolerant Applications as WorkFlows
    358
  19. Apache Kafka Explained: Powering Netflix, Building with PHP
    492
  20. Java Kafka on CentOS 7: Install, Configure, & Run with Examples
    425
  21. Milvus & FAISS: Decoding Their ML Synergy
    279
  22. AWS Ad Exchange Disaster Recovery: Active-Active, Active-Passive, and Cell Strategies - Disaster Recovery
    1,358
  23. Media sharing service architecture in AWS
    10,366
  24. Improving nested_fields data access experience with a persistent user-defined function (aka UDF) in Google Big Query
    1,500
  25. Creating a serverless Apache Kafka publisher using AWS Lambda
    563
  26. Apache Kafka - a distributed, fault-tolerant, high-throughput streaming platform
    615
  27. Amagi CLOUDPORT Architecture based on AWS for FAST for channel playout on AWS
    1,318
  28. Real-time Data Streaming Solutions - Kafka vs. Kinesis Comparison
    853
  29. Architectural Diagram Gallery for Amazon MSK
    502
  30. Building my own ChatGPT based on SageMaker and Milvus that is specialized to Shopping Mall
    269
  1. The Blueprint of Success: Why System Design and Architecture Matter?
    400
  2. Software Design Patterns Cheat Sheet
    3,323
  3. Various naming for the Software Architecture - I can't find Component-based Architecture, Functional Architecture
    3,334
  4. Builder Pattern - offering pre-defined Interfaces to set Individual Parts
    1,432
  5. Abstract Factory Pattern - Commonly Used for UI Themes or Objects
    1,469
  6. Software Design Patterns
    1,437
  7. Observer Pattern
    2,395
  8. Factory Method Pattern allows overriding to return different concrete object types
    1,528
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    42
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    36
  3. How do I create animated background for Google Meet?
    20,970
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    251
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    94
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    157
  7. Array of arguments passed to script in PHP
    90
  8. Invalid Auction Storms in Ad Tech
    98
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    202
  10. The Two Clocks of Ad Server Architecture
    70
  11. Frequency Cap Architecture Overview
    515
  12. Collecting Proof-of-Play from 100,000 Screens
    146
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    288
  14. What is RedisVL?
    109
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    231
  16. TPU & GPU Cluster Management Tools
    245
  17. The Concept of Scaffolding in AI Agents
    234
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    583
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    259
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    339
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    202
  22. Machine Learning: Training vs. Ranking
    222
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    222
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    195
  25. Designing a Data Curation System Around a Vector Database
    221
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    256
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    656
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    196
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    219
  30. Understanding Data Lineage
    262