Monedula

Scenario 12.1.6 · Nisshi: PostgreSQL unavailable

Nisshi diskless Kafka: when PostgreSQL goes down

Diskless · Advanced · about 4 min · Apache Kafka 4.4 · Nisshi 0.8.2

Nisshi 0.8.2 on PostgreSQL · while PostgreSQL is down produce gets KAFKA_STORAGE_ERROR, fetches close the connection and offset commits get COORDINATOR_NOT_AVAILABLE; when it is back, nothing is lost and no offset is skipped.

Run this scenario in the playground

p1's produce gets KAFKA_STORAGE_ERROR. t+1.350s

p1's record for orders-2 reaches broker-1 at 1350. The transaction cannot run: nothing is stored and p1 gets KAFKA_STORAGE_ERROR, which is retriable. It retries every 400 ms, each failing the same way until PostgreSQL is back.

Open at this step: step 4, p1's produce gets KAFKA_STORAGE_ERROR

What you start with

PostgreSQL holds everything on Nisshi's production engine: records, watermarks, consumer group state and committed offsets. When it is unavailable no broker can serve a request that needs it, but a transaction either commits or stores nothing. p1 (idempotent, acks=all) writes through broker-1; consumer group g1 reads through broker-2 every 600 ms. PostgreSQL stops at 1000 and starts again at 3000.

Step by step

  1. Steady traffic on PostgreSQL t+0.766s p1 writes orders-0 at 100 and orders-1 at 700; each is one transaction, committed and acked (166, 766). c1 reads through broker-2 every 600 ms. Open at this step: step 1, Steady traffic on PostgreSQL
  2. PostgreSQL stops t+1.000s PostgreSQL holds the records, the watermarks, the group state and the offsets. The simulator notices the outage at once. Open at this step: step 2, PostgreSQL stops
  3. c1's fetches close the connection; its commit gets COORDINATOR_NOT_AVAILABLE t+1.200s At c1's 1200 poll broker-2 cannot read the rows, so it closes the connection, as Nisshi 0.8.2 does (shown as REQUEST_TIMED_OUT); c1 reconnects at its next poll. Its offset commit gets COORDINATOR_NOT_AVAILABLE. Open at this step: step 3, c1's fetches close the connection; its commit gets COORDINATOR_NOT_AVAILABLE
  4. p1's produce gets KAFKA_STORAGE_ERROR t+1.350s p1's record for orders-2 reaches broker-1 at 1350. The transaction cannot run: nothing is stored and p1 gets KAFKA_STORAGE_ERROR, which is retriable. It retries every 400 ms, each failing the same way until PostgreSQL is back. Open at this step: step 4, p1's produce gets KAFKA_STORAGE_ERROR
  5. PostgreSQL starts again t+3.000s Produce, fetch and offset commits work again. Open at this step: step 5, PostgreSQL starts again
  6. p1's retry commits at offset 0: no gap t+3.366s p1's retry at 3350 commits orders-2 offset 0 and is acked at 3366. The failed transactions stored nothing, so there is no gap to skip. Open at this step: step 6, p1's retry commits at offset 0: no gap
  7. c1 reads every record t+3.600s c1's 3600 poll reads the three records it could not read during the outage: orders-1 offset 0, orders-2 offset 0 and orders-0 offset 1 (written at 3500). Open at this step: step 7, c1 reads every record
  8. Caught up: the commit goes through t+4.200s c1's offset commit at 4200 succeeds: orders-0 at 2, orders-1 at 1, orders-2 at 1. Nothing acked was lost and no offset was skipped. Open at this step: step 8, Caught up: the commit goes through

The takeaway

While PostgreSQL was down, produce got KAFKA_STORAGE_ERROR (retriable) and the producer retried, fetches made the broker close the connection and the consumer reconnected, and offset commits got COORDINATOR_NOT_AVAILABLE. When it came back the next retry committed and the consumer read every record. A failed transaction stores nothing, so there was no gap and nothing acked was lost. Simulator choices: the outage noticed at once, REQUEST_TIMED_OUT standing for the closed connection, the 15 ms transaction borrowed from Inkless's figure, and the 400 ms retry backoff.

Configs in this scenario

  • 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

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.6" title="Kafka Simulator: Nisshi: PostgreSQL unavailable" 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-unavailable/">Nisshi diskless Kafka: when PostgreSQL goes down</a></p>

Further reading

Nisshi v0.8.2 source on GitHub

Troubleshooting

More in Diskless

All scenarios