Skip to content

Certified publication

Why reads write a barrier, why responses wait for synchronous commit, and why unknown commits are not replayed.
Note

Condensed from Design 0006 (accepted 2026-10-08).

Decision

Before sending any state-observing gRPC response to a client, pgetcd requires two steps:

  1. In-transaction certification: Capture a consistent post-lock snapshot inside pg_etcd. If the request does not already write WAL after that observation (for example, a read or a failed comparison), update the logged counter in etcd.publication_barrier.
  2. Synchronous commit before publication: Buffer the provisional response in the gateway’s Publisher component and execute a synchronous COMMIT (synchronous_commit = on). Release the buffered response to the gRPC stream only after COMMIT succeeds with zero PostgreSQL warnings.

This rule applies to Range, read-only or false-branch Txn replies, Watch creation (Created), Watch event batches, Watch progress notifications, MemberList, Status, and state-dependent errors (ErrCompacted, ErrFutureRev, ErrLeaseNotFound).

A single certified snapshot can serve multiple Watch streams during one tail cycle, but an earlier barrier never certifies a snapshot taken later.

Why read barriers are required

In PostgreSQL synchronous replication, a committing backend writes its WAL record and makes the transaction locally visible in shared memory before waiting for the synchronous standby to flush WAL. If an operator cancels that backend (pg_cancel_backend), terminates it, or restarts the primary before the standby acknowledges the LSN, another local backend running a plain SELECT can read locally visible rows that never reached the synchronous standby. If a failover then promotes the standby, any etcd response derived from that uncertified read would violate linearizability.

By writing a WAL-logged row to etcd.publication_barrier after taking the read snapshot and requiring that transaction’s own synchronous COMMIT to succeed without warnings, pgetcd guarantees that the standby has flushed both the barrier’s LSN and every earlier LSN visible in the read snapshot.

Plain SELECT queries, empty transactions, pg_current_wal_lsn() reads, UNLOGGED table writes, or barriers written before the snapshot do not establish this WAL ordering. The trade-off is that every read and state-dependent error pays a small WAL write and synchronous commit round-trip.

Unknown commit outcomes

The Publisher retains its database connection and inflight admission slot until COMMIT returns a known result. If COMMIT fails, returns a PostgreSQL warning (such as a canceled synchronous-replication wait), or loses its connection before the result is known, the buffered gRPC response is discarded and an error is returned to the client.

The gateway never automatically replays a transaction whose COMMIT outcome is unknown, because the transaction may have committed on the server just before the connection dropped. Retrying clients must resolve ambiguity using Txn predicates or application idempotency keys. See Transactions and revisions.

Scan to open this page
https://mimus.pgsty.com/docs/etcd/design/certified-publication/