Interview's MateData Engineer
Interview's Mate

Data Engineer

SQL · Spark · Lakehouse · Streaming

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Engineer topics
Lesson 124/ 160
07. Streaming & Real-Time Data Engineering

Kafka Producers (Acknowledgments acks, Batching, Compression, Partitioners)

Tune producer acks, batching, compression, and partitioners for throughput and durability.

Intermediateacks · Batching · Partitioners3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Stable schema and ordering identity. Next, choose route, linger, compress, and bound buffers. Finally, queue, errors, request latency, and delivery timeout.

Think of it like…

A producer is a shipping desk that waits briefly to fill a carton, chooses a conveyor by key, and asks for one leader or all replica signatures depending on the parcel's risk.

Where you’ve seen it

enable.idempotence=true, acks=all, compression.type=zstd, linger.ms=10, batch.size=65536, and a key serializer for account_id trade a few milliseconds for safer compressed batches.

Words you’ll hear

acks
Acknowledgment policy for leader-only or all in-sync replica durability, with zero/none in restricted use cases.
Batching
Buffering records into partition requests to amortize headers and network overhead.
Partitioners
The function mapping a record key to a partition; null or unstable keys change distribution/order guarantees.
Operational boundary
acks=1 can acknowledge a record that is lost in a leader failure, tiny batches waste network calls, retries plus an unstable key can reorder records, and a blocked metadata/produce timeout can stop the whole extractor. Use idempotent producers and acks=all, tune linger.ms/batch.size from p95 load, set max.in.flight and delivery timeout consciously, expose broker errors/metrics, and partition by stable order-bearing business keys.

Visual diagram

Loading interactive diagram

Theory & deep dive

acks: the working mechanism

Kafka producers buffer records by partition, compress batches, apply a partitioner, retry transient errors, and wait for acknowledgments according to durability and throughput requirements.

Stable schema and ordering identity. Choose route, linger, compress, and bound buffers, then leader or ISR acknowledgements with retry; this exposes the state governed by Partitioners.

Kafka Producers in one concrete design

enable.idempotence=true, acks=all, compression.type=zstd, linger.ms=10, batch.size=65536, and a key serializer for account_id trade a few milliseconds for safer compressed batches.

Key takeaway: Kafka producers buffer records by partition, compress batches, apply a partitioner, retry transient errors, and wait for acknowledgments according to durability and throughput requirements

Kafka Producers: failure mode and production response

acks=1 can acknowledge a record that is lost in a leader failure, tiny batches waste network calls, retries plus an unstable key can reorder records, and a blocked metadata/produce timeout can stop the whole extractor.

Use idempotent producers and acks=all, tune linger.ms/batch.size from p95 load, set max.in.flight and delivery timeout consciously, expose broker errors/metrics, and partition by stable order-bearing business keys. Track linger.ms as "maximum intentional batching wait per request", and make acks=all visible to the dataset owner.

Key takeaway: Use idempotent producers and acks=all, tune linger.ms/batch.size from p95 load, set max.in.flight and delivery timeout consciously, expose broker errors/metrics, and partition by stable order-bearing business keys.

How it works, step by step

Step 1 of 4
acks

1. Serialize/key

Stable schema and ordering identity. Kafka producers buffer records by partition, compress batches, apply a partitioner, retry transient errors, and wait for acknowledgments according to durability and throughput requirements.

stable schema and ordering identity
Key numbers at this step
linger.ms
maximum intentional batching wait per request
Batching
Buffering records into partition requests to amortize headers and network overhead.

When to use it & trade-offs

What it is

Kafka producers buffer records by partition, compress batches, apply a partitioner, retry transient errors, and wait for acknowledgments according to durability and throughput requirements. enable.idempotence=true, acks=all, compression.type=zstd, linger.ms=10, batch.size=65536, and a key serializer for account_id trade a few milliseconds for safer compressed batches.

Why it matters: acks=1 can acknowledge a record that is lost in a leader failure, tiny batches waste network calls, retries plus an unstable key can reorder records, and a blocked metadata/produce timeout can stop the whole extractor. Use idempotent producers and acks=all, tune linger.ms/batch.size from p95 load, set max.in.flight and delivery timeout consciously, expose broker errors/metrics, and partition by stable order-bearing business keys.

When to reach for it

  • Tune producer acks, batching, compression, and partitioners for throughput and durability.
  • Choose acks because it provides this capability: Acknowledgment policy for leader-only or all in-sync replica durability, with zero/none in restricted use cases.
  • Keep evidence for linger.ms at "maximum intentional batching wait per request" so the last production stage-Observe - queue, errors, request latency, and delivery timeout-remains testable.

