Monedula

Scenario 08.1.1 · KafScale: the write path

KafScale diskless Kafka: etcd lease, S3 segment, ack

Diskless · Advanced · about 3 min · Apache Kafka 4.4 · KafScale 2.1

KafScale 2.1 · the owner of each partition holds an etcd lease; every produce request is one S3 segment, then the end offset in etcd, then the ack.

Run this scenario in the playground

The owner serves the read from its cache. t+1.850s

Consumer c1 read all three records and its offsets are committed (lag 0). A KafScale fetch takes the partition's lease, as a produce does, so the consumer's fetch reaches each partition's lease owner, which has the segment cached from its own upload: no read from S3 was needed.

Open at this step: step 4, The owner serves the read from its cache

What you start with

KafScale 2.1 is a broker written in Go that speaks the Kafka protocol and keeps every topic in S3, with one replica. Clients connect through its proxy, which routes each request to the partition's owner broker, the one holding a lease for it in etcd. With its default sync flush, a produce request is uploaded as one S3 segment, the new end offset is written to etcd, and only once that write succeeds does the producer get its ack. Producer p1 sends three keyed records, one per partition of orders. Watch the lease lane for etcd, the object storage lane and the partition strips. Timings are slowed so each phase gets its own frame.

Step by step

  1. KafScale cluster, no leases yet t+0.000s orders is a KafScale topic (KafScale 2.1): 3 partitions, one replica each, every byte in S3. Three brokers and etcd, which will hold one lease per partition, but no partition has an owner yet and nothing has been written. Producer p1 sends keyed records; consumer group g1 has one member. Open at this step: step 1, KafScale cluster, no leases yet
  2. First produce: lease, offset, segment upload t+0.150s The first produce request, flushed at 150 ms, makes a broker take each partition's lease in etcd: broker-2 for orders-0, broker-3 for orders-1 and orders-2 (the simulator's hash picks them). Each new owner restores its partition from S3, which is empty, gives its record offset 0 and starts uploading it as its own segment (one per produce request and partition, for example orders-0 · segment 0-0). The upload runs 600 ms here (the simulator's figure). Nothing is committed and p1 is not yet acked. Open at this step: step 2, First produce: lease, offset, segment upload
  3. etcd records the end offset, producer acked t+0.790s The uploads finished at 750 ms, then each owner wrote the partition's new end offset (1) to etcd, 40 ms here (the simulator's figure). Only now is p1 acked, 640 ms after the append, and the high watermark moves to 1 on all three partitions. Open at this step: step 3, etcd records the end offset, producer acked
  4. The owner serves the read from its cache t+1.850s Consumer c1 read all three records and its offsets are committed (lag 0). A KafScale fetch takes the partition's lease, as a produce does, so the consumer's fetch reaches each partition's lease owner, which has the segment cached from its own upload: no read from S3 was needed. Open at this step: step 4, The owner serves the read from its cache

The takeaway

No partition had an owner until the first produce; the first append took its lease and restored the partition from an empty S3. The owner then numbered the record, uploaded one segment per produce request and partition, and wrote the end offset to etcd; the producer was acked only after that write succeeded (08.2.5 shows what happens when that etcd write fails). Consumer c1 (group g1) read every record from the caches of the owner brokers. Simulator choices: which broker takes each lease is the simulator's hash of topic and partition, and the S3 upload time (600 ms here) and etcd write time (40 ms here) are slowed figures; KafScale's sources give none.

Embed this scenario

Paste this into a blog post, a course page or your team's docs. The scenario plays inside your page, and the link under it points readers to this walkthrough.

<iframe src="https://monedula.dev/kafka-simulator/embed/?scenario=08.1.1" title="Kafka Simulator: KafScale: the write path" width="100%" height="520" style="border:1px solid #d0d0d0;border-radius:8px" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
<p><a href="https://monedula.dev/kafka-simulator/scenarios/kafscale-write-path/">KafScale diskless Kafka: etcd lease, S3 segment, ack</a></p>

Further reading

KafScale v2.1.0 source on GitHub

More in Diskless

All scenarios