How would you optimize Kafka's log flush management to enhance throughput and durability?

Instruction: Provide strategies for balancing between high throughput and ensuring message durability, focusing on log flush settings.

Context: This question assesses the candidate's ability to tune Kafka settings for optimal performance and reliability, emphasizing their understanding of the log flush mechanism.

Updated

Official answer

Separate three events: appending to the filesystem/page cache, replication to other brokers, and forcing dirty data to stable storage. A successful producer acknowledgement does not generally mean each replica performed an fsync for that record.

Kafka recommends the default flush policy for typical deployments, using replication for durability and allowing operating-system writeback. Frequent forced flushes can add I/O stalls and reduce batching efficiency. Start by verifying acknowledgements, the minimum in-sync requirement, replica health and failure-domain placement rather than automatically lowering flush intervals.

The topic settings flush.messages and flush.ms control count-based and time-based forced flushing; their broker defaults are log.flush.interval.messages and log.flush.interval.ms. The time-based setting also depends on the broker's flush-check scheduler. Treat it as a configured policy, not a hard real-time promise that every record reaches durable media within exactly that duration.

If the threat model includes correlated loss of unflushed replicas, evaluate forced flushes and the storage device's actual durability guarantees. A single local fsync does not replace replication, and replication does not protect against every simultaneous storage or administrative failure.

Compare end-to-end latency, flush latency, disk utilization, dirty-page pressure and replication health under the same workload and acknowledgement policy. Test the relevant failure/recovery scenarios. Keep the change only if it meets the stated durability and performance requirements; do not claim an unmeasured optimum.

Flush configuration, application versus OS flush management

Related Questions