← All topics
Start ▶
Kafka and messaging
Topics, partitions, consumer groups and delivery guarantees.
100 questions
Level:
No questions match — try other words or turn a level back on.
1
What is Kafka, and how is it different from a regular message queue?
Kafka is a distributed log written to disk. A message isn't deleted after it's read; it stays until the retention period ends, so several systems can read it independently, as many times as they like.
2
Explain topics and partitions with a simple example.
A topic is a named stream of messages, for example payments. A partition is a slice of a topic; each partition is a separate ordered log that can live on a different broker and be read in parallel.
3
What does an offset mean in Kafka?
An offset is the sequence number of a message within a partition (0, 1, 2...). The consumer group commits the offset it has processed up to and continues from there after a restart.
4
What are a Kafka broker and a cluster, and how are they related?
A broker is a single Kafka server process; it stores partitions on disk and answers requests. A cluster is several brokers working together; partitions and their copies are distributed across them.
5
What decides which partition a producer sends a message to?
If the message has a key, the partition is chosen by the hash of the key, so the same key always lands in the same partition. Without a key, the default partitioner spreads messages across partitions (in newer versions, in a sticky way).
6
What is a consumer group for?
A consumer group is a set of consumers that act as one logical reader. Inside the group, partitions are divided among the consumers, so each message is delivered to only one consumer of the group.
7
How many consumers in one group can read the same partition at the same time?
Only one. Within a group a partition is assigned to exactly one consumer; a single consumer, on the other hand, can read several partitions.
8
Does Kafka delete a message after a consumer reads it?
No. Messages are deleted by the retention policy, either by time (retention.ms, 7 days by default) or by size (retention.bytes). Whether anyone has read them doesn't matter.
9
What is the replication factor, and what do you usually set it to on prod?
The replication factor is how many brokers hold a copy of each partition. On prod it's usually 3: even if one broker goes down, no data is lost and the topic keeps working.
10
What do the leader and follower replicas of a partition do?
The leader is the replica the producer writes to and (by default) the consumer reads from. Followers keep copying data from the leader, and if the leader goes down, one of them becomes the new leader.
11
What is the key of a Kafka message for, and can you leave it null?
The key does two things: it sends messages with the same key to the same partition to preserve order, and in compacted topics it says which object the "latest value" belongs to. If you don't need ordering, you can leave it null.
12
When does the auto.offset.reset setting apply, and what's the difference between earliest and latest?
It only applies when no committed offset is found for the consumer group: a new group, or an offset that has been deleted by retention. earliest starts from the beginning of the partition, latest only from messages that arrive from now on.
13
How do you send a message to Kafka from a Spring Boot application?
Once you add spring-kafka, Spring Boot creates a KafkaTemplate automatically. You inject it and call send(topic, key, value); the result comes back as a CompletableFuture.
14
What does the @KafkaListener annotation do under the hood?
Spring creates a listener container for each @KafkaListener. The container calls poll() in its own thread, deserializes the records, passes them to your method, and commits the offset depending on the configuration.
15
What do the serializer and deserializer do in Kafka?
Kafka only knows byte arrays. The serializer turns a Java object into bytes on the way out, and the deserializer rebuilds the object from bytes on the consumer side. Key and value are configured separately.
16
What do the values 0, 1 and all of the producer's acks setting mean?
Speed / Can the message be lost? — 0: fastest / yes, you won't even know if it's lost on the network; 1: medium / yes, if the leader writes it and crashes before the followers get it; all: slower / no (if min.insync.replicas is set correctly)
17
When does Kafka guarantee message ordering?
Only within a single partition. Messages written to one partition are read in that same order; there is no guarantee of a global order across the whole topic.
18
When do you really need Kafka in a project, and when is a plain REST call enough?
Use Kafka when several services need to receive the same event independently, when you need to buffer an event stream, or when you need to replay history. For a plain request-response where you need an answer right away, REST is simpler and the better fit.
19
What's the difference between ZooKeeper and KRaft?
Old Kafka clusters kept their metadata (brokers, topics, leaders) in ZooKeeper. In KRaft mode Kafka's own controllers do this job using the Raft protocol, and ZooKeeper isn't needed. ZooKeeper was removed completely in Kafka 4.0.
20
What parts does a Kafka record consist of?
Each record has a key, value, headers and timestamp; on the broker it is placed by partition and offset. Key and value are byte arrays, and headers are key-value pairs for extra metadata.
21
What problems can you run into with enable.auto.commit=true?
Auto-commit commits offsets on a timer (every 5 seconds by default) and doesn't care whether the message has actually been processed. As a result, after a crash messages can be lost or delivered again.
22
What's the difference between `commitSync()` and `commitAsync()`, and when do you use each?
commitSync() waits for the broker's response and retries on its own after a transient error, but it blocks the thread. commitAsync() doesn't wait and doesn't retry. The usual pattern: commitAsync() in the loop, commitSync() on shutdown and on rebalance.
23
What happens to keyed messages if you add partitions to a topic that's already running?
The partition for a key is computed as hash % number_of_partitions, so when the number changes, many keys move to a different partition. Old messages stay where they are and new ones go elsewhere, so ordering by key is temporarily broken.
24
Explain the difference between at-most-once, at-least-once and exactly-once delivery.
At-most-once means a message can be lost but is never repeated. At-least-once means it isn't lost but can be repeated. Exactly-once means the effect of each message happens once; Kafka gives you this only under certain conditions.
25
Where is the bug in this listener code that leads to lost messages?
The listener hands the work off to another thread and returns immediately. The container treats that as "processed successfully" and commits the offset; if the background work fails or the pod goes down, the message never comes back.
26
What is consumer lag, and how do you monitor it?
Lag is the difference between the partition's latest offset and the offset the consumer group has committed, in other words the number of messages not yet processed. If it keeps growing, the consumer can't keep up with the write rate.
27
How can a "poison pill" message that can't be deserialized stop a consumer?
If the deserializer fails, the message never reaches the listener and the offset doesn't move forward; the consumer hits the same message on every poll and gets stuck in an endless loop. In Spring the fix is ErrorHandlingDeserializer and a DLT.
28
If two different consumer groups read the same topic, are messages split between them?
No. Each group receives all the messages in the topic for itself and keeps its own offsets independently. Messages are split only among the consumers inside a single group.
29
What is log compaction, and when is it used?
In a compacted topic, Kafka keeps only the latest value for each key and cleans up older ones in the background. It's for cases where you need the "current state of each object": settings, user profiles, rebuilding a cache.
30
What is the main difference between RabbitMQ and Kafka, and when do you pick each?
RabbitMQ / Kafka — Model: push, the broker delivers / pull, the consumer fetches; After the ack: the message is deleted / stays according to retention; Routing: exchanges: direct, topic, fanout, headers / only topic + partition; Ordering: within a queue, but parallel consumers break it / strict within a partition…
31
When does a rebalance start in a consumer group, and how does it affect the work?
A rebalance is the redistribution of the group's partitions among the consumers. It starts when a consumer joins, leaves, stops sending heartbeats, is too slow to poll, or when partitions are added to a topic. With the eager protocol the whole group stops reading during it.
32
The consumer log says "max.poll.interval.ms exceeded" and messages keep coming again and again. What's going on and how do you fix it?
The listener can't process the messages from one poll within max.poll.interval.ms (5 minutes by default). The consumer is removed from the group, the offset isn't committed, the partition moves to another consumer, and the same messages are processed again.
33
How do you configure retries in Spring Kafka when a listener throws an error?
Spring Kafka 2.8+ uses DefaultErrorHandler: you give it a BackOff (for example FixedBackOff or ExponentialBackOff), and a recoverer is called when the attempts run out. Errors where retrying is pointless can be excluded with addNotRetryableExceptions.
34
What is a dead letter topic (DLT), and what do you do with the messages that end up there?
A DLT is a separate topic where messages go when they still haven't been processed after all the retries. The main processing doesn't stop, and the problem messages aren't lost; they can be analyzed later and resent.
35
How do you write a consumer so that the result isn't corrupted if a message arrives twice?
Make the consumer idempotent: store each event's unique ID and recognize a repeat, or make the operation naturally repeatable (upsert, "set the state"). At-least-once is the norm in Kafka, so a duplicate is an expected case.
36
How do the AckMode types in Spring Kafka differ, and when do you need MANUAL?
When it commits — BATCH: after the whole poll result is processed (default); RECORD: after each record: many commits, slower; TIME / COUNT: by time or by count; MANUAL: after acknowledge(), batched, before the next poll; MANUAL_IMMEDIATE: as soon as acknowledge() is called
37
What does the concurrency parameter of @KafkaListener do, and how do you choose it?
concurrency sets how many consumer threads (each a separate KafkaConsumer) run inside one application. The total number of consumers = pods × concurrency, and it shouldn't exceed the partition count.
38
How do the producer's linger.ms and batch.size settings affect throughput?
The producer collects messages into per-partition batches before sending. batch.size is the maximum batch size (in bytes), and linger.ms is how long to wait for a batch to fill. Waiting a little makes batches bigger and raises throughput, but it increases the latency of each message.
39
In Spring Kafka, what do you do when JSON messages from another service fail with a "class not found" or "not in trusted packages" error?
By default JsonSerializer writes the class name into the __TypeId__ header, and JsonDeserializer looks up the class by that name. The consumer doesn't have that package, or it isn't trusted. The fix is to give the target type explicitly instead of relying on the header, or to configure type mapping.
40
How do you test code that works with Kafka in an integration test?
There are two main ways: Spring's @EmbeddedKafka (a broker inside the JVM) and a real Kafka container with Testcontainers. Testcontainers is closer to prod; embedded starts faster and doesn't need Docker.
41
How does the idempotent producer work internally, and which duplicates does it protect against?
The broker gives each producer a PID, and the producer sends batches for each partition with a sequence number. If the broker sees a sequence it has already written, it returns "OK" without writing it again. It removes only the duplicates caused by producer retries.
42
acks=all is set, but a message was still lost when a broker went down. What role does min.insync.replicas play here?
acks=all waits only for the replicas currently in the ISR. If only the leader is left in the ISR, "all" means a single copy. With min.insync.replicas=2, the broker rejects writes when the ISR shrinks, so a message never ends up on just one copy.
43
What is unclean leader election, and what's the risk of turning it on?
Unclean election means making an out-of-sync follower the leader when no live replica is left in the ISR. The partition recovers faster, but the messages that follower hadn't written are lost for good, and consumer offsets can get confused.
44
What's the difference between eager and cooperative (incremental) rebalancing, and how do you enable it in a Spring application?
In eager, when a rebalance starts every consumer gives up its partitions and the whole group stops. In cooperative, only the partitions that must move to another consumer are given up, and the rest keep being read.
45
What problem does static membership (group.instance.id) solve?
Normally when a consumer restarts, it leaves the group and comes back as a new member, which causes two rebalances. With group.instance.id, the broker recognizes it as the same member, and if it returns within session.timeout.ms, no rebalance happens at all.
46
Why do you need a Schema Registry, and what do backward compatibility rules forbid in schema evolution?
Schema Registry stores Avro/Protobuf/JSON schemas centrally; only a small schema ID travels in the message. When a new version is registered, compatibility is checked: in BACKWARD mode, a new consumer must be able to read old messages.
47
How does non-blocking retry with @RetryableTopic work, and what does it cost?
A message that fails is sent with a delay to separate retry topics (-retry-0, -retry-1...), while the main partition moves on to the next messages. Processing doesn't stall, but the order for a single key is broken.
48
How do Kafka transactions work in a read-process-write chain, and why is isolation.level needed?
A transactional producer writes to several topics and commits the consumer offsets in one atomic transaction. With isolation.level=read_committed on the consumer side, only messages from committed transactions are visible, and aborted ones are skipped.
49
What's wrong with code that writes to the database and then sends an event to Kafka, and how does the outbox pattern fix it?
This is a "dual write": if the DB commits and sending to Kafka fails, the event is lost; if you swap the order, the event goes out and the DB rolls back. With an outbox, the event is written to a table in the same DB transaction, and a separate process delivers it to Kafka.
50
How can message order break when the producer retries, and how does max.in.flight.requests.per.connection relate to it?
If several requests are in flight on one connection without a response, and the first fails and is resent, the second gets written before it. Without idempotence you had to set in-flight to 1 to keep order; with idempotence enabled, up to 5 is safe.
51
How do you rewind a consumer to a specific offset or point in time: when do you need `seek()`, `offsetsForTimes()` and `--reset-offsets`?
In code I move a partition to any offset with seek(), and to rewind by time I first find the offset with offsetsForTimes(). To rewind a whole group I use kafka-consumer-groups.sh --reset-offsets, but that only works while the group is stopped.
52
`kafkaTemplate.send()` is supposed to be asynchronous, but on prod HTTP requests hung on it for 60 seconds. How can that happen?
send() blocks the calling thread in two cases: when the topic metadata isn't available yet, and when the producer buffer (buffer.memory) is full. In both, the wait is capped by max.block.ms (60 s by default), after which a TimeoutException is thrown.
53
What is the `__consumer_offsets` topic, and how is the group coordinator chosen?
Committed offsets and group metadata are stored in the internal, compacted __consumer_offsets topic (50 partitions by default). The hash of group.id picks one of these partitions, and the leader broker of that partition becomes the group's coordinator.
54
You need to connect to prod Kafka with TLS and SASL/SCRAM. How do you configure that in a Spring Boot application, and where do people usually go wrong?
You set security.protocol=SASL_SSL, sasl.mechanism=SCRAM-SHA-512 and the login through sasl.jaas.config, and give a truststore for TLS. Passwords come from secrets, not from the code; the producer, consumer and admin client must all get the same settings.
55
What is the ISR, and when does a replica drop out of it?
The ISR is the list of replicas considered in sync with the leader. If a follower doesn't catch up to the leader's end within replica.lag.time.max.ms (30s by default), it's removed from the ISR.
56
Where are messages compressed in Kafka, which codec would you pick, and what does `compression.type` on the broker affect?
Compression is done on the producer, per whole batch; the message stays compressed on the broker and on disk, and the consumer decompresses it. I usually pick lz4 or zstd. If compression.type on the broker or topic differs from the producer's, the broker recompresses and burns CPU.
57
What are Kafka record headers for, and how do you write and read them in Spring Kafka?
Headers are key-value pairs (the value is a byte[]) added to a message without touching the payload. They carry technical metadata such as a trace ID, event type, tenant or schema version; Spring also keeps __TypeId__ and DLT information in headers.
58
Consumer lag keeps growing. How do you investigate, and what do you do?
First I look at which partitions the lag is growing on: all of them or just one. If it's all of them, the consumer is slow or there aren't enough of them; if it's one, it's a hot key or a stuck consumer.
59
What happens to a failing message with this Spring Kafka configuration?
The message is retried 3 times, 1 second apart (4 attempts in total), then it's sent to the orders.DLT topic with the same partition number and the offset is committed. An IllegalArgumentException goes straight to the DLT without retries.
60
What do the consumer's `fetch.min.bytes`, `fetch.max.wait.ms`, `max.partition.fetch.bytes` and `max.poll.records` control, and when do you change them?
The first three control how data is pulled from the broker (how long to wait, how much), while max.poll.records only controls how many records a single poll() returns to the application. For throughput I increase the fetch sizes; if I have a poll timeout problem, I decrease max.poll.records.
61
How does creating topics in code (`NewTopic`, `TopicBuilder`) work in a Spring Boot application, and is it a good idea on prod?
If the context has NewTopic beans, KafkaAdmin creates the missing topics at startup, and even increases the partition count if it's too low. It's handy for dev and test, but on prod topics are usually managed through GitOps or by a platform team, and the application only checks.
62
What is Kafka Connect, and when do you use it instead of your own producer/consumer code?
Kafka Connect is a ready-made framework for moving data between Kafka and external systems (DBs, S3, Elasticsearch): a source connector writes to Kafka, a sink connector reads from Kafka. If there's no business logic and you only need "copy from A to B", configuring a connector is cheaper than writing code.
63
One topic carries several event types (`OrderCreated`, `OrderPaid`, `OrderCancelled`). How do you receive them in Spring Kafka?
I put @KafkaListener at the class level and a separate @KafkaHandler method for each type; Spring calls the right method based on the payload type. For that, the deserializer must know the exact Java type, through a type header or type mapping.
64
What does rack awareness (`broker.rack`, `client.rack`) give you in Kafka?
If broker.rack is set, Kafka places a partition's replicas in different racks or zones, so even if one zone goes down, each partition still has a copy. With client.rack and the rack-aware selector on the broker, a consumer can read from a follower in its own zone and cross-AZ traffic drops.
65
The producer log shows `TimeoutException: Expiring 15 record(s) ... has passed since batch creation`. What is it, and which settings are involved?
The batch wasn't delivered to the broker within delivery.timeout.ms (2 minutes by default) and the producer dropped it. It shows up as an error in the send() callback; if you don't check it, the message silently disappears. The cause is usually on the broker or network side.
66
How is a Kafka partition stored on disk: how do segments, indexes and retention work?
A partition is a directory containing segment files (.log) and their offset and time indexes. Retention deletes whole segments, not individual messages.
67
Where does the timestamp on a Kafka message come from, what's the difference between `CreateTime` and `LogAppendTime`, and what does a wrong timestamp break?
By default it's CreateTime, where the producer sets the time; with LogAppendTime the broker sets the time it wrote the message. Timestamps are used by retention, offsetsForTimes() and Kafka Streams windows, so a wrong producer clock or a deliberately old or future time throws these mechanisms off.
68
What is a "zombie" instance in a transactional producer, how do `transactional.id` and the epoch stop it, and how do you choose `transaction-id-prefix` in Spring?
A zombie is an old producer that hung, got replaced by a new one, and then "woke up" and kept writing. When a new producer with the same transactional.id calls initTransactions(), the coordinator bumps the epoch, and the old one gets a ProducerFencedException. In Spring the prefix must be unique per instance.
69
In a batch listener, what happens if record 237 out of 500 fails?
If you throw a plain exception, Spring doesn't know which record failed and resends the whole batch. If you point to the index with BatchListenerFailedException, the earlier ones are committed and only that record goes to retry or the DLT.
70
What happens when a message is redelivered in RabbitMQ, and how is that different from rewinding the offset in Kafka?
In RabbitMQ an unacked message goes back to the queue and can be sent to another consumer, while the rest of the messages keep moving. In Kafka it's not the message but the offset pointer that goes back: the partition is re-read from that point, and the following messages wait too.
71
How does a state store work in Kafka Streams: changelog topic, restore and standby replicas? What do you do if a restore takes 40 minutes on prod?
State lives in local RocksDB, and every change is also written to a compacted changelog topic. If a task moves to another instance, the state is restored from the changelog, which takes a long time for a big state. Standby replicas, persistent disks and static membership cut this time sharply.
72
How much data should you put in an event: only the ID (a "thin" event) or the full state (a "fat" event)? How do you choose?
A thin event is small and doesn't carry sensitive data, but consumers call back to the producer for details, which brings load and race conditions. A fat event makes consumers independent and makes replay easier, but the contract grows. I usually put the needed state in the event, but not everything.
73
When should you store consumer offsets in your own DB together with the result instead of in Kafka, and how do you do it?
Where the result is written to a DB and a duplicate is expensive, storing the offset in the same DB transaction makes processing and "where have I read up to" atomic. When a partition is assigned, the consumer reads the offset from the DB and starts from there with seek(); the commit to Kafka remains only for monitoring.
74
How do you choose the partition count for a new topic?
I divide the required throughput by the measured throughput of a single consumer and add headroom for 2-3 years of growth. But too many partitions are expensive too: more files, slower failover, longer rebalances.
75
When you deploy a service with a Kafka consumer and producer, how do you configure graceful shutdown so messages aren't lost and duplicates are minimal?
When the pod gets SIGTERM, the listener containers must finish the current batch, commit the offset and stop, and the producer must manage to send what's in its buffer. For that, the Kubernetes grace period has to be longer than the timeouts inside the application, and the processing code must stop through the Spring lifecycle, not in @PreDestroy.
76
You need delayed jobs like "cancel the order if it isn't paid after 30 minutes". Kafka doesn't support delayed messages. How do you design it?
Kafka has no "deliver this message in 30 minutes" feature. If the delays are few and fixed, delay topics work (the consumer pauses the partition until the time comes); for varied and cancellable deadlines I prefer a scheduled-jobs table in the DB.
77
One partition is getting far too much load (a hot partition). How do you find the cause and what do you do?
The cause is usually an uneven key distribution: one big customer, or a null/constant key. The fix depends on changing or "salting" the key, but each option gives up the ordering guarantee to some degree.
78
On prod, a consumer group rebalances every few minutes. How do you investigate?
First I find out who is starting the rebalance: is the consumer leaving on its own (poll interval exceeded), are heartbeats not arriving (session timeout, GC), or are pods restarting. The logs, the consumer metrics and the group coordinator logs on the broker give the answer.
79
The external service your consumer calls slowed down or went down. How do you handle backpressure in a Kafka consumer?
Kafka works on a pull model, so the simplest backpressure is polling less. When the downstream fails, I pause() the partitions, keep polling, and resume() when it recovers; in Spring that's done by pausing the container or with a circuit breaker.
80
The events of one order must be processed in strict order, but there are occasional transient errors. How do you design the retry?
If you need ordering at the key level, plain non-blocking retry doesn't work. The options: blocking retry (the whole partition waits), or "stopping the key", which means queueing a failed key's later events too until it recovers, or making the consumer tolerant of versions.
81
A user creates an order and doesn't see it in the list, because the read model is updated late through Kafka. How do you solve the "read-your-writes" problem at the architecture level?
First I find out where you really need strong consistency, which is often only for the user who just wrote. Then I choose a solution: return the result in the write response, wait until the read model has caught up using a version or offset, or have that user read from the write database for a short time.
82
How do you set up Kafka across two data centers: a stretched cluster or replication? What's hard in active-active?
With low latency (zones in one region), a single stretched cluster with rack awareness is the simplest and gives RPO=0. Between distant DCs you use two separate clusters and MirrorMaker 2 or Cluster Linking; that's asynchronous, so on failover you can lose a little data and have to deal with translating offsets.
83
Dozens of teams use one Kafka platform. What rules do you set for topics, event contracts and ownership?
Every topic needs a clear owner (the producing team), a naming convention, a mandatory schema in the schema registry and a compatibility mode. Topic creation and ACLs go through code (GitOps), not by hand; otherwise after a year nobody knows what is for what.
84
Is it right to use Kafka as the main "source of truth" for event sourcing?
Kafka is good as an event log, but it has limits as an event store: you can't quickly read one aggregate's events by ID, and there's no optimistic check (expected version) on write. Usually the event store is a separate DB, and Kafka is used to distribute the events.
85
How do you plan the capacity of a new Kafka cluster?
I calculate disk, network and broker count from the incoming traffic, replication factor, retention and the number of consumers, then check that the remaining brokers can carry the load when one is lost. Often the bottleneck is the network, not the disk.
86
What does moving from ZooKeeper to KRaft give you, and how do you plan the migration?
KRaft stores metadata in Kafka's own Raft quorum: the separate ZooKeeper cluster goes away, controller failover gets faster and the partition limit goes up a lot. In Kafka 4.0 ZooKeeper mode is removed completely, so the migration is mandatory before moving to 4.x.
87
The business demands "every payment must be processed exactly once", and the chain has Kafka, a DB and an external bank API. How do you respond?
In a distributed system there's no "exactly-once delivery", but you can get an "exactly-once effect": at-least-once delivery plus idempotency at every stage. Kafka transactions cover only the part inside Kafka; for the DB and the bank API you need an idempotency key and dedup.
88
When many teams use one Kafka cluster (multi-tenant), what do you do so that one team doesn't interfere with the others?
Each team gets its own identity (SASL/mTLS), prefix-based ACLs and producer/consumer/request quotas. On top of that come topic-level limits and monitoring; moving very critical or very noisy workloads to a separate cluster is also an option.
89
What is tiered storage, and how does it change decisions about keeping data in Kafka for a long time?
Tiered storage (KIP-405; early access in Kafka 3.6, production-ready since 3.9) moves old segments to object storage like S3, leaving only the recent part on the broker's disk. Retention of months or years gets cheaper and adding or replacing brokers gets faster, but reading old data is slower.
90
A bug in a consumer produced wrong calculations for two weeks. How do you organize the reprocessing of events?
First I identify which effects the reprocessing would repeat: are the DB writes idempotent, are there external calls (email, payments). Then, often with a separate consumer group or a separate "replay" deployment, I read from the required time without stopping the main consumer, compare the results, and swap afterwards.
91
For stream processing, how do you choose between a plain consumer, Kafka Streams and Flink?
Plain consumer / Kafka Streams / Flink — Deploy: the service itself / the service itself (a library) / a separate cluster / operator; State: yours (DB) / local RocksDB + changelog topic / large state with checkpoints; Sources: Kafka / Kafka only / Kafka, CDC, files, DB...; Exactly-once: manual / exactly_once_v2 /…
92
To get events out of a DB, do you use a transactional outbox or direct CDC (Debezium on the tables), and why?
Doing CDC directly on tables exposes your internal DB schema to other teams: every column change breaks them. An outbox (with the Debezium outbox router) gives a clear, versioned event contract. I choose the outbox for public events and table CDC for internal replication and analytics.
93
How do you build an order process spanning several services as a saga on top of Kafka: choreography or orchestration?
In choreography each service reacts to another's event. It starts out simple, but as steps are added nobody sees the whole process. In orchestration a single orchestrator keeps the state and sends commands. With more than 3-4 steps and complex compensations, I choose orchestration.
94
You need to send large payloads (say, a 20 MB PDF or an image) through Kafka. How do you approach it?
Kafka isn't designed for big messages: the default limit is ~1 MB, and large messages slow down broker memory, replication and consumers. I use the claim check pattern: put the file in object storage and send only a reference and metadata to Kafka.
95
How do you trace requests that pass through Kafka end to end (tracing, lag SLOs, alerts)?
I pass the trace context in Kafka headers (OpenTelemetry/Micrometer does this automatically), measure lag both in message count and in time, and set alerts tied to the business SLO. In an asynchronous chain, a trace and an end-to-end latency metric answer "where did it get delayed?".
96
How do you build a disaster recovery plan for a Kafka cluster, and which failure scenarios do you consider?
I split the scenarios into levels: a single disk/broker, a whole zone, a whole region, and human error (a topic deleted, a wrong offset reset). Each needs an RPO/RTO target, a path to recovery (automatic or manual), and regular drills.
97
The current system runs on RabbitMQ and the decision was made to move to Kafka. How do you plan a zero-downtime migration?
Step by step, one flow at a time: first the producers write to both systems (or there's a bridge), the consumers move to Kafka one by one and the results are compared, and at the end the RabbitMQ path is removed. The main risks are semantic differences (ack, ordering, retry) and duplicates during the migration.
98
You have to make a breaking change in the contract of an event with many consumers. How do you roll it out?
I don't break the old topic in place; I release the new version in parallel (orders.v2 or a new event type), the producer writes both for a while, consumers move at their own pace, and v1 is shut down once the last one has moved. The key is knowing exactly who reads what.
99
How do you design event ordering for a bank ledger: is global ordering needed, or is per-entity enough? How do you choose the key?
Global ordering in Kafka is possible only with a single partition, and that kills scale; in fact it's rarely needed. Ordering per account is usually enough, with the key = accountId. For transfers that span two accounts, what you need isn't ordering but the transfer's own state machine and idempotent steps.
100
Should you use Kafka for synchronous request-reply? One team is proposing it instead of HTTP.
Technically it's possible (Spring has ReplyingKafkaTemplate), but it usually combines the drawbacks of both worlds: you keep HTTP's coupling and add Kafka's delay and complexity on top. Unless there's a specific reason, I'm against it.
Sign up — studied questions get marked and your progress is saved.