---
title: "Nisshi diskless Kafka on PostgreSQL: a row lock per write"
description: "Nisshi's PostgreSQL engine runs each produce request as one transaction holding the partition's watermark row lock; a second writer waits, then commits."
url: https://monedula.dev/kafka-simulator/scenarios/nisshi-postgresql-row-lock/
---

# Nisshi diskless Kafka on PostgreSQL: a row lock per write

Scenario 12.1.2 · Nisshi on PostgreSQL: one transaction per write. Diskless · Advanced · about 3 min · Apache Kafka 4.4 · Nisshi 0.8.2.

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 it: https://monedula.dev/kafka-simulator/playground/?scenario=12.1.2

## What 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

1. **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](https://monedula.dev/kafka-simulator/playground/?scenario=12.1.2&t=0)
2. **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](https://monedula.dev/kafka-simulator/playground/?scenario=12.1.2&t=1)
3. **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](https://monedula.dev/kafka-simulator/playground/?scenario=12.1.2&t=2)
4. **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](https://monedula.dev/kafka-simulator/playground/?scenario=12.1.2&t=3)
5. **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](https://monedula.dev/kafka-simulator/playground/?scenario=12.1.2&t=4)

## 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

- [`acks`](https://kafka.apache.org/44/configuration/producer-configs/#producerconfigs_acks): How 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](https://monedula.dev/kafka/configs/acks/)
- [`maintenance_interval`](https://github.com/nisshi-io/solace-nisshi/blob/v0.8.2/docs/compatibility.md): A setting of the Nisshi PostgreSQL engine, 10 minutes by default, for how often its maintenance applies retention and compaction to the stored records.

## Further reading

- [Nisshi v0.8.2 source on GitHub](https://github.com/nisshi-io/solace-nisshi/blob/v0.8.2/docs/storage.md)
