Chaturmind
LearnDSASystem DesignInterview PrepDevOpsEngineering GrowthBlog
Start learning
Chaturmind

Structured learning paths for engineers who want to go deep. Written by practitioners.

Learn

  • Java
  • DSA
  • System Design
  • Spring Boot
  • AI / ML
  • DevOps
  • Engineering Growth
  • Java Interview Prep

Company

  • Blog
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

© 2026 Chaturmind. All rights reserved.

Built for engineers who want to go deep.


← Java Interview Prep: 2–5 Years

Revise the Fresher Tier

  • Revise: Core Java Fundamentals (Fresher Tier)
  • Revise: Collections, Threads, Java 8 & Coding (Fresher Tier)
  • Revise: Spring Core, Spring Boot & Spring MVC (Fresher Tier)
  • Revise: Hibernate, SQL, Microservices, Maven & Git (Fresher Tier)

Intermediate Core Java

  • Intermediate OOP & Language Features — Interview Questions
  • Enums, Generics, Pass-by-Value & Imports — Interview Questions
  • Collections Internals & Scenarios — Interview Questions
  • JVM, Memory & Class Loading — Interview Questions
  • Exception Design & Serialization Edge Cases — Interview Questions

Java 8 Deep Dive & Stream Coding

  • Lambdas, Functional Interfaces & Method References — Interview Questions
  • Default Methods, Backward Compatibility & Optional — Interview Questions
  • Stream API Internals (Part 1) — Interview Questions
  • Stream API Internals (Part 2) — Interview Questions
  • Stream Coding Problems (Level 2, Part 1) — Interview Questions
  • Stream Coding Problems (Level 2, Part 2) — Interview Questions

Concurrency & Multithreading

  • Synchronization, Locks & Deadlocks — Interview Questions
  • Executors, ThreadLocal & Concurrent Collections — Interview Questions

Spring Framework In Depth

  • Bean Lifecycle, Contexts & Circular Dependencies — Interview Questions
  • Spring Bean Conflicts, AOP, Batch & Injection Styles — Interview Questions

Spring Boot In Depth & Scenarios

  • Spring Boot Internals & Auto-Configuration — Interview Questions
  • Spring Boot Configuration, Profiles & Secrets — Interview Questions
  • Spring Boot Data, Transactions & Caching — Interview Questions
  • Spring Boot Testing, Error Pages & Deployment — Interview Questions
  • Spring Boot Performance, Scaling & Resilience — Interview Questions
  • Spring Boot Async, Events & Messaging — Interview Questions
  • Spring Boot Security Scenarios — Interview Questions
  • Actuator, AOP, Spring Cloud & Distributed Tracing — Interview Questions
  • External APIs, Files, GraphQL & WebFlux — Interview Questions

Spring Security

  • Spring Security — OAuth2, CORS, CSRF & Access Rules — Interview Questions
  • Spring Security — Passwords, Filter Chain, Sessions & Debugging — Interview Questions

Apache Kafka

  • Kafka Architecture, Topics & ZooKeeper vs KRaft — Interview Questions
  • Kafka Producers, Consumers, Reliability & Streams — Interview Questions
  • Kafka Security, Connect & Core Scenarios — Interview Questions
  • Kafka Production Scenarios — Interview Questions

Git, Maven & Gradle (Level II)

  • Git Workflows, Rebase & Conflict Handling — Interview Questions
  • Git Recovery, Hooks, Tags & Collaboration — Interview Questions
  • Maven Builds, Multi-Module Projects & Dependency Resolution — Interview Questions
  • Maven Profiles, settings.xml, Plugins & Quality Gates — Interview Questions
  • Gradle Fundamentals, Migration & Dependencies — Interview Questions
  • Gradle Performance, Plugins, Testing & Publishing — Interview Questions

Deployment & CI/CD

  • Sessions, CI/CD Pipelines, Rollbacks & Secrets — Interview Questions
  • Migrations, Zero-Downtime Releases, Containers & Monitoring — Interview Questions

JUnit 5 & Mockito

  • JUnit 5 — Interview Questions
  • Mockito Basics — Interview Questions
  • Mockito Advanced & Tricky Questions — Interview Questions
Chaturmind
← Java Interview Prep: 2–5 Years

