liveBook · Manning

Consistency

As explained in Kafka for Architects

Consistency is the transaction property that preserves defined data rules while moving a system between valid states.

Consistency keeps a transaction within defined data rules, moving the system from one valid state to another without compromising integrity. section 7.4.2

In Kafka, consistency matters most in read-process-write pipelines. A transaction can read an Order event and atomically publish its related Shipment, Billing, and Inventory events. section 7.4.2

Order processing

An OrderService reads from ORDERS, processes product, payment, and shipping data, then writes to SHIPMENTS, BILLING, and INVENTORY. Exactly-once processing prevents retries or failures from duplicating or skipping downstream events. section 7.4.2

Consistency is an architectural choice with operational consequences:

  • Favor data safety when financial transactions or payment processing cannot tolerate loss; accept downtime when necessary. section 11.3.2
  • Favor availability for log collection or real-time analytics when remaining online matters more than preserving every message. section 11.3.2
  • Improve durability with multiple in-sync replicas, acks=all, idempotence, manual offset commits, and read_committed consumers. section 11.3.2
Figure 7.24 OrderService reads, processes, and writes each event atomically.
A white rectangle with black text

AI-generated content may be incorrect.

Trace the atomic path from reading an order through processing it and producing all related events. section 7.4.2

Table 11.2 Balancing durability and availability

Configuration setting

Improve durability

Improve availability

Setting type

acks

Use acks=all to ensure data is written to all in-sync replicas

With acks=1 or 0 the producer can continue sending data even if some replicas are temporarily unavailable

Producer

enable.idempotence

Enable to avoid duplicate messages and improve reliability

Enable to avoid duplicate messages and retries in the producer

Producer

enable.auto.commit

Disable and manually commit offsets after processing to avoid data loss

Consumer progresses without waiting for manual commit logic to complete

Consumer

isolation.level

Set to read_committed to read only committed data

Set to read_uncommitted to allow faster reads of all data

Consumer

max.poll.records

Smaller batches reduce memory pressure and risk of data loss during failure

Larger batches improve consumer throughput and avoid stalling (but may risk larger reprocesses)

Consumer

max.poll.interval.ms

Reduce to catch slow consumers faster and avoid stale offsets

Increase to allow slower consumers to stay in group longer

Consumer

session.timeout.ms

Reduce to detect dead consumers quickly and maintain ISRs

May be increased to avoid unnecessary rebalances, but for detecting dead consumers it can be decreased

Consumer

replication.factor

Use a higher replication factor for better data redundancy

A lower replication factor can speed up recovery but risks data loss

Broker

min.insync.replicas

Set higher to ensure more replicas are in sync before committing data

Set lower to allow writes even with fewer in-sync replicas

Broker

unclean.leader
.election.enable

Disable to avoid data loss with unclean leader election

Enable to allow faster leader election even if some data is lost

Broker

broker.rack

Distribute replicas across racks to avoid rack failures causing data loss

Ensure rack awareness for faster recovery if a rack fails

Broker

log.flush.interval
.messages

Reduce to flush data more frequently to disk, minimizing potential data loss

Increase to flush data less frequently for faster throughput

Broker

log.flush.interval.ms

Reduce to flush data to disk more frequently

Increase to flush less often and improve broker throughput

Broker

num.recovery.threads
.per.data.dir

Increase to reduce the window in which durability is weakened

Increase to speed up broker recovery after a crash

Broker

num.standby
.replicas

Increase to reduce the risk
of data loss during failover

Increase to maintain availability during maintenance or failures

Broker

replica.lag.time
.max.ms

Reduce to quickly detect lagging replicas and exclude them from ISRs
for consistency

Increase to tolerate more lag and avoid unnecessary ISR changes that can affect availability

Broker

auto.leader
.rebalance.enable

Disable to keep leaders stable, avoiding leader changes that can affect
data consistency

Enable to allow automatic rebalancing of leaders, improving availability during broker failures

Broker

Compare producer and consumer settings that trade data durability against recovery speed and availability. section 11.3.2

How Kafka for Architects covers it

How deep it goes
Explains ACID consistency, Kafka exactly-once processing, and durability settings, but stops short of implementation walkthroughs.
Examples
Uses an OrderService publishing shipment, billing, and inventory events, plus producer and consumer durability settings.
What it assumes
Assumes familiarity with Kafka topics, producers, consumers, partitions, replicas, and offsets while defining ACID consistency explicitly.
What you can do after
Evaluate Kafka designs by choosing atomic processing and durability or availability settings appropriate to business risk.
How it connects
Connects consistency with transactions, ACID, exactly-once semantics, durability, availability, replication, isolation, and offset commits.

Also explained in

Compare how 20 books explain consistency →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka for Architects. The section links point to the parts of the book it draws on.