Choose what this site may use

This site uses strictly necessary cookies to work and to remember your privacy choices. With your permission it would also load content hosted by other services, such as videos, maps and fonts, which then receive your network address and device data. We do not sell or share your personal information and we run no advertising. Choose Accept all, Reject all or Customise. You can change your mind at any time through Privacy choices at the foot of every page.

  • Always on

    Needed for the site to work and to remember your privacy choices. Always on.

  • Remembers settings you choose, such as the light or dark display, in your browser.

  • Loads videos, maps and other content hosted by other services. Those services receive your address and device data.

Menu Close
In this section: Learn
Start
Guides
Domain packs
Participants
Security and privacy
Pilot kits
Operations
Ecosystem

Data plane

Source docs/ops/dataplane.md

On this page
  1. What holds what
  2. How a write stays correct across replicas
  3. Delivery guarantees
  4. Operating it
  5. Backup and restore
  6. Capacity
  7. Not done

How the reference gateway runs as a production data plane: stateless replicas on one PostgreSQL database, an object store for large payloads, an event bus, and the workers that carry corrections to subscribers and federation peers. The code is in reference/rust/obsp-gateway (features postgres, nats, s3, fast-alloc) and reference/rust/obsp-dataplane. The manifests are gateway-dp, dataplane-relay, nats and dataplane-migrate in infra/deploy, and the local stack is in infra/compose. None of this runs anywhere yet.

 nodes ──HTTP──▶ gateway-dp replicas (stateless) ──one transaction per write──▶ PostgreSQL + PostGIS
                    │ payloads ≥ 256 KiB by digest                                │ change feed (txid, seq)
                    ▼                                                              ▼
              object storage (S3 API)                       dataplane-relay (one leader) ──CloudEvents──▶ NATS JetStream
                                                                                                │ one durable consumer per sink
                                                              fan-out workers ◀────────────────┘
                                                                 ├──▶ subscriber webhooks (application/cloudevents+json)
                                                                 └──▶ federation peers' gateways (POST /node-ingest/v0.1/corrections)

What holds what

Store Holds Durability Restored from
PostgreSQL every write: idempotency records, participants, claims, nodes, admissions, intake events (partitioned by month), key records, correction notices, deliveries the database’s (commit waits for the WAL flush) managed point-in-time recovery, or dataplane-backup.sh dumps
Object storage intake payloads of 256 KiB or more (canonical form), by SHA-256 digest; every read is checked against the digest the object store’s a copy of the bucket (objects never change)
NATS JetStream the stream of CloudEvents (7 days) file storage, 3 replicas in production not restored: the relay republishes from the database

Record tables are append-only: triggers refuse UPDATE, DELETE and TRUNCATE (migrations/0001_initial.sql). A correction is a new row in corrections, and the corrected record never changes. The view record_correction_state gives each record’s state after its last notice. Only consumer_cursors (the relay’s progress) changes in place.

How a write stays correct across replicas

Each write is one transaction. The transaction takes advisory locks on every key the decision reads, in ascending order: the idempotency key, the node whose key records it checks, every event id, and the entity it may create. It then reads, decides, inserts and commits. Two writes that share a key are decided one after the other, as in the single-lock reference store, and the answers match. Writes with disjoint keys run in parallel on any replica. Unique constraints back the locks up: writes.scope_key, event_ids.event_id, entities (kind, uni) and corrections.notice_uni. Evidence: every gateway test passes against PostgreSQL (OBSP_TEST_DATABASE_URL), and tests/postgres.rs sends every batch through two replicas at once. Each event is accepted exactly once, and the other replica answers it as an idempotent replay.

Delivery guarantees

  • Relay. It reads the change feed in commit order, below the oldest transaction still in progress, so it never passes a row that commits later. It publishes a batch, waits for the bus to acknowledge every message, and only then saves its cursor. Delivery is at least once. JetStream drops a duplicate by its message id (the CloudEvent id) within its 2-minute window, and every consumer must also treat a repeated id as a duplicate. One relay is active per database, chosen by a session advisory lock; another replica takes over when the leader’s connection ends.
  • Fan-out. Each sink has its own durable consumer, so a slow sink delays only itself. A failed delivery is retried with a doubling delay of up to 60 s, and the sink’s later corrections wait for it. This keeps one worker’s deliveries in recording order. With two relay replicas sharing a durable consumer, order holds per message only. A peer gateway answers a repeated notice as an idempotent replay. Every delivery is recorded in deliveries with its latency.
  • Back-pressure. At most 4 096 publishes await their acknowledgement at once. A slow bus slows the relay, never the intake: the intake answers after its own commit and does not wait for the bus.