Revise the Fresher Tier

  • Revise: Core Java Fundamentals (Fresher Tier)
  • Revise: Collections, Threads, Java 8 & Coding (Fresher Tier)
  • Revise: Spring Core, Spring Boot & Spring MVC (Fresher Tier)
  • Revise: Hibernate, SQL, Microservices, Maven & Git (Fresher Tier)

Intermediate Core Java

  • Intermediate OOP & Language Features — Interview Questions
  • Enums, Generics, Pass-by-Value & Imports — Interview Questions
  • Collections Internals & Scenarios — Interview Questions
  • JVM, Memory & Class Loading — Interview Questions
  • Exception Design & Serialization Edge Cases — Interview Questions

Java 8 Deep Dive & Stream Coding

  • Lambdas, Functional Interfaces & Method References — Interview Questions
  • Default Methods, Backward Compatibility & Optional — Interview Questions
  • Stream API Internals (Part 1) — Interview Questions
  • Stream API Internals (Part 2) — Interview Questions
  • Stream Coding Problems (Level 2, Part 1) — Interview Questions
  • Stream Coding Problems (Level 2, Part 2) — Interview Questions

Concurrency & Multithreading

  • Synchronization, Locks & Deadlocks — Interview Questions
  • Executors, ThreadLocal & Concurrent Collections — Interview Questions

Spring Framework In Depth

  • Bean Lifecycle, Contexts & Circular Dependencies — Interview Questions
  • Spring Bean Conflicts, AOP, Batch & Injection Styles — Interview Questions

Spring Boot In Depth & Scenarios

  • Spring Boot Internals & Auto-Configuration — Interview Questions
  • Spring Boot Configuration, Profiles & Secrets — Interview Questions
  • Spring Boot Data, Transactions & Caching — Interview Questions
  • Spring Boot Testing, Error Pages & Deployment — Interview Questions
  • Spring Boot Performance, Scaling & Resilience — Interview Questions
  • Spring Boot Async, Events & Messaging — Interview Questions
  • Spring Boot Security Scenarios — Interview Questions
  • Actuator, AOP, Spring Cloud & Distributed Tracing — Interview Questions
  • External APIs, Files, GraphQL & WebFlux — Interview Questions

Spring Security

  • Spring Security — OAuth2, CORS, CSRF & Access Rules — Interview Questions
  • Spring Security — Passwords, Filter Chain, Sessions & Debugging — Interview Questions

Apache Kafka

  • Kafka Architecture, Topics & ZooKeeper vs KRaft — Interview Questions
  • Kafka Producers, Consumers, Reliability & Streams — Interview Questions
  • Kafka Security, Connect & Core Scenarios — Interview Questions
  • Kafka Production Scenarios — Interview Questions

Git, Maven & Gradle (Level II)

  • Git Workflows, Rebase & Conflict Handling — Interview Questions
  • Git Recovery, Hooks, Tags & Collaboration — Interview Questions
  • Maven Builds, Multi-Module Projects & Dependency Resolution — Interview Questions
  • Maven Profiles, settings.xml, Plugins & Quality Gates — Interview Questions
  • Gradle Fundamentals, Migration & Dependencies — Interview Questions
  • Gradle Performance, Plugins, Testing & Publishing — Interview Questions

Deployment & CI/CD

  • Sessions, CI/CD Pipelines, Rollbacks & Secrets — Interview Questions
  • Migrations, Zero-Downtime Releases, Containers & Monitoring — Interview Questions

JUnit 5 & Mockito

  • JUnit 5 — Interview Questions
  • Mockito Basics — Interview Questions
  • Mockito Advanced & Tricky Questions — Interview Questions
HomeLearnJava Interview PrepJava Interview Prep: 2–5 YearsApache Kafka
✓ FreeIntermediate· 8 min read

Kafka Producers, Consumers, Reliability & Streams — Interview Questions

Producers and consumers, how producers send data (batching, keys, idempotence), consumer read strategies and offset commits, consumer groups and scaling, fault tolerance and replication, preventing data loss end to end, acks settings, Kafka Streams, how it differs from other engines, state stores and its challenges.

Published September 25, 2026


How to use this lesson

"Kafka is reliable" isn't an answer. Interviewers want to know which settings make it reliable (acks, idempotence, min.insync.replicas, commit strategy), and where data can still be lost or duplicated. Walk through the full path: producer → broker → consumer.

Q1. What are Kafka producers and consumers?

