Skip to content

Architecture

Components, request paths, tenants and persistent state in pgetcd.

pgetcd implements an etcd v3 service API protocol gateway over PostgreSQL. The Go process handles gRPC and tenant connections. The pg_etcd C extension owns storage semantics, and PostgreSQL stores all durable state.

Each gateway process serves one configured tenant on a fixed PostgreSQL primary. Multi-node high availability and automatic primary promotion are part of the post-MVP HA roadmap. See Status for current validation boundaries.

Components

ComponentResponsibility
Go gatewayDecode protobuf requests, check input limits, authenticate clients and translate SQL envelopes
Publisher (gateway component)Own SQL transactions and retain responses until synchronous COMMIT succeeds
Tenant Watch serviceRead committed event batches, track each Watch and enforce queue limits
pg_etcdEvaluate Txn, allocate revisions, store events, manage Lease state and compact history
pg_kvcoreInternal C helpers linked into pg_etcd; not a separate extension
PostgreSQLStore logged tables, serialize requests, maintain snapshots and commit WAL
Lease launcher and workersSupervise one background worker per allowed database and rebuild Lease deadlines

The C extension has no network listener or embedded Go runtime. The Go gateway has no independent revision allocator or Lease expiry clock.

Request path

etcd client
    │ gRPC with tenant mTLS
    ▼
Go gateway → Publisher → PostgreSQL transaction
                              │
                              ▼
                          pg_etcd
                    lock meta → fresh snapshot
                    validate → evaluate → certify
                              │
                              ▼
                       synchronous COMMIT
                              │
                              ▼
                     buffered gRPC response

Each logical request uses one READ COMMITTED transaction with synchronous_commit = on. The extension locks the tenant’s metadata row and takes a fresh snapshot after the lock wait finishes. Any response that observes state requires a logged change after that observation and a normal synchronous COMMIT before publication. Transactions and revisions explains this order.

Watch uses the same publication boundary. A per-tenant tailer reads complete committed revisions; PostgreSQL notifications wake the tailer, and periodic polling recovers missed notifications. Lease expiry also changes state through PostgreSQL transactions. See Watch, Lease and history.

Tenant boundary

A tenant has a fixed endpoint, database, SQL role and certificate policy. One gateway process serves one tenant. Two gateway processes can serve the same database with separate connection pools. Multiple tenants use separate process configurations and database bindings.

A client request cannot select a database. Key prefixes are an application convention, not an isolation boundary. Read Security before assigning credentials.

Persistent state

The seven core tables in the etcd schema are ordinary logged PostgreSQL tables. They hold current values, complete events, revision manifests, history anchors, Lease facts, logical identity and publication barriers. See Schema for table definitions and invariants.

PostgreSQL sequences do not allocate protocol revisions. A rolled-back request consumes no revision, and all actual KV changes in one request share a single revision.

Source map

Paths below are relative to the pgetcd repository:

PathMain content
cmd/pgetcd/main.goProcess modes, tenant startup, listeners and shutdown
internal/gateway/gRPC service adapters
internal/pgstore/, internal/pgflight/Publication and SQL transaction ownership
internal/watch/, internal/tenantservice/Watch delivery and tenant readiness
extension/pg_etcd.cSQL entry points and request execution
extension/pg_etcd--0.1.0.sqlSchema, SQL functions and privileges
extension/pg_kvcore/Revision budgets and Lease runtime

Architecture topics

  • Transactions and revisions — Post-lock snapshots, revision allocation, read barriers, and synchronous COMMIT publication.
  • Watch, Lease and history — Complete revision delivery, Lease facts and worker recovery, and baseline compaction.
  • Schema — The seven logged tables in the etcd schema, invariants, and the internal SQL ABI.
  • Security — Tenant mTLS, certificate URI SAN matching, database role boundaries, and admission limits.

The seven tables of the etcd schema and what each one holds.

Tenant mTLS, certificate identities, database roles and grants.