Scrivio Interview library

Apache Kafka with Spring

51 questions in 16 subtopics.

Topics, partitions and consumer groups

InternalsFoundations7 min read
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?
DebuggingFoundations6 min read
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?
DesignIntermediate6 min read
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?
LeadershipAdvanced6 min read
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?
LeadershipPrincipal7 min read
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?
LeadershipPrincipal6 min read
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

ConceptFoundations6 min read
Explain the producer settings acks=0, acks=1 and acks=all together with min.insync.replicas. What are the defaults in recent Kafka clients, and which combination loses data when a leader fails?
DebuggingIntermediate6 min read
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?
ScenarioIntermediate6 min read
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

InternalsFoundations5 min read
How does the idempotent producer prevent duplicate records when a send is retried, and what does it not protect against?
CodingIntermediate6 min read
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?
ScenarioIntermediate6 min read
A listener writes an order row to PostgreSQL and then sends an event with a transactional KafkaTemplate. 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

ConceptFoundations6 min read
Spring Kafka's listener container commits offsets for you. Explain the default AckMode, the MANUAL and MANUAL_IMMEDIATE modes, and why Spring disables enable.auto.commit by default.
DebuggingFoundations7 min read
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.
ScenarioIntermediate7 min read
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

ConceptFoundations7 min read
In Spring Kafka, what does DefaultErrorHandler do when a listener throws an exception, with default settings, and how do you send failed records to a dead-letter topic?
DebuggingIntermediate7 min read
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?
DesignIntermediate7 min read
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.
LeadershipAdvanced7 min read
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

ConceptFoundations6 min read
What ordering does Kafka guarantee? A team sends events for the same customer without a key and wonders why a consumer sometimes sees CustomerUpdated before CustomerCreated. Explain and fix.
DesignIntermediate7 min read
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?
ScenarioAdvanced6 min read
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

ConceptIntermediate6 min read
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.
InternalsIntermediate6 min read
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?
DesignAdvanced7 min read
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?
LeadershipPrincipal6 min read
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

ConceptFoundations6 min read
What does a schema registry do in a Kafka system using Avro, and what happens on the wire when KafkaAvroSerializer sends a record?
ScenarioIntermediate6 min read
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?
LeadershipAdvanced6 min read
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.
LeadershipPrincipal6 min read
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

ConceptIntermediate6 min read
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.
DebuggingIntermediate7 min read
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?
DesignAdvanced6 min read
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

ConceptFoundations6 min read
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?
DebuggingIntermediate7 min read
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?
ScenarioAdvanced7 min read
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

InternalsFoundations7 min read
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.
DebuggingIntermediate7 min read
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.
ScenarioIntermediate7 min read
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

ConceptFoundations7 min read
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 why ErrorHandlingDeserializer is recommended.
DebuggingIntermediate6 min read
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

CodingFoundations6 min read
Show how a Spring Boot application declares a topic named "orders" with 12 partitions and replication factor 3, and explain what KafkaAdmin does at startup. What happens if you later change the bean to 6 partitions?
ScenarioIntermediate7 min read
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?
DesignAdvanced6 min read
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

CodingFoundations6 min read
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.
DebuggingIntermediate6 min read
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

ConceptIntermediate6 min read
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.
DesignAdvanced5 min read
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?
LeadershipPrincipal6 min read
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

ConceptFoundations6 min read
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.
DebuggingIntermediate6 min read
A developer runs Kafka in Docker with advertised.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.