Scenario 12.1.2 · Nisshi on PostgreSQL: one transaction per write
Nisshi diskless Kafka on PostgreSQL: a row lock per write
Nisshi 0.8.2 on PostgreSQL · each produce request is one transaction that locks the partition's watermark row; a second writer of the partition waits for the lock, then commits right after.
Run this scenario in the playgroundbroker-1's transaction holds orders-0's row lock; broker-2's waits. t+0.150s
p1 (on broker-1) and p2 (on broker-2) each send a record for orders-0 at 100, and both batches flush at 150. broker-1's transaction locks orders-0's watermark row; broker-2's transaction waits for that lock. Both producers are idempotent, acks=all.
Open at this step: step 1, broker-1's transaction holds orders-0's row lock; broker-2's waitsbroker-1 commits row 0 and the watermark; broker-2 takes the lock. t+0.165s
After 15 ms broker-1's transaction has inserted the row at offset 0, moved the watermark to 1 and committed, which releases the lock. broker-2's transaction takes it at once, with no retry.
Open at this step: step 2, broker-1 commits row 0 and the watermark; broker-2 takes the lockbroker-2 commits row 1; both producers are acked. t+0.181s
broker-2 commits offset 1 at 180. Each ack leaves 1 ms after its commit (a simulator choice): p1's at 166, p2's at 181, 15 ms later for the wait. The idempotent sequence check runs inside each transaction, under the lock.
Open at this step: step 3, broker-2 commits row 1; both producers are ackedc1 on broker-3 reads both rows at its first poll. t+0.600s
c1 talks to broker-3, which wrote nothing. On PostgreSQL a fetch reads the watermark row and the rows together, so every broker sees a commit at once.
Open at this step: step 4, c1 on broker-3 reads both rows at its first pollorders-1 has its own row: no wait. t+1.200s
p1's next record goes to orders-1 at 700: its transaction locks orders-1's row, commits at 765 with nobody waiting and is acked at 766. c1 reads it at 1200.
Open at this step: step 5, orders-1 has its own row: no waitWhat you start with
PostgreSQL is Nisshi's production engine and its Docker Compose default. On it a produce request is one transaction per partition: it locks the partition's watermark row (select ... for no key update), inserts the records, moves the watermark and commits. Nothing goes to object storage. p1 on broker-1 and p2 on broker-2 write orders-0 in the same millisecond; consumer group g1 reads through broker-3. The 15 ms transaction is Inkless's PostgreSQL figure, borrowed (Nisshi's sources give none).
Step by step
- broker-1's transaction holds orders-0's row lock; broker-2's waits t+0.150s p1 (on broker-1) and p2 (on broker-2) each send a record for orders-0 at 100, and both batches flush at 150. broker-1's transaction locks orders-0's watermark row; broker-2's transaction waits for that lock. Both producers are idempotent, acks=all. Open at this step: step 1, broker-1's transaction holds orders-0's row lock; broker-2's waits
- broker-1 commits row 0 and the watermark; broker-2 takes the lock t+0.165s After 15 ms broker-1's transaction has inserted the row at offset 0, moved the watermark to 1 and committed, which releases the lock. broker-2's transaction takes it at once, with no retry. Open at this step: step 2, broker-1 commits row 0 and the watermark; broker-2 takes the lock
- broker-2 commits row 1; both producers are acked t+0.181s broker-2 commits offset 1 at 180. Each ack leaves 1 ms after its commit (a simulator choice): p1's at 166, p2's at 181, 15 ms later for the wait. The idempotent sequence check runs inside each transaction, under the lock. Open at this step: step 3, broker-2 commits row 1; both producers are acked
- c1 on broker-3 reads both rows at its first poll t+0.600s c1 talks to broker-3, which wrote nothing. On PostgreSQL a fetch reads the watermark row and the rows together, so every broker sees a commit at once. Open at this step: step 4, c1 on broker-3 reads both rows at its first poll
- orders-1 has its own row: no wait t+1.200s p1's next record goes to orders-1 at 700: its transaction locks orders-1's row, commits at 765 with nobody waiting and is acked at 766. c1 reads it at 1200. Open at this step: step 5, orders-1 has its own row: no wait
The takeaway
On PostgreSQL the watermark row lock orders the writers of a partition: the second transaction waited and committed right after the first, so the offsets follow commit order and no write was retried. Records, watermarks, group state and committed offsets all live in PostgreSQL, so any broker reads a commit at once, with no cache to wait for. Writers of different partitions never wait for each other. Retention and compaction run in a maintenance sweep, every 10 minutes by default (maintenance_interval). Simulator choices: the 15 ms transaction borrowed from Inkless's figure, the pinned brokers, and the response 1 ms after the commit.
Configs in this scenario
-
acksHow many replicas must have a write before the producer counts it as sent: 0 (none), 1 (the leader only) or all (every in-sync replica, the default, and required for idempotence). How acks works -
maintenance_A setting of the Nisshi PostgreSQL engine, 10 minutes by default, for how often its maintenance applies retention and compaction to the stored records.interval
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=12.1.2" title="Kafka Simulator: Nisshi on PostgreSQL: one transaction per write" 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/nisshi-postgresql-row-lock/">Nisshi diskless Kafka on PostgreSQL: a row lock per write</a></p> Further reading
Nisshi v0.8.2 source on GitHub
More in Diskless
- Diskless Kafka topics (KIP-1163): the write path
- Diskless vs classic Kafka: cross-AZ replication traffic
- Diskless Kafka produce latency: the price of object storage
- Diskless Kafka (KIP-1163): when object storage goes down
- Aiven Inkless diskless Kafka: the write path
- Aiven Inkless: what a PostgreSQL outage does to Kafka
- Aiven Inkless: what losing a Kafka broker costs
- Aiven Inkless: a slow S3 bucket fails Kafka produce
- KafScale diskless Kafka: etcd lease, S3 segment, ack
- KafScale 2.1 diskless Kafka: a lease owner crashes
- KafScale 2.1 diskless Kafka: when etcd goes down
- KafScale 2.1 diskless Kafka: when S3 goes down
- KafScale 2.1 proxy: etcd down past the 60 s cache TTL
- KafScale 2.1: a Kafka producer timeout that still wrote
- KafScale 2.1 diskless Kafka: lease handover, no overwrite
- KafScale 2.1 diskless Kafka: a paused broker comes back
- AutoMQ diskless Kafka: one S3 WAL per broker, then ack
- AutoMQ diskless Kafka: a broker crash and WAL failover
- AutoMQ diskless Kafka: moving a partition, no copying
- AutoMQ diskless Kafka: zone router, no cross-zone data
- AutoMQ diskless Kafka: when S3 goes down
- WarpStream diskless Kafka: the write path through Agents
- WarpStream Kafka: a leader per client, a cache per zone
- WarpStream Kafka: an Agent dies mid-commit
- WarpStream Kafka: the control plane goes down
- WarpStream Kafka Ripcord: produce without the control plane
- WarpStream Kafka lightning topics: ack before the commit
- WarpStream Kafka transactions in the control plane
- Redpanda Kafka write path: the offset comes after S3
- Redpanda Kafka leader crash: a Raft election, no replay
- Redpanda Kafka S3 outage: uploads time out, Raft holds
- Redpanda Kafka L0 to L1: the LRO and who serves a read
- Redpanda Kafka transactions: exactly-once on Cloud Topics
- Nisshi diskless Kafka: watermark.json, then the batch
- Nisshi diskless Kafka: two brokers write one partition
- Nisshi diskless Kafka: reading through another broker
- Nisshi diskless Kafka: a broker dies mid-write
- Nisshi diskless Kafka: when PostgreSQL goes down
- Nisshi diskless Kafka: what 0.8.2 refuses
- Ursa for Kafka write path: Oxia assigns the offset
- Ursa for Kafka zones: the zonal owner and the zone cache
- Ursa for Kafka compaction: from WAL objects to Parquet
- Ursa for Kafka broker failure: a kill and a silent broker
- Ursa for Kafka: diskless and disk topics, side by side