When to avoid or be careful

  • acks=1 can acknowledge a record that is lost in a leader failure, tiny batches waste network calls, retries plus an unstable key can reorder records, and a blocked metadata/produce timeout can stop the whole extractor.
  • Do not conflate Batching with acks. The second concept contributes different behavior: Buffering records into partition requests to amortize headers and network overhead.
  • Release only after this guardrail is in place: Use idempotent producers and acks=all, tune linger.ms/batch.size from p95 load, set max.in.flight and delivery timeout consciously, expose broker errors/metrics, and partition by stable order-bearing business keys.

acks / Batching / Partitioners - roles, limits, and operating cost

acks
Best for: Acknowledgment policy for leader-only or all in-sync replica durability, with zero/none in restricted use cases.

Strengths: Acknowledgment policy for leader-only or all in-sync replica durability, with zero/none in restricted use cases. Kafka producers buffer records by partition, compress batches, apply a partitioner, retry transient errors, and wait for acknowledgments according to durability and throughput requirements.

Watch out: acks=1 can acknowledge a record that is lost in a leader failure, tiny batches waste network calls, retries plus an unstable key can reorder records, and a blocked metadata/produce timeout can stop the whole extractor.

Batching
Best for: Buffering records into partition requests to amortize headers and network overhead.

Strengths: Buffering records into partition requests to amortize headers and network overhead. In this workflow it supports: Send/ack - leader or ISR acknowledgements with retry.

Watch out: The operating cost is real: all current ISR leaders/replicas acknowledge.

Partitioners
Best for: The function mapping a record key to a partition; null or unstable keys change distribution/order guarantees.

Strengths: The function mapping a record key to a partition; null or unstable keys change distribution/order guarantees. Its output can be checked with Delivery timeout.

Watch out: Operating guardrail: Use idempotent producers and acks=all, tune linger.ms/batch.size from p95 load, set max.in.flight and delivery timeout consciously, expose broker errors/metrics, and partition by stable order-bearing business keys.

Interview signals & numbers to know

When this topic comes up

  • “Where is the failure boundary for acks, and how would linger.ms reveal it?”
  • “Why is Batching distinct from this behavior: the function mapping a record key to a partition; null or unstable keys change distribution/order guarantees?”
  • Production clue: acks=1 can acknowledge a record that is lost in a leader failure, tiny batches waste network calls, retries plus an unstable key can reorder records, and a blocked metadata/produce timeout can stop the whole extractor.
  • Design probe: Use idempotent producers and acks=all, tune linger.ms/batch.size from p95 load, set max.in.flight and delivery timeout consciously, expose broker errors/metrics, and partition by stable order-bearing business keys.

Benchmarks & rules of thumb

linger.ms -
maximum intentional batching wait per request
acks=all -
all current ISR leaders/replicas acknowledge
Delivery timeout -
upper bound including queue and retries

Common mistakes & follow-ups

Common interview mistakes

  • acks=1 can acknowledge a record that is lost in a leader failure, tiny batches waste network calls, retries plus an unstable key can reorder records, and a blocked metadata/produce timeout can stop the whole extractor.
  • Reporting success from a job exit code without checking linger.ms and acks=all.
  • Treating this example as complete without replay, rollback, or access boundaries: enable.idempotence=true, acks=all, compression.type=zstd, linger.ms=10, batch.size=65536, and a key serializer for account_id trade a few milliseconds for safer compressed batches.

Likely interviewer follow-ups

  • How would you prove this contract instead of only checking that the command ran: Acknowledgment policy for leader-only or all in-sync replica durability, with zero/none in restricted use cases.
  • What does the recovery plan do when this occurs? acks=1 can acknowledge a record that is lost in a leader failure, tiny batches waste network calls, retries plus an unstable key can reorder records, and a blocked metadata/produce timeout can stop the whole extractor.
  • When is acks insufficient for acks=all, and what does adding Batching cost in linger.ms?
Interview tip: Lead with the data path and failure boundary: Kafka producers buffer records by partition, compress batches, apply a partitioner, retry transient errors, and wait for acknowledgments according to durability and throughput requirements. Then make the answer operational: Use idempotent producers and acks=all, tune linger.ms/batch.size from p95 load, set max.in.flight and delivery timeout consciously, expose broker errors/metrics, and partition by stable order-bearing business keys.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Kafka Producers (Acknowledgments acks, Batching, Compression, Partitioners) with data engineer interview Q&A and hands-on practice.

Open Data Engineer Q&A →Machine Learning Q&A
Previous topic
Apache Kafka Architecture (Brokers, Topics, Partitions, Offsets, Zookeeper vs KRaft)
Next topic
Kafka Consumers, Consumer Groups, Rebalancing & Offset Management