In this post we are going to cover Kafka fundamentals and architecture: what Kafka is, topics, partitions and offsets, how keys decide ordering, KRaft and what changed in Kafka 4, brokers and controllers, and replaying events. These are 7 real Kafka interview questions for data engineers, asked the way they come up on a real project, and the last one is a scenario where the business wants every order event available to five teams in near real time.
Kafka is a distributed event log. Applications write events to it, and any number of other applications read them, each at its own pace. Interviewers start here because every later Kafka question, from producers to exactly-once, builds on these few ideas. They also check whether your answer is current, because a lot of older material still says Kafka needs ZooKeeper.
Part 1 of the Real Time Kafka Interview Questions and Answers series on TechBrothersIT.
- The short answer
- Let's set up the cluster and some sample data
- Question 1: Your manager asks what Kafka is and why the team should not just use a database table or a queue. What do you say?
- Question 2: A new teammate asks how topics, partitions and offsets fit together. How do you explain it?
- Question 3: Orders for the same customer are processed out of order. How do keys and partitions decide ordering?
- Question 4: Someone says Kafka needs ZooKeeper. What is KRaft, and what changed in Kafka 4?
- Question 5: A teammate asks what a broker, a controller and a cluster are. How do they work together?
- Question 6: Consumers can read last week's events again. How is Kafka different from a traditional message queue?
- Scenario 7: The business wants every order event available to five teams in near real time. How would you design the topics?
- The full script
The short answer
Kafka is a distributed, replicated event log: a topic is split into partitions, every record gets an offset, and the key decides the partition, so order holds per key. Since 4.0 Kafka runs only in KRaft mode, where a controller quorum manages the metadata, and any number of consumer groups read and replay the same events within retention.
Let's set up the cluster and some sample data
We run a local Apache Kafka 4.4 cluster in KRaft mode with 3 nodes, and each node is both a broker and a controller. Here are the sample files: a producer that sends six orders keyed by customer, a script that sends one more order, a small reader we run with different group names, a file of order events, and a script that reads as five teams.
from confluent_kafka import Producer
p = Producer({'bootstrap.servers': 'localhost:9092'})
orders = [('c-101', 'order-1'), ('c-707', 'order-2'),
('c-101', 'order-3'), ('c-606', 'order-4'),
('c-707', 'order-5'), ('c-101', 'order-6')]
done = []
def report(err, m):
if err:
print('FAILED', m.value(), err)
return
done.append((m.partition(), m.offset(), m.key().decode(),
m.value().decode()))
for customer, order in orders:
p.produce('orders', key=customer, value=order, on_delivery=report)
p.flush()
for row in sorted(done):
print('partition %d offset %d key %s %s' % row)from confluent_kafka import Producer
p = Producer({'bootstrap.servers': 'localhost:9092'})
def report(err, m):
print(m.key().decode(), m.value().decode(), err or '',
'-> partition', m.partition(), 'offset', m.offset())
p.produce('orders', key='c-101', value='order-7', on_delivery=report)
p.flush()print.partition=true
print.offset=true
print.key=trueimport sys
from confluent_kafka import Consumer
group = sys.argv[1]
c = Consumer({'bootstrap.servers': 'localhost:9092', 'group.id': group,
'auto.offset.reset': 'earliest'})
c.subscribe(['orders'])
seen, idle = [], 0
while idle < 5: # stop after 5 quiet seconds
m = c.poll(1.0)
if m is None:
idle += 1
elif m.error():
raise SystemExit(m.error())
else:
seen.append(m.value().decode())
c.close() # commits the final offsets
print(group, 'read', len(seen), 'orders:', ' '.join(sorted(seen)))o-1001:created
o-1002:created
o-1001:paid
o-1001:shipped
o-1002:paid
o-1003:createdfrom confluent_kafka import Consumer
for team in ['billing', 'shipping', 'fraud', 'analytics', 'email']:
c = Consumer({'bootstrap.servers': 'localhost:9092',
'group.id': team + '-svc',
'auto.offset.reset': 'earliest'})
c.subscribe(['orders-v1'])
events, idle = [], 0
while idle < 5:
m = c.poll(1.0)
if m is None:
idle += 1
elif not m.error():
events.append(m.value().decode())
c.close()
print(f'group {team}-svc read {len(events)} events')Question 1: Your manager asks what Kafka is and why the team should not just use a database table or a queue. What do you say?
Kafka is a distributed event log. Applications publish events, like a new order, to a topic. Kafka writes them to disk, replicates them across brokers, and any number of consumers read them at their own pace.
Let's take the two alternatives one at a time.
First, a database table. Every team would poll the same table on a schedule, add load to the database, and track for itself what it already read.
Then a classic queue. There, each message goes to one consumer and is deleted once it is acknowledged. So a second team needs its own copy.
In Kafka, reading removes nothing. Each consumer group tracks its own offset, so five teams read the same stream, and they can replay it. And partitions spread a topic over brokers, so it scales out. Let's put the three side by side.
| Many readers | After a read | Replay | |
|---|---|---|---|
| Database table | all poll the same table | row stays | only if you keep history |
| Classic queue | one consumer per message | message is deleted | no, it is gone |
| Kafka topic | each group reads everything | kept until retention | reset the group offset |
On a real project I always add one thing: Kafka does not replace the database. The database stays the system of record that you query. Kafka moves its events to everyone who needs them.
Say "the database stays the system of record, Kafka moves the events". It shows you know where each one fits.
Question 2: A new teammate asks how topics, partitions and offsets fit together. How do you explain it?
A topic is a named stream of events, like orders. It is split into partitions, and each partition is an ordered, append-only log. Every record gets an offset, its position in its partition.
Let's see it. First we create orders with three partitions and run kafka-topics.sh --describe. The replicas are pinned with --replica-assignment, so the output repeats on every run.
$ kafka-topics.sh --bootstrap-server localhost:9092 --create --topic orders --replica-assignment 1:2:3,2:3:1,3:1:2
Created topic orders.
$ kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic orders
Topic: orders TopicId: <topic-id> PartitionCount: 3 ReplicationFactor: 3 Configs:
min.insync.replicas=1
Topic: orders Partition: 0 Leader: 1 Replicas: 1,2,3 Isr: 1,2,3 Elr: LastKnownElr:
Topic: orders Partition: 1 Leader: 2 Replicas: 2,3,1 Isr: 2,3,1 Elr: LastKnownElr:
Topic: orders Partition: 2 Leader: 3 Replicas: 3,1,2 Isr: 3,1,2 Elr: LastKnownElr:Describe shows each partition with its leader: partition 0 on broker 1, partition 1 on broker 2 and partition 2 on broker 3. By default, producers and consumers talk to the leader, and the other replicas copy it.
Now we send six orders with python producer.py. The delivery report tells us where each record landed.
$ python producer.py
partition 0 offset 0 key c-101 order-1
partition 0 offset 1 key c-101 order-3
partition 0 offset 2 key c-101 order-6
partition 1 offset 0 key c-707 order-2
partition 1 offset 1 key c-707 order-5
partition 2 offset 0 key c-606 order-4Partition 0 holds offsets 0 to 2, partition 1 holds two records and partition 2 holds one. Then kafka-get-offsets.sh shows the end offset of each partition, which is the offset the next record will get.
$ kafka-get-offsets.sh --bootstrap-server localhost:9092 --topic orders
orders:0:3
orders:1:2
orders:2:1We get orders:0:3, orders:1:2 and orders:2:1. A consumer reads by offset, so let's read partition 0 from offset 1 with the console consumer.
$ kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic orders --partition 0 --offset 1 --max-messages 2 --formatter-config show.properties
Partition:0 Offset:1 c-101 order-3
Partition:0 Offset:2 c-101 order-6We get offsets 1 and 2, order-3 and order-6. Consumer groups commit the next offset to read, so after a restart they continue from there.
Order is kept per partition, not per topic. And in a consumer group each partition goes to one consumer, so the partition count caps the parallelism.
Question 3: Orders for the same customer are processed out of order. How do keys and partitions decide ordering?
Kafka keeps order only inside a partition, so the fix is the key. The producer hashes the key to pick the partition, and here the key is the customer ID.
Let's look again at the output of producer.py from Question 2. All three orders of customer c-101 landed in partition 0, at offsets 0, 1 and 2, in the order they were sent. c-707 went to partition 1 and c-606 to partition 2.
Without a key, the producer spreads records over the partitions. One customer's orders then sit in different partitions, consumers read them in parallel, and the order is lost.
There is a catch: the mapping depends on the partition count. Let's grow orders to six partitions with kafka-topics.sh --alter, and then send one more order for c-101 with python one_more.py.
$ kafka-topics.sh --bootstrap-server localhost:9092 --alter --topic orders --partitions 6
$ python one_more.py
c-101 order-7 -> partition 3 offset 0The alter command prints nothing, and the new order lands in partition 3 offset 0. The older orders of c-101 stay in partition 0, so order-7 can be processed before order-6.
So key by the entity that needs order, like the customer ID or the order ID, and size the partitions up front. Retries can also reorder records, and the Python and Java clients hash keys differently. We cover both in Part 2.
Adding partitions later moves keys to new partitions. Existing records stay where they are, so ordering breaks right at the change.
Question 4: Someone says Kafka needs ZooKeeper. What is KRaft, and what changed in Kafka 4?
That is outdated. KRaft is Kafka's own consensus protocol, based on Raft: a quorum of controllers keeps the cluster metadata in a replicated log, with no ZooKeeper. KRaft was production-ready for new clusters in 3.3, and Kafka 4.0 removed ZooKeeper mode.
| Metadata lives in | You run | Status | |
|---|---|---|---|
| ZooKeeper mode | a separate ZooKeeper ensemble | Kafka and ZooKeeper | removed in Kafka 4.0 |
| KRaft mode | a Raft log on the controllers | Kafka only | the only mode since 4.0 |
Let's look at one of our nodes. We grep its config file and list its data folder.
$ grep -E 'roles|node.id|quorum|controller.listener' ../cluster/node1.properties
process.roles=broker,controller
node.id=1
controller.quorum.bootstrap.servers=localhost:9093,localhost:9095,localhost:9097
controller.listener.names=CONTROLLER
$ ls ../cluster/node1 | grep cluster_metadata
__cluster_metadata-0The node runs with process.roles=broker,controller, it has node.id=1, and it finds the quorum through controller.quorum.bootstrap.servers. The metadata log sits on disk in __cluster_metadata-0. Combined mode is fine for a lab, but for critical production we run dedicated controllers.
Now we ask kafka-metadata-quorum.sh for the quorum and keep only the stable lines.
$ kafka-metadata-quorum.sh --bootstrap-server localhost:9092 describe --status | grep -E 'ClusterId|CurrentVoters'
ClusterId: p1n057GhRYecMDp97v4mSA
CurrentVoters: [{"id": 1, "directoryId": "AI32SBvqTIeXkw9Yb8ODxg", "endpoints":
["CONTROLLER://localhost:9093"]}, {"id": 2, "directoryId": "E4DiDywxSBWUSd1q12wxTw", "endpoints":
["CONTROLLER://localhost:9095"]}, {"id": 3, "directoryId": "GZ79KsDxQ8yNEuHzEpQOuQ", "endpoints":
["CONTROLLER://localhost:9097"]}]The quorum has three voters, nodes 1, 2 and 3, and one of them is the active controller. A majority must be alive, so three controllers survive one failure, and five survive two.
What changed in Kafka 4:
- ZooKeeper is gone. A ZooKeeper cluster first moves to a bridge release, ideally 3.9, the last one, migrates its metadata to KRaft, finalizes, and only then rolls to 4.x.
- Brokers now need Java 17, and clients must be on version 2.1 or newer.
controller.quorum.voters is deprecated in favor of controller.quorum.bootstrap.servers and dynamic quorums, and in 4.4 broker.id is deprecated for node.id.
Question 5: A teammate asks what a broker, a controller and a cluster are. How do they work together?
A broker stores partitions and serves producers and consumers. A controller manages the metadata: which brokers are alive, and which replica leads each partition. The cluster is all of them, under one cluster ID. Here, three nodes run both roles.
Let's see them work together. First we create payments, replicated on all three brokers, and describe it.
$ kafka-topics.sh --bootstrap-server localhost:9092 --create --topic payments --replica-assignment 1:2:3,2:3:1,3:1:2
Created topic payments.
$ kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic payments
Topic: payments TopicId: <topic-id> PartitionCount: 3 ReplicationFactor: 3 Configs:
min.insync.replicas=1
Topic: payments Partition: 0 Leader: 1 Replicas: 1,2,3 Isr: 1,2,3 Elr: LastKnownElr:
Topic: payments Partition: 1 Leader: 2 Replicas: 2,3,1 Isr: 2,3,1 Elr: LastKnownElr:
Topic: payments Partition: 2 Leader: 3 Replicas: 3,1,2 Isr: 3,1,2 Elr: LastKnownElr:Each partition has one leader and two followers, and the leaders are spread over brokers 1, 2 and 3. Now we stop broker 2 and describe the topic again.
Now stop broker 2 (we stop that node of the cluster).
$ kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic payments
Topic: payments TopicId: <topic-id> PartitionCount: 3 ReplicationFactor: 3 Configs:
min.insync.replicas=1
Topic: payments Partition: 0 Leader: 1 Replicas: 1,2,3 Isr: 1,3 Elr: LastKnownElr:
Topic: payments Partition: 1 Leader: 3 Replicas: 2,3,1 Isr: 3,1 Elr: LastKnownElr:
Topic: payments Partition: 2 Leader: 3 Replicas: 3,1,2 Isr: 3,1 Elr: LastKnownElr:The active controller moved the leadership: partition 1 is now led by broker 3, and broker 2 dropped out of the in-sync replicas, the ISR. Every ISR is down to two brokers. Clients simply follow the new leader. Now we start broker 2 again.
Now start broker 2 again.
$ kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic payments
Topic: payments TopicId: <topic-id> PartitionCount: 3 ReplicationFactor: 3 Configs:
min.insync.replicas=1
Topic: payments Partition: 0 Leader: 1 Replicas: 1,2,3 Isr: 1,2,3 Elr: LastKnownElr:
Topic: payments Partition: 1 Leader: 3 Replicas: 2,3,1 Isr: 1,2,3 Elr: LastKnownElr:
Topic: payments Partition: 2 Leader: 3 Replicas: 3,1,2 Isr: 1,2,3 Elr: LastKnownElr:Broker 2 caught up from the leaders and rejoined the ISR, so every partition shows Isr: 1,2,3 again. Partition 1 stays on broker 3 for now.
Clients only need a few bootstrap servers. From there, they fetch the metadata and talk to each partition's leader directly.
In production I run at least three brokers, and dedicated controllers.
Question 6: Consumers can read last week's events again. How is Kafka different from a traditional message queue?
A traditional queue deletes a message once a consumer acknowledges it. Kafka keeps the log for the retention period, whether anyone read it or not.
Let's check the retention of orders with kafka-configs.sh.
$ kafka-configs.sh --bootstrap-server localhost:9092 --describe --topic orders --all | grep -E ' retention\.(ms|bytes)='
retention.bytes=-1 sensitive=false synonyms={DEFAULT_CONFIG:log.retention.bytes=-1}
retention.ms=604800000 sensitive=false synonyms={}retention.ms=604800000 is seven days, and retention.bytes=-1 means no size limit. That is the default.
Reading only moves the group's offset. Let's read with the billing group using python read.py billing, and then describe the group.
$ python read.py billing
billing read 7 orders: order-1 order-2 order-3 order-4 order-5 order-6 order-7
$ kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group billing
Consumer group 'billing' has no active members.
GROUP TOPIC PARTITION CURRENT-OFFSET LOG-END-OFFSET LAG CONSUMER-ID
HOST CLIENT-ID
billing orders 0 3 3 0 -
- -
billing orders 1 2 2 0 -
- -
billing orders 2 1 1 0 -
- -
billing orders 3 1 1 0 -
- -Billing read all seven orders, and its committed offset equals the log end offset in every partition it read, so the lag is 0. Now a new team starts its own group, fraud-model.
$ python read.py fraud-model
fraud-model read 7 orders: order-1 order-2 order-3 order-4 order-5 order-6 order-7It reads the same seven orders from the beginning. No copy, and nothing changes for billing.
A replay is just moving offsets. With its consumers stopped, we reset billing by duration, seven days back, and read again.
$ kafka-consumer-groups.sh --bootstrap-server localhost:9092 --reset-offsets --group billing --topic orders --by-duration P7D --execute
Warn: Partition 4 from topic orders is empty. Falling back to latest known offset.
Warn: Partition 5 from topic orders is empty. Falling back to latest known offset.
GROUP TOPIC PARTITION NEW-OFFSET
billing orders 0 0
billing orders 1 0
billing orders 2 0
billing orders 3 0
billing orders 4 0
billing orders 5 0
$ python read.py billing
billing read 7 orders: order-1 order-2 order-3 order-4 order-5 order-6 order-7Every partition goes to offset 0, and billing reads all seven orders again. The two warnings are only for partitions 4 and 5, which are empty.
Your replay window is the retention. If you need queue-style work sharing, share groups are production-ready since Kafka 4.2, and we cover them in Part 3.
Scenario 7: The business wants every order event available to five teams in near real time. How would you design the topics?
One shared topic for order events, owned by the order service, not a copy per team. Each team reads it with its own consumer group, at its own pace.
Here is how I set it up, step by step:
- Key by order ID, so each order's events stay in order.
- Size the partitions for peak traffic and for the biggest team's consumers, because growing later moves keys. Here we use six.
- Use replication factor 3,
min.insync.replicas=2, and producers onacks=all. - Set retention long enough to replay after a bug, here fourteen days.
- Keep the event schema in a schema registry with compatibility rules, so one team can't break the other four. The common one, Confluent Schema Registry, is not part of Apache Kafka.
Let's create orders-v1 with these settings.
$ kafka-topics.sh --bootstrap-server localhost:9092 --create --topic orders-v1 --partitions 6 --replication-factor 3 --config min.insync.replicas=2 --config retention.ms=1209600000
Created topic orders-v1.
$ kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic orders-v1 | grep PartitionCount
Topic: orders-v1 TopicId: <topic-id> PartitionCount: 6 ReplicationFactor: 3 Configs:
min.insync.replicas=2,retention.ms=1209600000The topic has PartitionCount: 6 and ReplicationFactor: 3, with min.insync.replicas=2,retention.ms=1209600000. Now the order service publishes six events from events.txt with the console producer, using the order ID as the key, and python teams.py reads them as five teams.
$ kafka-console-producer.sh --bootstrap-server localhost:9092 --topic orders-v1 --reader-property parse.key=true --reader-property key.separator=: < events.txt
$ python teams.py
group billing-svc read 6 events
group shipping-svc read 6 events
group fraud-svc read 6 events
group analytics-svc read 6 events
group email-svc read 6 eventsBilling, shipping, fraud, analytics and email each read all 6 events, each with its own group.
Then we lock it down: only the order service may write, and each team reads with its own identity. A team that needs a filtered or enriched view gets a derived topic from stream processing, and the shared topic stays as it is.
One topic, one owner, one group per team. That sentence covers most of the design.
Key points to remember
- Kafka is a replicated event log: groups read it independently
- A topic splits into partitions; each record gets an offset
- The key picks the partition: order holds per partition
- KRaft only since 4.0: a controller quorum, no ZooKeeper
- Replay = move the group's offsets, within retention
The full script
Here is a Python script that writes the files and runs every command above in order against a local Kafka 4.4; run pip install confluent-kafka first.
Show the full script that writes the files and runs every step
# ========================================================================
# Kafka Interview Q&A #1 - Kafka fundamentals and architecture
# TechBrothersIT. Sample data is invented for teaching.
# Every step below was run on Apache Kafka 4.4.0 (KRaft mode, 3 nodes) with confluent-kafka 2.16.0;
# the outputs in the video and the blog post are the real outputs. To run it yourself (Linux, macOS or WSL):
# 1. Download Kafka 4.4.0 from kafka.apache.org, extract it, and put its bin folder on your PATH.
# 2. Start a local cluster (see the Kafka quickstart; node 1 listens on localhost:9092).
# 3. pip install confluent-kafka then python Kafka_Interview_QA_01_Code.py in an empty folder.
# Steps that stop or start a broker say so in a comment: do that by hand at that point.
# ========================================================================
import os, subprocess
def write(path, text):
os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
with open(path, "w", encoding="utf-8") as f:
f.write(text.strip("\n") + "\n")
def run(cmd, expect_error=False):
print("\n$ " + cmd, flush=True)
rc = subprocess.run(cmd, shell=True).returncode
if rc != 0 and not expect_error:
raise SystemExit("stopped: this command was expected to succeed")
# Step 0: files used by the steps
write('producer.py', """\
from confluent_kafka import Producer
p = Producer({'bootstrap.servers': 'localhost:9092'})
orders = [('c-101', 'order-1'), ('c-707', 'order-2'),
('c-101', 'order-3'), ('c-606', 'order-4'),
('c-707', 'order-5'), ('c-101', 'order-6')]
done = []
def report(err, m):
if err:
print('FAILED', m.value(), err)
return
done.append((m.partition(), m.offset(), m.key().decode(),
m.value().decode()))
for customer, order in orders:
p.produce('orders', key=customer, value=order, on_delivery=report)
p.flush()
for row in sorted(done):
print('partition %d offset %d key %s %s' % row)
""")
write('one_more.py', """\
from confluent_kafka import Producer
p = Producer({'bootstrap.servers': 'localhost:9092'})
def report(err, m):
print(m.key().decode(), m.value().decode(), err or '',
'-> partition', m.partition(), 'offset', m.offset())
p.produce('orders', key='c-101', value='order-7', on_delivery=report)
p.flush()
""")
write('show.properties', """\
print.partition=true
print.offset=true
print.key=true
""")
write('read.py', """\
import sys
from confluent_kafka import Consumer
group = sys.argv[1]
c = Consumer({'bootstrap.servers': 'localhost:9092', 'group.id': group,
'auto.offset.reset': 'earliest'})
c.subscribe(['orders'])
seen, idle = [], 0
while idle < 5: # stop after 5 quiet seconds
m = c.poll(1.0)
if m is None:
idle += 1
elif m.error():
raise SystemExit(m.error())
else:
seen.append(m.value().decode())
c.close() # commits the final offsets
print(group, 'read', len(seen), 'orders:', ' '.join(sorted(seen)))
""")
write('events.txt', """\
o-1001:created
o-1002:created
o-1001:paid
o-1001:shipped
o-1002:paid
o-1003:created
""")
write('teams.py', """\
from confluent_kafka import Consumer
for team in ['billing', 'shipping', 'fraud', 'analytics', 'email']:
c = Consumer({'bootstrap.servers': 'localhost:9092',
'group.id': team + '-svc',
'auto.offset.reset': 'earliest'})
c.subscribe(['orders-v1'])
events, idle = [], 0
while idle < 5:
m = c.poll(1.0)
if m is None:
idle += 1
elif not m.error():
events.append(m.value().decode())
c.close()
print(f'group {team}-svc read {len(events)} events')
""")
# Step 1: Create the orders topic: 3 partitions, each on 3 brokers (replicas pinned so the output is repeatable)
run('kafka-topics.sh --bootstrap-server localhost:9092 --create --topic orders --replica-assignment 1:2:3,2:3:1,3:1:2')
run('kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic orders')
# Step 2: Produce six orders keyed by customer: the delivery report gives each record its partition and offset
run('python producer.py')
# Step 3: The end offset of every partition: the offset the next record will get
run('kafka-get-offsets.sh --bootstrap-server localhost:9092 --topic orders')
# Step 4: Read partition 0 starting at offset 1
run('kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic orders --partition 0 --offset 1 --max-messages 2 --formatter-config show.properties')
# Step 5: Grow the topic to 6 partitions: the same customer now maps to a different partition
run('kafka-topics.sh --bootstrap-server localhost:9092 --alter --topic orders --partitions 6')
run('python one_more.py')
# Step 6: KRaft: the node config, and the metadata log on disk
run("grep -E 'roles|node.id|quorum|controller.listener' ../cluster/node1.properties")
run('ls ../cluster/node1 | grep cluster_metadata')
# Step 7: The controller quorum: three voters
run("kafka-metadata-quorum.sh --bootstrap-server localhost:9092 describe --status | grep -E 'ClusterId|CurrentVoters'")
# Step 8: A payments topic replicated on all three brokers
run('kafka-topics.sh --bootstrap-server localhost:9092 --create --topic payments --replica-assignment 1:2:3,2:3:1,3:1:2')
run('kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic payments')
# Step 9: Stop broker 2: the controller moves its partition leadership
# >>> now STOP broker 2 (the video stops node 2 here) <<<
run('kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic payments')
# Step 10: Start broker 2 again: it catches up and rejoins the ISR
# >>> now START broker 2 again <<<
run('kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic payments')
# Step 11: Retention: the log is kept whether or not anyone read it
run("kafka-configs.sh --bootstrap-server localhost:9092 --describe --topic orders --all | grep -E ' retention\\.(ms|bytes)='")
# Step 12: The billing group reads all orders and commits its offsets
run('python read.py billing')
run('kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group billing')
# Step 13: A new team reads the same orders with its own group
run('python read.py fraud-model')
# Step 14: Replay: move the billing group back seven days and read again
run('kafka-consumer-groups.sh --bootstrap-server localhost:9092 --reset-offsets --group billing --topic orders --by-duration P7D --execute')
run('python read.py billing')
# Step 15: One shared topic for order events: 6 partitions, 3 replicas, min ISR 2, 14 days retention
run('kafka-topics.sh --bootstrap-server localhost:9092 --create --topic orders-v1 --partitions 6 --replication-factor 3 --config min.insync.replicas=2 --config retention.ms=1209600000')
run('kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic orders-v1 | grep PartitionCount')
# Step 16: The order service publishes events keyed by order ID; five teams read them with their own groups
run('kafka-console-producer.sh --bootstrap-server localhost:9092 --topic orders-v1 --reader-property parse.key=true --reader-property key.separator=: < events.txt')
run('python teams.py')
Part 2: Producers and Delivery Guarantees
The sample data on this page is invented for teaching. Every terminal output is the real output of the command above it, run on Apache Kafka 4.4.0 in KRaft mode with confluent-kafka 2.16.0; topic IDs are masked. Part of the Real Time Kafka Interview Questions and Answers series on TechBrothersIT. Features, limits and their status (GA or preview) are current as of October 2026; check the official Apache Kafka documentation (kafka.apache.org) for anything you quote in an interview.



No comments:
Post a Comment
Note: Only a member of this blog may post a comment.