The parts of a cluster
TrapKafka 4.x has no ZooKeeper. It runs only in KRaft mode.
Asked in interviews
AskedExplain the core components of Kafka architecture.TrapKafka 4.x has no ZooKeeper. It runs only in KRaft mode.
Asked in interviews
AskedExplain the core components of Kafka architecture.batch.size bytes.TrapAdding partitions can move a key to another partition.
Asked in interviews
AskedWhat is a Kafka topic and how does partitioning work?max(t/p, t/c), with target t and one partition's producer rate p and consumer rate c.TipEach partition must fit on one broker. Very high counts cost file handles, metadata and recovery time.
TrapYou can never reduce the count. Raising it remaps keys, which breaks per-key order for existing keys.
Asked in interviews
AskedHow do you choose the number of partitions for a Kafka topic?TrapKafka never pushes records. Consumers pull them.
kafka-topics.sh --bootstrap-server localhost:9092 --listkafka-topics.sh --create --topic t --partitions 6 --replication-factor 3kafka-topics.sh --describe --topic tkafka-console-consumer.sh --topic t --from-beginningkafka-topics.sh --alter --topic t --partitions 12kafka-topics.sh --delete --topic tTipEvery tool needs --bootstrap-server. The other rows on this sheet leave it out to stay short.
Asked in interviews
AskedWhat is a Kafka topic and how does partitioning work?record.headers().add("trace-id", bytes)TipHeaders don't affect partitioning.
Asked in interviews
AskedWhat are Kafka Headers and when would you use them?acks=0Send without waiting for any brokeracks=1Wait for the leader onlyacks=allWait for every in-sync replica (default)Trapacks=1 turns off default idempotence. A record is lost if the leader fails before the followers copy it.
Asked in interviews
AskedExplain Kafka producers and their key configurations.linger.ms=5batch.size=65536 delivery.timeout.ms=120000 Trapmax. above 1 can reorder retried batches when idempotence is off.
Asked in interviews
AskedExplain Kafka producers and their key configurations.compression.type=lz4 compression.type=zstd compression.type=gzip gzip uses more CPU.compression.type=snappy TrapIf a topic sets a different compression., the broker recompresses every batch. That costs CPU.
Asked in interviews
AskedExplain Kafka's compression and its trade-offs.group.id=billing group.id, so each keeps its own offsets.TrapTwo apps in one group each read only part of the topic.
Asked in interviews
AskedHow do Kafka consumers work and what is a consumer group?consumer.poll(Duration.ofMillis(100)) poll() returnsmax.poll.records=500 fetch.min.bytes=50000 fetch.max.wait.ms=500 TipA fetch is the network request under poll(). KafkaConsumer has no public fetch() method.
Trapmax. limits one poll(), not fetching. The consumer caches fetched records.
Asked in interviews
AskedWhat is the difference between poll and fetch in a Kafka consumer?auto.commit.interval.ms=5000 consumer.commitSync() consumer.commitAsync() Set enable.auto.commit=false first.auto.offset.reset=earliest The default is latest.kafka-consumer-groups.sh --reset-offsets --to-latest --group g --topic tThis previews. Add --execute with the group stopped. --to-earliest replays.TipYou commit the offset of the next record to read.
TrapCommit before processing and a crash loses messages. Commit after processing and a crash repeats them.
Asked in interviews
AskedWhat is offset management in Kafka?__consumer_offsets A compacted internal topic, holding the latest offset per group and partition.offsets.retention.minutes=10080 After 7 days by default.TrapNever add partitions to this topic. Each group maps to one partition, and a new count breaks that mapping.
Asked in interviews
AskedWhat is the purpose of the __consumer_offsets topic?RangeAssignorCooperativeStickyAssignor group.protocol=consumer No member has to wait for the others to rejoin.group.instance.id=app-1 It must return before the session timeout.TipA rebalance starts when a member joins, leaves or crashes, or when a subscribed topic gains partitions.
TrapA consumer past max. between polls leaves the group, even with live heartbeats.
kafka-consumer-groups.sh --describe --group gTipLag is the latest offset minus the consumer's current offset. The records-lag-max metric reports it.
Asked in interviews
AskedWhat causes consumer lag and how do you address it?RecordDeserializationException and seek past its offset.TipConsumer groups have no built-in dead letter queue, so you build it.
TrapSkipping breaks per-key order. When order matters, pause the partition and alert.
Asked in interviews
AskedHow do you handle poison messages in a Kafka consumer?--replication-factor 3 at creation. The count includes the leader.replica.lag.time.max.ms=30000 It must heartbeat and reach the log end within this time.TipKafka measures follower lag only in time. The old replica. setting no longer exists.
Records up to the high watermark are on every in-sync replica, and consumers can read them. A leader failure can lose the rest.
min.insync.replicas=2 acks=allunclean.leader.election.enable=true Off by default. It can lose committed data.TrapIf the ISR drops below min., acks=all writes fail with Not. Strong consistency costs availability.
Asked in interviews
AskedWhat are Kafka's consistency guarantees?acks=0At-most-once. Commit before processing.acks=allAt-least-once, the default. Commit after processing.transactional.id=app-1 Exactly-once, with read_committed consumers.TrapExactly-once covers reads and writes on Kafka topics. A write to an outside database needs its own idempotent handling.
Asked in interviews
AskedWhat are Kafka's delivery semantics?enable.idempotence=true The broker checks a producer ID and a sequence number.processing.guarantee=exactly_once_v2 transactional.id . Brokers reject the old instance's writes and commits.Tipread_committed hides aborted and unfinished records. The default, read_, returns everything.
TrapA fenced producer can't abort, so close it on a fatal error. On any other error, abort and retry.
read_committed consumers.TipThe idempotent producer, on by default since 3.0, stops the duplicates that retries cause.
TrapAn in-memory set of seen IDs works only in one process, and a restart loses it.
Asked in interviews
AskedHow do you handle duplicate messages in Kafka?log.retention.hours=168 log.retention.bytes=10737418240 cleanup.policy=compact,delete Tipdelete is the default cleanup.policy. A segment is 1 GB by default.
TrapRetention removes whole segments by age or size, whether or not anyone has read them.
Asked in interviews
AskedWhat are Kafka's log retention and cleanup policies?cleanup.policy=compact delete.retention.ms=86400000 Send a tombstone, that key with a null value. The cleaner removes it after this time.TipUse it for changelog topics and Streams state stores.
TrapThe cleaner never compacts the active segment, so older values of a key can stay readable for a while.
Asked in interviews
AskedExplain Kafka's log compaction feature.remote.log.storage.system.enable=true remote.storage.enable=true local.retention.ms=86400000 retention.ms still sets the total.TipLong retention gets cheaper, and storage grows without new brokers.
TrapKafka ships no remote storage implementation, so you plug one in. Compacted topics aren't supported.
Asked in interviews
AskedWhat is tiered storage in Kafka, and what problem does it solve?TrapA cluster still in ZooKeeper mode must migrate to KRaft before it upgrades to 4.x.
broker.session.timeout.ms , and in-sync replicas take over.TipKafka favours consistency. It may stop taking writes during a network partition.
Asked in interviews
AskedHow does Kafka handle network partitions and split-brain scenarios?kafka-features.sh only after all are done.TrapKafka 4.0 removed old protocol versions. 4.x Java clients and brokers need the other side on 2.1 or later.
Asked in interviews
AskedWhat is Kafka's approach to backward compatibility?sendfile sends it straight to the network.TipBatches and compression shrink each request. A fully committed write takes about 10 ms.
TrapTLS stops zero-copy, because encryption runs in user space.
Asked in interviews
AskedHow does Kafka ensure high throughput?batch.size=65536 linger.ms=20compression.type=lz4 batch.size=0linger.ms=0num.network.threads=8 num.io.threads=16 Asked in interviews
AskedHow do you tune Kafka for maximum performance?UnderReplicatedPartitions OfflinePartitionsCount ActiveControllerCount RequestHandlerAvgIdlePercent TipBrokers and clients expose metrics through JMX.
Asked in interviews
AskedHow do you monitor Kafka cluster performance?TrapDon't rely on topic auto-creation. It applies broker defaults.
Asked in interviews
AskedWhat are some common Kafka anti-patterns to avoid?sasl.mechanism to SCRAM-SHA-512. Run PLAIN only over TLS.GSSAPI for Kerberos or OAUTHBEARER for OAuth 2.kafka-acls.sh --add --allow-principal User:a --operation Read --topic tTrapOnce authorizer. is set, a resource with no ACLs is open only to super users.
Asked in interviews
AskedExplain Kafka's security features.security.protocol=SSL TipA client adds a truststore to verify the broker, and a keystore only for mutual TLS.
TrapDisk encryption protects a stolen disk. Any client allowed to read the topic still sees plain data.
builder.stream("in").filter(f).to("out") TipKafka Streams is a library inside your Java or Scala app, so it needs no separate cluster.
Asked in interviews
AskedWhat is Kafka Streams and when would you use it?orders from us-west becomes us-west.orders.TipMirrorMaker 2 runs on Connect. Use it for disaster recovery, data locality, migration and compliance.
TrapKafka 4.0 removed the original MirrorMaker.
TipA Schema Registry enforces the rule. Add only optional fields, with defaults.
TrapDon't remove required fields.
Asked in interviews
AskedHow do you handle schema evolution in Kafka?retention.ms=-1TipA CQRS read just after a write may not show it, because the query side is eventually consistent.
TrapDon't compact the event topic. Put snapshots in a separate compacted topic.
Nothing matches. Try a shorter word, or clear the search.
With Pro, you can:
Already have Pro? Sign in