Architecture
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
| Component | Responsibility |
|---|---|
| Go gateway | Decode 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 service | Read committed event batches, track each Watch and enforce queue limits |
pg_etcd | Evaluate Txn, allocate revisions, store events, manage Lease state and compact history |
pg_kvcore | Internal C helpers linked into pg_etcd; not a separate extension |
| PostgreSQL | Store logged tables, serialize requests, maintain snapshots and commit WAL |
| Lease launcher and workers | Supervise 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
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:
| Path | Main content |
|---|---|
cmd/pgetcd/main.go | Process 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.c | SQL entry points and request execution |
extension/pg_etcd--0.1.0.sql | Schema, 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
COMMITpublication. - Watch, Lease and history — Complete revision delivery, Lease facts and worker recovery, and baseline compaction.
- Schema — The seven logged tables in the
etcdschema, invariants, and the internal SQL ABI. - Security — Tenant mTLS, certificate URI SAN matching, database role boundaries, and admission limits.
How one etcd request becomes one PostgreSQL transaction with a single revision.
Event history, Watch delivery, lease expiry and logical compaction.
The seven tables of the etcd schema and what each one holds.
Tenant mTLS, certificate identities, database roles and grants.