Operating it

  • Migrations are forward-only and embedded in the binary: obsp-gateway migrate --database-url ... --database-password-file .... The dataplane-migrate job runs it, and in compose it runs once before the replicas start. A changed migration that was already applied is refused (checksum). Concurrent runs wait on the migrator’s lock. Each run also creates the event partitions of this month and the next two. Run it at least monthly, for example with every release; an event that lands in the default partition makes a later partition for that month impossible to create.
  • Probes. GET /livez answers 200 while the process serves. GET /readyz answers 200 when every migration is applied and the gateway is not draining, and 503 otherwise.
  • Drain. On SIGTERM a replica turns not ready at once, stops accepting connections and finishes the requests in progress. It exits 0 within --drain-seconds (25 in the manifests, under the 30 s termination grace). Evidence: tests/drain.rs.
  • Tracing. Requests carry W3C traceparent (observability). OTEL_EXPORTER_OTLP_ENDPOINT exports spans, and --log json writes structured logs.
  • Pool. --database-pool sets the connections per replica (16 in the manifests). Keep the sum over the maximum replicas below the database’s connection limit.

Backup and restore

infra/deploy/scripts/dataplane-backup.sh <folder> writes four things:

  • pg_dump (custom format);
  • a manifest with the row count and an MD5 digest of every record table, taken from the same exported snapshot as the dump;
  • the object store (a file store; for a bucket, copy it with the operator’s tool after the dump);
  • the complete-line prefix of a JSON-lines store.

dataplane-restore.sh <folder> restores into an empty database, object folder and store file. It refuses anything else. It checks, in order: the backup’s checksums; the manifest’s table digests; the append-only triggers; every object’s digest; the store’s digest.

It also refuses a target whose transaction counter is not past the backup’s highest transaction id. The relay orders the change feed by transaction id, so restored rows would otherwise sort after new ones. On a fresh cluster, first advance the epoch of its transaction counter (pg_resetwal --epoch, with the server stopped). Managed services restore their own point-in-time copies within the same counter.

make dataplane-restore-test (with OBSP_DRILL_ADMIN_URL) is the drill, 17 checks:

  1. Load two gateways, one on PostgreSQL with offloaded payloads and one on a JSON-lines store, and record a correction.
  2. Back up while both serve.
  3. Restore, and check that gateways on the copies serve the same records, payloads and correction state, and answer a known idempotency key from the restored store.
  4. Check that the restored gateways accept new writes, and that the triggers still refuse an update.
  5. Check that a restore into a database that holds tables is refused, and so is a backup whose bytes changed.

Last run: every check passed. The drill found and fixed a race in the file object store (two writes of one object shared a temporary file name).

Capacity

See reference/rust/obsp-load/RESULTS.md. On one shared 4-thread machine, with the harness, the replicas and PostgreSQL all on it, the measured throughput is:

  • about 17 000 to 19 000 events per second on PostgreSQL, with 1, 2 or 4 replicas;
  • 38 000 to 41 000 events per second on the in-memory store.

This machine is CPU-bound. Per event, the gateway uses about 108 µs and PostgreSQL about 86 µs. The target of 100 000 events per second per region was not reached here. By those figures it needs about 11 gateway cores and 9 database cores; that is an estimate, not a measurement. Correction propagation was at most 232 ms on one machine, against an objective of 60 s or less. It has not been measured across regions.

Not done

  • No deployment, account, domain or secret exists. The database address and range, the object store, the subscribers and the federation peers are owner decisions (owner-decisions.md).
  • The compose services for PostgreSQL, NATS and the object store emulator were checked statically (tests/test_infra.py, docker compose config). No container engine ran in the environment where they were written.
  • PostgreSQL scales up, not out. Partitioning tenants or regions over several databases is not built.
  • Payloads offloaded to the object store are not matched by find_payload’s member lookup (the 0.2 candidate’s time-quality lookup), because only their digest is in the database.
  • The relay does not carry the intake request’s traceparent into the CloudEvent.