Short answer: Producers publish records (key, value, headers, timestamp) to topics. Consumers pull records from partitions, and track their position with offsets. Consumers usually belong to a consumer group, so the partitions are shared out among them. Producers and consumers are fully decoupled: neither knows about the other, and they can run at different speeds.

Learn it in depth → Message Queue System

Q2. How do producers send data to Kafka?

Short answer:

  1. The producer serialises the key and value.
  2. It picks a partition: by key hash (same key → same partition, which preserves per-key order), or with the sticky partitioner when there's no key.
  3. It batches records per partition in memory (batch.size, linger.ms), and optionally compresses them (lz4, zstd).
  4. It sends each batch to that partition's leader, and waits for acks according to acks.

It retries automatically on transient failures.

Properties p = new Properties();
p.put(ProducerConfig.ACKS_CONFIG, "all");
p.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, true);          // no duplicates from retries (default true since 3.0)
p.put(ProducerConfig.LINGER_MS_CONFIG, 10);
p.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, "zstd");
producer.send(new ProducerRecord<>("orders.placed", order.id(), event), (meta, ex) -> {
    if (ex != null) log.error("publish failed for {}", order.id(), ex);    // handle async failures!
});

Q3. What strategies do consumers use to read data?

Short answer:

  • Subscribe to topics as part of a group (automatic partition assignment and rebalancing), or assign specific partitions manually.
  • Where to start with no committed offset: auto.offset.reset = earliest or latest.
  • How to commit offsets:
    • Auto-commit (periodic): simple, but it can lose or duplicate records around a crash.
    • Manual commit after processing gives at-least-once delivery. It's the usual choice, and Spring Kafka's default AckMode.BATCH does this.
    • Transactional read-process-write, for exactly-once within Kafka.
  • Batch vs per-record processing, and max.poll.records to control the batch size.

Key points to cover:

  • At-least-once means duplicates are possible, so make processing idempotent. For example, deduplicate by event ID, or upsert.

Q4. How do consumer groups help Kafka scale?

Short answer: Within a group, each partition is consumed by exactly one member. Adding consumers spreads the partitions across more instances (horizontal scaling), up to one consumer per partition. Extra consumers sit idle. Different groups each get every record independently, which gives pub/sub fan-out. When members join or leave, the group rebalances the partitions.

Key points to cover:

  • Scale limit = partition count, so plan partitions for peak parallelism.
  • Use cooperative sticky assignment and static membership (group.instance.id), so rolling deploys don't trigger full stop-the-world rebalances.
  • Kafka 4.0 brings the new consumer rebalance protocol (KIP-848), which makes rebalances incremental and server-driven.

Q5. How does Kafka achieve fault tolerance?

Short answer:

  • Replication: each partition has copies on several brokers, spread across racks or AZs.
  • Leader election from the ISR when a broker fails.
  • Durable, append-only logs on disk.
  • Controller quorum (KRaft), for metadata high availability.
  • Client-side resilience: producer retries with idempotence, and consumers resuming from committed offsets after a crash or rebalance.

Q6. What is the role of replication in Kafka?

Short answer: Replication keeps redundant copies of each partition, so a broker failure causes no data loss and only a brief interruption for leader election. Writes go to the leader. Followers replicate them, and an acknowledged write (acks=all) has reached all in-sync replicas. Combined with min.insync.replicas, replication defines your durability guarantee.

Common trap: "replication helps balance reads because consumers read from different copies". By default, consumers read from the leader. Follower fetching exists, but it's an opt-in, rack-aware optimisation.

Q7. How does Kafka make sure data isn't lost?

Short answer: Only when the whole chain is configured for it:

StageSetting
Produceracks=all, enable.idempotence=true, sensible retries / delivery.timeout.ms, handle send callbacks
Topicreplication.factor=3, min.insync.replicas=2, unclean.leader.election.enable=false
BrokersReplicas spread across racks/AZs; monitor under-replicated partitions
ConsumerCommit offsets after successful processing; no auto-commit for critical data
ApplicationThe outbox pattern, so events are published if and only if the database commit succeeds

Key points to cover:

  • Kafka writes to the OS page cache, and relies on replication rather than an fsync per message for durability. Losing all in-sync replicas at the same moment (for example, a whole AZ with a replication factor of 1 per AZ) can still lose data. Design the replica placement accordingly.

Q8. What is the significance of the producer's acks setting?

