Design a Kafka-based messaging system for a global e-commerce platform that handles millions of transactions per minute. Explain how you would ensure data consistency, fault tolerance, and high availability across geographically distributed data centers.

Instruction: Outline the architecture of your system, including the choice of Kafka configuration parameters, data replication strategies across data centers, and any additional components you would integrate with Kafka to meet the requirements.

Context: This question assesses the candidate's ability to design complex, scalable systems using Kafka. It tests their understanding of Kafka's architecture and its interaction with other systems to ensure data consistency, fault tolerance, and high availability in a challenging, high-volume scenario.

Updated

Official answer

First define the required ordering, consistency, recovery point and recovery time for orders, inventory and payments. A regional network partition prevents a design from guaranteeing both immediate global consistency and unrestricted writes everywhere. Make the failure policy explicit before choosing replication settings.

Use regional Kafka clusters with replicas distributed across availability zones. For Kafka 4.x, use a suitably resilient KRaft controller quorum; ZooKeeper is no longer the cluster-management mode. Estimate capacity from peak records per second, bytes per record, replication, retention, consumer fan-out and failure headroom. Partition by the business entity requiring order, such as order ID; ordering is per partition, not global.

Within a region, a typical baseline is replication factor 3, acks=all, min.insync.replicas=2 and idempotent producers. Validate the tradeoff between durability and write availability during replica loss. Kafka transactions can cover Kafka records and offsets, not an arbitrary payment provider or regional database transaction.

Use an outbox/CDC design to publish committed business events reliably and assign stable event/business-operation IDs. Consumers must handle retries without double charging or applying an order transition twice. Enforce business invariants in the owning service/database and define schema compatibility, access controls and sensitive-data handling.

MirrorMaker provides cross-cluster replication, but asynchronous mirroring is not a global serializable transaction or zero-loss failover guarantee. Prefer an explicit owner/home region per entity unless a real conflict-resolution model is required. During failover, fence the old writer, assess replication/checkpoint lag, translate consumer positions where supported and reconcile uncertain or duplicate operations. Bi-directional replication alone does not resolve concurrent conflicting updates.

Define and test recovery-point/time objectives, regional isolation, broker loss and replay. Measure end-to-end event age, throughput, replication lag, under-replicated partitions, errors and recovery duration. Keep retention and capacity sufficient for catch-up. Claim the required million-per-minute capacity only after representative load and failure testing.

Sources

Kafka cross-cluster mirroring; Kafka 4.x upgrade and KRaft requirement; producer reliability settings.

Related Questions