Apache Kafka with Spring
51 questions in 16 subtopics.
Topics, partitions and consumer groups
Explain how a Kafka consumer group assigns partitions to consumers and what happens during a rebalance. A topic has 6 partitions and a Spring@KafkaListener has concurrency = 3 in each of 4 pods. How many consumers actually receive data?A Spring Kafka consumer processes each record by calling a slow external API, and the logs show repeated rebalances and "CommitFailedException" or messages about the consumer leaving the group. What is the cause and how do you fix it?How would you choose the number of partitions for a new topic carrying 20,000 events per second of order updates, consumed by three services with different processing speeds? What makes changing it later hard?You are defining the Kafka platform standards for 50 teams. What would you standardise about topic naming, partition counts, retention, replication and ownership, and how would you enforce it?Some architects propose making Kafka the system of record for the company, with infinite retention on key topics and databases treated as derived views. How would you evaluate this proposal for a ten-year horizon?Ten years ago your company built its integration on a central Kafka cluster. Today it runs many clusters, costs a lot, and every team depends on it. How would you evaluate the event platform's future: managed service, self-hosted, tiered storage, or alternatives?Producer configuration and acks
Explain the producer settings acks=0, acks=1 and acks=all together withmin.insync.replicas. What are the defaults in recent Kafka clients, and which combination loses data when a leader fails?During a broker restart a producer logs NotEnoughReplicasException and TimeoutException and some sends fail after delivery.timeout.ms. What does each error mean and how should the service react?A producer service needs higher throughput; it sends small JSON events one at a time with KafkaTemplate and blocks on each send's result. Which producer settings and code changes would you consider, and what do they cost?Idempotent and transactional producers
How does the idempotent producer prevent duplicate records when a send is retried, and what does it not protect against?Show how to enable Kafka transactions in Spring Boot and write a listener that consumes from "orders" and produces to "invoices" and "audit" atomically. Which consumer setting must downstream consumers use?A listener writes an order row to PostgreSQL and then sends an event with a transactionalKafkaTemplate. Someone proposes chaining the JPA and Kafka transaction managers so both commit together. What actually happens, and what would you recommend?Consumer offsets and commits
Spring Kafka's listener container commits offsets for you. Explain the defaultAckMode, the MANUAL and MANUAL_IMMEDIATE modes, and why Spring disables enable.auto.commit by default.After a consumer restart, a service reprocessed two days of events. The consumer group had been stopped for a week during a migration and auto.offset.reset is earliest. Explain what happened.You need to reprocess the last six hours of events for one consumer group after a bug fix, without affecting other groups. How would you do it safely?Retries and dead-letter topics
In Spring Kafka, what doesDefaultErrorHandler do when a listener throws an exception, with default settings, and how do you send failed records to a dead-letter topic?A consumer is stuck: lag on one partition grows while others are fine, and the logs show the same deserialization error repeating forever. The service uses JsonDeserializer directly. What is wrong and how do you fix it?Design error handling for a payment-events consumer where some failures are transient (downstream timeouts) and some permanent (invalid data). Compare blocking retries with @RetryableTopic non-blocking retries.Many teams' dead-letter topics fill up with millions of records that nobody looks at. How would you set a dead-letter policy for the event platform?Ordering guarantees
What ordering does Kafka guarantee? A team sends events for the same customer without a key and wonders why a consumer sometimes seesCustomerUpdated before CustomerCreated. Explain and fix.A consumer must process events in order per account but one partition carries much more traffic than others and processing is slow. How can you get more parallelism without breaking per-account ordering?Several services rely on strict global order of events across all customers, which forces a single-partition topic now at its throughput limit. How would you lead the change away from global ordering?Exactly-once semantics
What does exactly-once semantics in Kafka actually guarantee, and what does it not cover? A product manager hears "Kafka is exactly-once" and assumes no customer will ever be charged twice.How do transactional producers fence zombie instances, and why did Kafka add the EOS v2 (exactly_once_v2) mode for Kafka Streams and consume-transform-produce applications?You are asked to guarantee that a ledger built from Kafka events never double-counts, across producers, a stream processor and a database sink. How would you design end-to-end exactly-once behaviour?Leaders are asking whether the company should require exactly-once processing on all event pipelines. How would you answer and what policy would you propose?Schema registry and Avro
What does a schema registry do in a Kafka system using Avro, and what happens on the wire whenKafkaAvroSerializer sends a record?A team wants to rename a field in an Avro schema used by five consumer services and remove another field. Compatibility is set to BACKWARD. Which changes are allowed, and how would you roll them out?Should your organisation standardise on Avro, Protobuf or JSON Schema for Kafka events, and how strict should compatibility rules be? Lay out how you would decide.Business units now want to use Kafka events directly for analytics, machine learning and partner data feeds. How would you set up ownership and governance of event data as a company asset over the long term?Kafka Streams
Explain the difference between a KStream, a KTable and a GlobalKTable in Kafka Streams, and how state stores and changelog topics make stateful processing fault tolerant.A Kafka Streams application joins orders with customers, but some orders never produce a joined result even though the customer exists. What would you check?When would you choose Kafka Streams inside a Spring Boot service, and when a separate stream processing platform such as Apache Flink, for an organisation building real-time features?Consumer lag
What is consumer lag in Kafka, how is it measured, and which tools or metrics would you use to watch it for a Spring Boot consumer?Consumer lag for an order-processing group grows steadily every evening and recovers overnight. The group has 12 partitions and 12 consumers. How would you diagnose and fix it?Your company's event platform has 300 consumer groups. Teams get paged for lag that resolves itself, and real lag problems are missed. How would you define a standard lag alerting policy?@KafkaListener and listener containers
What happens behind a@KafkaListener method in Spring for Apache Kafka? Explain the roles of the listener container factory, ConcurrentMessageListenerContainer and KafkaMessageListenerContainer, and what the concurrency attribute does.A new @KafkaListener(topics = "invoices") in a service never receives messages, while another listener in the same application works. No errors appear at startup. List the configuration causes you would check, in order.A Spring Kafka listener writes to a downstream payment API. When that API is down for 20 minutes, the listener keeps failing, retrying and filling logs, and after recovery the service is slow to catch up. How would you use the listener container features to handle outages and recovery?Serializers and deserializers
In Spring Kafka, explain how you configure JSON serialization for values, what the __TypeId__ header is, why you set trusted packages on the deserializer, and whyErrorHandlingDeserializer is recommended.A producer team moved its event class from com.acme.orders.events.OrderPlaced to com.acme.orders.api.OrderPlaced. Since their release, a consumer in another team fails with a class-not-found or "not in the trusted packages" error for every record. Explain the cause and how to decouple producers and consumers.Topic administration
Show how a Spring Boot application declares a topic named "orders" with 12 partitions and replication factor 3, and explain whatKafkaAdmin does at startup. What happens if you later change the bean to 6 partitions?A topic keyed by customer id has 6 partitions and needs more throughput, so a team wants to increase it to 24 partitions. Consumers rely on per-customer ordering. What happens if you just add partitions, and how would you carry out the change safely?Fifty teams create Kafka topics in different ways: some from application code with NewTopic beans, some by ticket to the platform team, some with scripts. Topics without owners, wrong retention and replication factor 1 keep causing incidents. How do you design topic administration for the organization?Testing Kafka clients
How do you write an integration test for a Spring Boot service that consumes from Kafka and stores records in a database? Compare@EmbeddedKafka with Testcontainers, and show how the test waits for the asynchronous result.A Kafka integration test passes locally but fails about 1 run in 10 in CI: the consumer sometimes sees no record, and sometimes a record from another test. Tests share one broker container. What causes this, and how do you make the tests reliable?Share groups and Kafka queues
Kafka is adding share groups (KIP-932), often described as "queues for Kafka". Explain how a share group differs from a consumer group in partition assignment, acknowledgement, redelivery and ordering, and what problem it solves.Your company runs both Kafka and a separate queue system (RabbitMQ or SQS) for background jobs. With share groups arriving in Kafka, some engineers propose moving all job queues to Kafka. How do you evaluate this?Kafka is moving toward queue semantics, cloud providers offer many managed messaging services, and vendors bundle streaming with analytics. As the person responsible for the company's messaging strategy for the next five years, how do you decide what to consolidate and what to keep?Local Kafka setup
How do you run Kafka locally for development of a Spring Boot service today? Show the main settings of a single-node KRaft broker in Docker Compose and explain the listeners and advertised listeners settings.A developer runs Kafka in Docker withadvertised.listeners=PLAINTEXT://localhost:9092. The Spring Boot app running on the host works, but the same app in another container on the same Docker network logs repeatedly: "Connection to node 1 (localhost/127.0.0.1:9092) could not be established. Node may not be available." Explain and fix.No question matches these choices.