Short answer: It defines when a write counts as successful:

  • acks=0: fire-and-forget. Fastest, but data can be lost silently.
  • acks=1: the leader has written it. Data is lost if the leader fails before the followers replicate it.
  • acks=all (-1): all in-sync replicas have it. That's the strongest durability, and it's the default since Kafka 3.0 (together with idempotence).

Key points to cover:

  • acks=all is only meaningful with min.insync.replicas ≥ 2. Otherwise "all ISR" can shrink to just the leader.
  • When the ISR is too small, acks=all producers get a NotEnoughReplicas error. That's safety over availability, by design.

Q9. What is Kafka Streams, and what is it used for?

Short answer: Kafka Streams is a Java library for building stream-processing applications that read from Kafka topics, transform, join, aggregate and window the data, and write the results back to Kafka. It runs inside your own application, with no separate cluster. Use cases:

  • real-time aggregations (orders per minute);
  • enrichment joins (clicks + user profiles);
  • fraud and anomaly detection;
  • materialised views, queryable through interactive queries;
  • event-driven microservices.
StreamsBuilder b = new StreamsBuilder();
b.stream("payments", Consumed.with(Serdes.String(), paymentSerde))
 .filter((k, p) -> p.amount().compareTo(new BigDecimal("100000")) > 0)
 .groupBy((k, p) -> p.cardId(), Grouped.with(Serdes.String(), paymentSerde))
 .windowedBy(TimeWindows.ofSizeWithNoGrace(Duration.ofMinutes(5)))
 .count()
 .toStream()
 .filter((windowedCard, count) -> count >= 3)
 .to("fraud-alerts");

Q10. What differentiates Kafka Streams from other stream-processing frameworks?

Short answer:

  • It's a library, not a cluster. You deploy it like any Java app (in containers, scaled by running more instances), unlike Flink or Spark, which need their own cluster managers.
  • It's Kafka-native. It uses Kafka for input and output, for state backup (changelog topics), for repartitioning and for coordination (consumer groups).
  • Exactly-once processing within Kafka (processing.guarantee=exactly_once_v2).
  • The KStream/KTable duality, joins, windowing and event-time processing.

The trade-off: it's Kafka-in, Kafka-out. For multiple sources and sinks, very large state, or complex event-time handling at scale, Apache Flink is often the better fit.

Q11. How does Kafka Streams handle state?

Short answer: Stateful operations (aggregations, joins, windows) keep their state in local state stores: RocksDB by default, or in memory. Each store is backed by a compacted changelog topic in Kafka. On a restart or rebalance, a task restores its store by replaying the changelog. Standby replicas (num.standby.replicas) keep warm copies on other instances, for faster failover. State is partitioned in the same way as the input topics.

Q12. What are the challenges of using Kafka Streams?

Short answer:

  • State restoration time: large stores can take minutes to rebuild after a rebalance. Mitigate with standby replicas and warm-up.
  • Rebalances pause processing.
  • Repartition topics created implicitly by groupBy/selectKey add latency and storage.
  • Disk sizing for RocksDB, and memory tuning.
  • Schema evolution of state and events.
  • Handling late or out-of-order events (grace periods).
  • Debugging and testing topologies (use TopologyTestDriver).
  • Scaling is limited by the input partition count.

Follow-up questions this topic invites — and their answers

Q: What does producer idempotence guarantee? A: Retries can't create duplicates in the log, and order is preserved per partition. The broker deduplicates using a producer ID plus per-partition sequence numbers. It covers a single producer session. For atomic writes across partitions, use transactions.

Q: What's consumer lag, and why does it matter? A: Lag is the difference between the latest offset in a partition and the consumer group's committed offset. Growing lag means consumers can't keep up, and data is getting stale. It's the key metric for autoscaling and alerting.

Q: When should you commit offsets? A: After the record's side effects are durable: after the database write succeeds. Committing before processing risks losing records on a crash. Committing after means occasional duplicates, so make the handlers idempotent.

Q: KStream vs KTable? A: A KStream is an unbounded stream of events, where every record is a fact. A KTable is a changelog view, keeping the latest value per key, like a continuously updated table. Joining a stream to a table enriches each event with the current state.

Previous

Kafka Architecture, Topics & ZooKeeper vs KRaft — Interview Questions

Next

Kafka Security, Connect & Core Scenarios — Interview Questions

AI Tutor

Lesson: Kafka Producers, Consumers, Reliability & Streams — Interview Questions

Quick actions

AI responses can be inaccurate. Verify critical information.