Java Backend Interview Q&A← All stacks

Apache Kafka — Interview Q&A Matrix

Parent stack: Messaging & Integration Technology: Apache Kafka Levels: Junior · Senior · Architect Questions: 6

Each entry contains a Question, the Expected Depth, an Ideal Answer, and Red Flags.

Junior

Q1 — Kafka producers, consumers, and the log model

Question: Explain Kafka's main concepts: topic, partition, record, offset, producer, consumer, and consumer group.

Expected Depth:

Ideal Answer:

java
kafkaTemplate.send("orders", order.customerId(), order);
java
@KafkaListener(topics = "orders", groupId = "billing")
public void onOrder(OrderEvent event) {
    billing.charge(event);
}

Red Flags:


Q2 — Message keys and partition assignment

Question: Why would you set a key on a Kafka record, and what happens when the key is null?

Expected Depth:

Ideal Answer:

java
var record = new ProducerRecord<String, AccountEvent>(
  "account-events",
  event.accountId(),
  event);

producer.send(record);

Red Flags:


Senior

Q3 — Delivery semantics: at-least-once, at-most-once, exactly-once

Question: Compare Kafka's delivery guarantees and how you achieve idempotent/exactly-once processing in a consumer.

Expected Depth:

Ideal Answer:

java
props.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, true);
props.put(ProducerConfig.TRANSACTIONAL_ID_CONFIG, "billing-tx");

producer.initTransactions();
producer.beginTransaction();
try {
  producer.send(outputRecord);
  producer.sendOffsetsToTransaction(offsets, consumerGroupMetadata);
  producer.commitTransaction();
} catch (RuntimeException error) {
  producer.abortTransaction();
  throw error;
}
properties
isolation.level=read_committed
sql
BEGIN;

WITH accepted AS (
    INSERT INTO consumer_inbox (consumer_name, event_id)
    VALUES ('billing', :event_id)
    ON CONFLICT DO NOTHING
    RETURNING 1
)
UPDATE invoices
SET status = 'PAID'
WHERE id = :invoice_id
  AND EXISTS (SELECT 1 FROM accepted);

COMMIT;

Red Flags:


Q4 — Consumer group rebalancing and poison records

Question: Consumers rebalance often, and one invalid record blocks a partition. Explain the causes and how you would handle both problems.

Expected Depth:

Ideal Answer:

java
@Bean
DefaultErrorHandler errorHandler(KafkaTemplate<?, ?> template) {
    var recoverer = new DeadLetterPublishingRecoverer(template);
    var backoff = new ExponentialBackOffWithMaxRetries(3);
    backoff.setInitialInterval(1_000L);
    backoff.setMultiplier(2.0);
    backoff.setMaxInterval(10_000L);
    return new DefaultErrorHandler(recoverer, backoff);
}
properties
spring.kafka.consumer.value-deserializer=\
org.springframework.kafka.support.serializer.ErrorHandlingDeserializer
spring.kafka.consumer.properties.spring.deserializer.value.delegate.class=\
org.springframework.kafka.support.serializer.JsonDeserializer

Red Flags:


Architect

Q5 — Saga vs Outbox: distributed transactions across services

Question: An order flow spans Order, Payment, and Inventory services with separate databases. There's no distributed 2PC. As architect, design reliable cross-service consistency.

Expected Depth:

Ideal Answer:

sql
BEGIN;

INSERT INTO orders (id, status)
VALUES (:order_id, 'PENDING');

INSERT INTO outbox (event_id, aggregate_id, event_type, payload)
VALUES (:event_id, :order_id, 'OrderCreated', :payload);

COMMIT;

Red Flags:


Q6 — Event-driven architecture, schema evolution, and governance

Question: Events are becoming the platform's integration backbone across many teams. Design for schema evolution, compatibility, and governance so producers and consumers can evolve independently.

Expected Depth:

Ideal Answer:

json
{
  "name": "discountCode",
  "type": ["null", "string"],
  "default": null
}
proto
message Payment {
  reserved 4;
  string payment_id = 1;
  int64 amount_minor = 2;
  string currency = 3;
}

Red Flags:


Scoring Rubric

Level Pass bar
JuniorExplains Kafka's basic model and uses producers and consumers correctly.
SeniorExplains delivery trade-offs and handles failures without losing correctness.
ArchitectDefines reliable event contracts, workflows, governance, and operational controls.