Distributed SystemsADVANCEDPart 3 of 3 in Series

Kafka Partitioning Strategies for Zero-Data-Loss Architectures

Guaranteed message ordering, consumer group rebalancing internals, and handling backpressure in distributed event stream pipelines.

A
Alex Rivera
@alexdev
September 21, 2026 15 min read
Share
Part 3 of 3Technical Learning Track

System Design: From Zero to Production

A comprehensive engineering series guiding backend developers from single-node instances to highly resilient distributed architectures.

Kafka Partitioning Strategies for Zero-Data-Loss Architectures

Overview

Apache Kafka enables petabyte-scale stream processing, but achieving exactly-once semantics (EOS) and zero message loss requires careful configuration across brokers, partition keys, and consumers.

Partitioning Topology

text
flowchart LR
    P[Event Producer] -->|Hash Partition Key: order_id| K[Kafka Broker Cluster]
    subgraph Partitions [Topic: orders.v1]
      P0[Partition 0: Leader Broker 1]
      P1[Partition 1: Leader Broker 2]
      P2[Partition 2: Leader Broker 3]
    end
    K --> P0
    K --> P1
    K --> P2
    P0 --> C0[Consumer Instance A]
    P1 --> C1[Consumer Instance B]
    P2 --> C2[Consumer Instance C]

Zero-Loss Producer Configuration

text
import { Kafka, CompressionTypes, logLevel } from 'kafkajs';

const kafka = new Kafka({
  clientId: 'order-processing-gateway',
  brokers: ['kafka-1.internal:9092', 'kafka-2.internal:9092', 'kafka-3.internal:9092'],
  logLevel: logLevel.WARN,
});

export const producer = kafka.producer({
  // Idempotent producer prevents duplicate message writes
  idempotent: true,
  maxInFlightRequests: 1,
  transactionTimeout: 30000,
});

export async function publishOrderEvent(orderId: string, payload: Record<string, unknown>) {
  await producer.send({
    topic: 'orders.v1',
    compression: CompressionTypes.GZIP,
    messages: [
      {
        key: orderId, // Guarantees all state transitions for this order land on same partition
        value: JSON.stringify({ ...payload, emittedAt: new Date().toISOString() }),
        headers: { correlationId: crypto.randomUUID() },
      },
    ],
    acks: -1, // acks=all: Wait for full In-Sync Replica (ISR) quorum commit
  });
}
Share
Track Roadmap: System Design: From Zero to Production
All Chapters (3)
Previous Chapter (Part 2)

Zero-Downtime PostgreSQL Schema Migrations at Scale

★ You have reached the final chapter of this track!
A

Alex Rivera

@alexdev

Principal Distributed Systems Engineer. Specializing in high-throughput caching and message brokers.

NexusBlog