Unreleased documentation. These pages follow the main branch and can change before the next release. For supported guidance, use v0.48.0.
When you operate indexed external views, keep the projection cache separate from the registry’s own Records and backups. An external value becomes readable only under the current package, deployment binding, source grant, local profile, and expiry. Refreshing the cache does not create a Record revision.
Provision and bind
Section titled “Provision and bind”Indexed projections require separate migration and runtime PostgreSQL roles. Activation and startup refuse a shared role; packages without indexed projections can keep their existing role layout. The migration role installs the projection store when the compiled project contains an indexed projection. A project with live projections only, or without external projections, does not install this store. The store has four tables: projection scopes, refresh receipts, snapshots, and values. The migration role installs the refresh queue with it: a plans table, a work table, and the work table’s sequence. The runtime role can read the four store tables and execute their bounded functions. It cannot insert, update, or delete their rows directly. It reads and writes the two queue tables.
The migration-installed binding function contains the compiled projection allowlist, and its definition is part of the managed catalog fingerprint. At startup, each configured deployment binding binds its allowlisted slot under the exact active package and activation, one projection at a time. A restart with the same binding, source grant, and cache lifetime reuses the stored epoch, so the cache stays warm.
The binding and source grant fingerprints cover only what grants authority over cached rows: the reviewed pack contract, the operation, and the allowed fields. Renewing the grant cutoff, replacing a CA bundle, moving an endpoint, or changing acquisition limits keeps the stored epoch. A changed contract, operation, allowed field list, or effective cache lifetime starts a fresh epoch at the next start. A purged scope whose binding is still configured also starts a fresh epoch. Rows under every older epoch are left for the retention worker, and a purged or replaced epoch never becomes readable again.
allowedFields in the deployment binding is the runtime operator’s own approval of which outside fields Base Registry Engine (BReg) may copy.
It is separate from the fields the package author lists on the projection.
A package that adds a projection field leaves that projection unavailable until the operator adds the field to allowedFields.
The refusal names the field and the path /externalSources/{id}/allowedFields.
Each projection’s scope covers its own declaration and its external Record type. Editing a view, an access profile, or another projection keeps its cache. Changing the projection’s own declaration resets its scope during package activation and requires fresh acquisition.
The migration installs the queue and the compiler-owned lookup indexes. Activating a package that removes the last indexed projection drops the refresh queue first, then the store, so the retired declaration leaves no cached source data behind in the live database. To stop acquisition without changing the package, remove the projection’s source binding and refresh plans from every BReg instance and restart.
A projection that cannot bind leaves only its own views unavailable.
Its binding can fail its own checks, its source grant can have expired, or the database can refuse its scope.
Those views answer 503 with the source.unavailable Problem, whose fieldPath is /externalProjections/{id}, and other views keep serving.
Startup logs each unavailable projection with the reason, and bregctl doctor reports each one as an external-projection.unavailable warning.
A doctor check binds and rolls back, so it never moves a serving scope to a new epoch.
A link takes its identifier scheme from its projection: the external Record type’s identifierScheme for a cardinality-one projection, or the projection’s selectorScheme for a cardinality-many projection.
Links from the same local field must use projections that share one selector scheme; the compiler refuses a conflict at the link’s fromField.
Write access to a link’s fromField chooses which outside subject BReg fetches.
Whoever can set that field on a root decides which subject the source is asked for under the deployment’s source grant, and which subject’s values readers of that root then see.
Grant write access to a link field only to identities trusted to assert that link, and review changes to it as you would review a disclosure.
A source states a decimal field as a JSON number, and BReg serves it as a string. An integer keeps its exact digits. Any other number is read as a double, so a value with more than about 15 significant digits is rounded before BReg serves it. A source that needs exact decimals beyond that cannot send them as JSON numbers, because BReg does not accept decimal strings from a source.
Set freshness and understand purge
Section titled “Set freshness and understand purge”cacheTtlSeconds is the one cache lifetime of a source result.
A deployment binding can set its own cacheTtlSeconds to shorten, but never extend, the authored value.
The lifetime is measured from the original source observation time, not from refresh completion.
The effective expiry is the earlier of that lifetime and the deployment binding’s source grant cutoff, grantValidUntil.
From a successful source response, BReg honours only no-store; it reads no other expiry or storage permission there, so set grantValidUntil no later than the source permits storage.
There is no retention period after expiry: an expired value is purged.
A captured snapshot stores the observation time and a keyed revision reference when the source supplies a revision. The reference is scoped to the bound source.
Replaying an accepted result keeps its original expiry.
A refresh that fails because the source is unavailable, returns an incomplete result, or cannot be acquired under the current binding keeps the previous snapshot of either kind until its own expiry, without extending its lifetime.
Explicit grant denial, or a successful source response marked no-store, removes the previous snapshot, making coverage unproven, fenced against newer publications.
A no-store on an error, a redirect, or the authentication challenge that starts a credential refresh changes nothing: that refresh fails as unavailable and keeps the previous snapshot.
A successful source response marked no-store cannot enter the indexed store, even when a later step of the same acquisition fails.
If it supersedes an earlier retained result for the same subject, the guarded retention-refusal path removes that result, and an older refresh cannot erase a newer publication.
Reads check expiry independently of the refresh job.
Indexed predicates, sorts, and counts refuse incomplete coverage before selecting matching rows.
A plain list over a to-one link, including its continuation pages, serves each uncovered root with availability unavailable and no external fields, and reports page status unavailable.
A list over a related collection has no row to mark for an uncovered root, so it refuses incomplete coverage unless it reads one root; that root’s first page answers with no rows and status unavailable.
Each page reads coverage, rows, and any count from one statement snapshot, so a count always matches complete coverage at that moment.
A refresh records each key in its own short transaction, so a read waits for at most one key’s publication and can show new values for some keys of a page in flight and previous values for the rest.
A nextCursor stays valid while refreshes publish or fail individual keys, and the next page reads the values current when it runs.
A row whose ordering value changed between pages can appear twice or not at all.
A cursor is encrypted and authenticated with the deployment’s cursor key and bound to its caller, query, and projection generation, so the client cannot alter or read its contents, including the sort value it resumes from.
A sort value resumes from up to 6144 bytes.
When the last row of a page carries a longer sort value, or its cursor would exceed the 8 KiB cursor payload, that page’s request is answered source.unavailable and no nextCursor is issued.
The cursor payload counts the key, query, and sort value, with quotes, backslashes, and control characters counted as their JSON escapes.
When that happens the earlier pages were served and the listing stops there.
Every cursor the server issues is one the next page accepts.
Purging or resetting the projection, or moving it to a fresh epoch, invalidates outstanding cursors.
A complete empty related collection is covered; a partial collection, source failure, or protected-existence response is not evidence of emptiness or absence.
A read of one Record looks only at that Record. Every other indexed page, including each continuation page, computes coverage, root presence, expiry, and any count over every root the caller is authorised to read before it selects its rows. Its cost therefore grows with the caller’s whole authorised population, not with the page size. Grant indexed views only to access profiles whose row boundaries are narrowed to the Records their callers need, and rate-limit the callers of indexed queries, source changes, and one-root refresh requests at the gateway.
A root whose link field is empty or unset names no outside subject.
It counts as covered, reads with its external fields absent or as an empty related collection, and its refresh sends no source request.
A root whose link key the store or the source contract would refuse is never sent to the source.
The store refuses a key over 1024 bytes or with a control character, and the source contract also refuses a key over 512 bytes or with leading or trailing white space.
Such a root reads as having no outside value, like a root with an empty link field, for that Record alone.
It is covered, its external fields are absent, and lists, predicates, sorts, and counts over its view keep serving the other Records.
The refresh still logs and counts the key as invalid-key and as unavailable in its report, so you can find and correct it.
A write of such a key to a field an external view links from is refused as request.invalid on create, patch, Action, Proposal, batch, and import writes, and it writes nothing.
Two paths differ: a mutation returned in an Action hook’s answer is refused as hook.proposal.mutation_refused, and the SQL steps of a history migration write current rows without this check, so reads guard those rows.
The same value in a field no view links from is accepted.
A key stored before the view was configured is read as having no outside value, as described above, until it is corrected.
A label sweep applies the same rules to each related row’s label key, so one invalid label key leaves only that row without its label.
The retention worker runs every five seconds. Each pass deletes expired snapshots, refresh receipts whose lease has ended, and everything under purged or replaced epochs, in at most eight batches of a thousand rows of each kind. The same pass deletes queued work that has expired or belongs to an inactive plan, an older plan generation, or a purged or replaced epoch. It deletes an inactive plan once it has no work left and 24 hours have passed since it changed. Freshness enforcement keeps expired values out of responses even when refresh or purge is delayed, but an expired value stays stored until a pass deletes it. That happens while the database is down, while the server is stopped, and while a backlog larger than one pass drains. Size database capacity for the backlog. Where a storage obligation is strict, choose a cache lifetime shorter than that obligation by more than the worker interval and the time you need to recover from those conditions, and watch the signals in the next section. The cache tables are ordinary logged PostgreSQL tables, so the WAL, WAL archives, streaming replicas, and physical backups carry cached source values. They need their own retention policy; see Physical backups, WAL, and replicas.
Monitor refresh and purge
Section titled “Monitor refresh and purge”Each signal names the projection and a fixed reason category. None carries a source key, a selector, a value, or a secret.
- A retention pass that deletes cache rows logs one
infoline per projection and reason, withsnapshotsandreceiptscounts. The reason isexpired,replacedfor an epoch that a changed contract, operation, allowed field list, or cache lifetime replaced, orwithdrawnfor a scope thatpurgemade inactive. - A retention pass that deletes queue rows logs
external refresh retention removed queue stateatinfo, withworkandplanscounts. - A retention pass that fails logs
external projection retention tick failedaterror, with areasonofregistry-not-ready,lock-timeout,query-cancelled,database, ordeadline. It names no projection, because one pass covers them all. - A retention pass that reaches its batch bound logs a
warnline. The rest of the backlog waits for the next pass. - On the metrics listener,
breg_worker_last_success_age_seconds{worker="external-projection-retention"}reports the seconds since the last completed pass. It is absent until the first pass completes. Alert when it grows well past the five-second interval. - A refresh page that acquired keys logs one
infoline with itspublishedcount, and onewarnline per failure reason with akeyscount. The reason isdenied,retention-refused,unavailable,incomplete,invalid-binding, orabandonedwhen a newer result, a changed root, or a changed collection superseded the result before publication. - A refresh page that holds link keys or label keys the store or the source contract would refuse logs a
warnline with the reasoninvalid-keyand akeyscount. Those keys are never sent to the source, and the Records that hold them read as having no outside value until the keys are corrected. - A live read whose root holds a link key the store or the source contract would refuse logs one
warnline with theview, the reasoninvalid-key, andkeysof 1. The key is never sent to the source and the Record reads as having no outside value. - Each refresh worker step logs
external refresh step completedatinfowith the plan, its outcome, and counts of processed, published, reused, retried, and settled items and of sweep acquisition failures. - At startup, a plan that cannot resolve logs
external refresh plan is unavailableatwarnwith its path andbreg.external-refresh.*code. Other plans and views keep serving. - A live read whose source acquisition fails logs a
warnline with the same reasons as a refresh key, other thanabandoned. The view answers unavailable. bregctl doctorreports each projection a server would serve as anexternal-projection.statusadvisory. It gives the time the source grant expires and, for an indexed projection, when the newest snapshot it holds was observed. Renew a grant before that time. An old or missing newest snapshot means the refresh sweep is not running.bregctl doctorreports each plan as anexternal-refresh.statusadvisory, and warns withexternal-refresh.grant-expiredwhen the source grant has expired andexternal-refresh.ttl-headroomwhen the plan interval reaches the shorter of the cache lifetime and the remaining grant.bregctl external-projection inspectreports the expired snapshots that the retention worker has not yet deleted.
Monitor and recover lists the worker signals alongside the other BReg workers.
Refresh plans and the in-process worker
Section titled “Refresh plans and the in-process worker”Add an optional top-level externalRefresh block in your BReg runtime file, alongside externalSources.
Each plan targets one indexed view link and names the worker identity BReg refreshes as.
BReg runs every plan that resolves in process, under that identity.
No scheduler, access token, or step request is involved.
Every indexed link whose projection has a source binding needs a plan; bregctl check reports a link without one as breg.external-refresh.plan-missing.
The following example uses the service profile and a 300-second source lifetime from the external views example project in the repository (at your release tag).
The reviewed project gives that profile List permission on the root Record type and refreshExternalProjections for both indexed projections.
BReg uses the separate credentials under externalSources to contact the authority.
externalRefresh: plans: licensing-holders: target: view: licence-holder-indexed link: holder worker: accessProfile: projection-refresh requesterClient: licensing-refresh principal: synthetic-licensing-refresh rowClaims: jurisdiction: zone-a intervalSeconds: 120 licensing-holdings: target: view: business-holdings-indexed link: holdings worker: accessProfile: projection-refresh requesterClient: licensing-refresh principal: synthetic-licensing-refresh rowClaims: jurisdiction: zone-a intervalSeconds: 120 sourceChanges: holdings-indexed: requesterClient: business-change-notifier requiredScope: registry:licensing:source-changeThe worker’s accessProfile must be declared on the view’s root Record type, grant List on it, grant refreshExternalProjections for the link’s projection, and declare no requireConsent.
Its requesterClient must be one the profile admits.
principal supplies the profile’s principal claim, and rowClaims must pin every claim the profile’s row boundaries use: exactly one value for an equals boundary, and a list of 1 to 64 values for an in boundary.
A plan whose worker identity the profile would refuse does not resolve (breg.external-refresh.worker-not-admitted).
The worker acts with the profile’s required scopes and purposes.
When the profile’s refreshExternalProjections also covers the link’s label projection, the plan refreshes the labels too.
Check the complete file with bregctl check PROJECT --runtime-config FILE.
It reports each plan problem as an error with a breg.external-refresh.* code and the path to fix.
At startup, a plan that cannot resolve is logged and skipped; other plans and views keep serving.
intervalSeconds accepts 1 to 31536000 and is measured from the start of one sweep to the start of the next.
A sweep that runs past its interval is due again when it completes; a sweep with acquisition failures waits at least 60 seconds.
When a target gives up its retries, or a reconciliation request arrives during a sweep, the plan becomes due no sooner than 60 seconds later and no sooner than the smaller of its interval and 15 minutes after that sweep started, so a persistent failure cannot create a tight loop.
Keep the interval, the time to finish a sweep, and a margin for retries inside the effective source lifetime.
Measure them with your number of distinct subjects and the source’s request budget.
pageSize defaults to 50 and accepts 1 to 100.
Collections use a root page of at most 10, and every call observes the bound Adapter operation’s own limits.
A newly registered plan, a plan whose authority changed, and a plan whose projection epoch holds no snapshots are due immediately. PostgreSQL holds the plan lease and the sealed sweep continuation, so another replica can resume after interruption. The plan lease is the only worker serialiser: a worker settles work only while it holds the lease and only for the enqueue generation it read. Steps alternate between ready targets and a due sweep, and each chunk of results is published and settled on its own.
An ordinary Record write queues a local root when it changes a link or a field used by the worker’s row boundary.
The worker rechecks the current root and can reuse a fresh snapshot.
A capture that fails keeps the Record write and logs a warn line with the category external_refresh.capture_failed; the next sweep covers the root.
A source change instead asks for a new observation.
A transient failure retries the affected key on one retry schedule while the previous value keeps its original expiry.
Each plan holds at most 10,000 pending work rows.
The limit is soft: concurrent writers can overshoot it by at most their own batch.
A source change refused at that limit answers 429 and makes the plan due for a reconciliation sweep within 60 seconds instead.
A sweep retry refused at that limit waits for the next sweep without forcing reconciliation.
Removing a plan, changing its activation, authority, or projection epoch, or disabling its indexed projection fences the previous generation immediately. No worker can claim or publish that work, and the retention worker deletes it on its next pass. Adding the plan back starts a current-generation reconciliation instead of reviving the old work.
Source changes
Section titled “Source changes”For source notifications, configure sourceChanges for the link’s projection or its refreshed label projection.
The notifier uses its own verified BReg service client and must hold the configured scope.
It posts projection and selector to POST /v1/external-refresh-plans/{plan}/source-changes.
A 202 acknowledges a committed queue entry.
A repeated change also answers 202 and updates the queued one.
The answer does not report whether an eligible local root exists.
A 429 with Retry-After means the plan’s queue is full.
BReg has already scheduled a reconciliation sweep; retry after that many seconds if the change is still current.
The signed webhook bridge example project in the repository (at your release tag) shows admission, retry, and holdings moves.
A holdings notice fetches the complete current collection for the named parent.
To pick up a move immediately, notify for both parents.
A scheduled sweep reconciles missed notifications.
Refresh one record
Section titled “Refresh one record”A staff application’s service client can ask for one root’s outside values to be refreshed, for example right after an officer corrects the source: POST /v1/external-views/{view}/{link}/records/{root}/refresh.
BReg admits the caller when the selected profile is a service profile that may Get the root and holds refreshExternalProjections for the link’s projection; the compiler refuses that grant on any other profile (refresh-service-profile).
It queues that root’s work with the same upsert a source change uses and answers 202.
The in-process worker settles it on its next tick.
The request is audited as external-projection-refresh.
Inspect coverage
Section titled “Inspect coverage”Use bregctl doctor to see each plan’s external-refresh.status advisory: whether it is registered, due or leased, its pending and ready work, the age of the oldest ready work, its last attempt and completed sweep, and the last outcome.
A completed sweep can have acquisition failures.
An authorised indexed query checks current coverage for the scope that query serves, because the operator’s grant horizon and queue status cannot establish coverage on their own.
In a sweep, a root without a link key counts only as processed, and an invalid key counts as unavailable.
bregctl external-projection inspect reports projection receipt counts by outcome and fresh, expired, and invalidated snapshot counts.
Stop acquisition, purge, and renew
Section titled “Stop acquisition, purge, and renew”Deployment configuration is the only cutoff for acquisition.
To stop acquiring a projection, remove its binding and its refresh plans from the deployment configuration and restart.
Its views then answer source.unavailable.
A binding that stays in the configuration binds again at the next start and acquires fresh data, even after a purge.
Record a source withdrawal in deployment configuration or at the source authority so that it also holds after a backup restore.
Use bregctl external-projection with the runtime configuration.
It connects with the configured migration role, reads no source values, and takes the registry lock.
Runtime cannot execute its maintenance function.
inspect and purge check the active package, activation, and managed catalog in the same transaction, and record an audit request and response under breg-external-projection-audit/v1.
While another session holds the migration lock, they answer external-projection.in-progress and change nothing.
- Remove or update the deployment binding and refresh plans first, then restart.
- Run
bregctl external-projection inspect --runtime-config ABSOLUTE_FILE --projection PROJECTION. It reports the scope epoch, whether it is active, its binding and grant digests, its cache lifetime, the active package and activation, and the counts described earlier. A null epoch means the projection has not bound yet. - Purge with
bregctl external-projection purge --runtime-config ABSOLUTE_FILE --projection PROJECTION. This makes the scope inactive and erases its retained values and refresh receipts. Purge erases data; it does not stop acquisition. The projection’s views stay unavailable until each BReg instance restarts. If the binding is still configured, that start binds a fresh epoch and acquires again, so purge also discards the cache under an unchanged binding. - A renewed binding or grant needs no maintenance. When its contract, operation, allowed fields, or cache lifetime changed, the next start moves the projection to a fresh epoch and leaves the old rows for the retention worker. Otherwise the stored epoch and its cache stay in place.
- Acquire fresh authorised data. A fresh epoch does not assert coverage.
These operations do not change the governed schema or package digest. They mutate only the rebuildable projection cache. A database-only purge cannot be durable across a backup that excludes those rows, so the current deployment or source authority is the durable cutoff.
Back up logically
Section titled “Back up logically”Exclude data from all six projection and refresh-queue tables with one pattern. Keep their schema and functions so a restore retains the package-installed allowlist but starts with no source values, old bindings, refresh work, or selectors. For example, with PostgreSQL service profiles supplying your connections and credentials:
pg_dump --dbname='service=breg-backup' --format=custom \ --exclude-table-data='registry_internal.registry_external_*' \ --file=registry.backupQuote the pattern so the shell does not expand it.
It matches the four store tables (registry_external_projection_scopes, _refreshes, _snapshots, and _values) and the two queue tables (registry_external_refresh_plans and registry_external_refresh_work).
The exclusion does not remove the local identifiers that your own Records hold.
Those identifiers remain part of the registry backup according to its ordinary policy.
Do not use --exclude-table, because the projection and refresh table definitions, privileges, and functions belong to the governed database schema.
After restore, startup registers the current plans and their reconciliation sweeps run under current source authority.
Use a PostgreSQL dump client compatible with the server version. Protect the backup according to the sensitivity of the registry’s own Records. Back up, restore, and drill recovery covers the wider backup procedure.
Physical backups, WAL, and replicas
Section titled “Physical backups, WAL, and replicas”The cache tables are logged. Physical base backups, storage snapshots, WAL archives, and streaming replicas therefore carry cached source values, and the table-data exclusion above does not apply to them. A purge or expiry on the primary reaches a replica through replication, but copies already taken keep the values until they age out.
As the operator, you own that retention:
- Keep WAL archives and physical backups for no longer than the source grant permits storage, or protect and erase them under a separately approved procedure.
- When you restore a physical backup or promote a replica for a deployment whose source authority changed, run
bregctl external-projection purgefor each affected projection on that copy before any BReg instance serves from it, then start BReg. - Treat a replica’s database as holding the same cached source values as its primary.
Restore
Section titled “Restore”Restore with the registry’s ordinary PostgreSQL and instance-claim procedure. Fence the original instance and complete explicit instance adoption before serving the restored database. Preserve the exact package and verify the restored managed catalog and runtime privileges.
Before startup, check the current source grant and deployment binding. A purge stored only in excluded database rows does not survive the restore, so reflect withdrawn source authority in the current deployment configuration or at the source before allowing reacquisition. The absence of cached values prevents old bytes from being served, but it is not permission for a new acquisition.
Startup binds each configured projection using the current reviewed deployment configuration. Indexed queries remain incomplete until authorised refresh covers their eligible roots. Restore does not mark a projection ready or extend any source lifetime. Live reads continue to use their own current source contract and retain no projection copy.
Cookies on Registry Stack
We use optional cookies to understand how you use the main Registry Stack website and this documentation. If you contact us, we may link this activity to your enquiry. You can change your choice at any time. Read the privacy policy.
Your browser asks sites not to track you, so optional tracking stays off.
We could not use or save that choice. Optional tracking remains off.