Spectral Foreign Keys
What it is
Section titled “What it is”In a traditional database, every INSERT into a child table triggers a blocking
lookup against the parent’s primary-key index. At high ingest rates — with rows
arriving from many sources at once, and parent rows occasionally arriving
milliseconds after their children — that blocking lookup becomes the dominant
cost, and orphaned children become a constant source of failed loads. Spectral
foreign keys replace the synchronous lookup with an eventually-convergent
integrity model.
When a child row arrives, the engine performs a fast local membership check against a summary of the parent’s primary keys. If the parent definitely exists, the row is accepted and tagged valid. If the parent is missing — or might be missing — the row is still accepted immediately, but the foreign-key column is marked spectral: a third state alongside “valid” and “null”, meaning “the reference is unresolved right now, and the database will reconcile it in the background.”
Why it matters
Section titled “Why it matters”Out-of-order arrivals are the rule, not the exception, at high ingest rates. Spectral foreign keys turn that reality from a data-loss problem into a non-event.
- Ingest never blocks on referential integrity — the check is local work, not a network round-trip.
- Late-arriving parents auto-heal their children — once the parent shows up, the database silently flips every matching child from spectral to valid.
- Configurable expiry policy — if a parent never arrives within the window you choose, the row can be nulled, routed to a dead-letter table, or rejected.
flowchart LR
classDef a fill:#1f2640,stroke:#7c5cff,color:#e8eaf0
classDef b fill:#1f2640,stroke:#00d4ff,color:#00d4ff
classDef g fill:#1f2640,stroke:#4ade80,color:#4ade80
classDef w fill:#1f2640,stroke:#facc15,color:#facc15
CR[Child row arrives]:::a --> CHK{Membership check<br/>against parent summary}:::b
CHK -- definitely present --> OK[Accepted: valid FK]:::g
CHK -- maybe absent --> SP[Accepted: spectral FK<br/>marked unresolved]:::w
SP --> CONV[Background convergence<br/>re-checks on parent arrival]:::b
CONV -- parent appears --> OK
CONV -- window expires --> POL[Apply expiry policy]:::w
How you use it
Section titled “How you use it”Declare a foreign key with the spectral clause. Choose how long unresolved references should be tolerated and what should happen if the parent never arrives. From there, the database does the rest.
-- A high-ingest orders table that references customers.CREATE TABLE orders ( id BIGINT PRIMARY KEY, customer_id BIGINT, amount DECIMAL(12, 2));
ALTER TABLE orders ADD CONSTRAINT fk_customer FOREIGN KEY (customer_id) REFERENCES customers(id) SPECTRAL CONVERGENCE WINDOW INTERVAL '24 hours' ON SPECTRAL EXPIRE NULLIFY;
-- See which rows are still waiting for their parent.SELECT id, customer_id, _spectral_state, _spectral_sinceFROM ordersWHERE _spectral_state = 'UNRESOLVED';
-- Standard JOINs behave as you expect.SELECT o.id, c.nameFROM orders oJOIN customers c ON c.id = o.customer_id; -- excludes spectral rows
SELECT o.id, c.nameFROM orders oLEFT JOIN customers c ON c.id = o.customer_id; -- includes them as NULLThe bare INNER JOIN behaves exactly as relational correctness demands — rows without a confirmed parent are not returned. LEFT JOIN keeps them with a null parent. Aggregations on the child table itself include spectral rows, because the child data is fully valid even when the bond is still resolving.
Maturity
Section titled “Maturity”Spectral foreign keys ship in layers, and not every layer is equally mature:
- Stable — the
SPECTRAL CONVERGENCE WINDOW/ON SPECTRAL EXPIREDDL, the_spectral_stateand_spectral_sincesystem columns, andSPECTRAL OFFstrict mode (a traditional synchronous local FK check). - Beta — single-node background convergence and auto-heal, the
NULLIFY/DEAD_LETTER/REJECTexpiry policies, and JOIN-time spectral filtering. Use these in development and pilot environments. - Roadmap — cluster-wide convergence (an out-of-order arrival on one node converging from a parent ingested on another) and a convergence-statistics dashboard.
The DDL is forward-compatible: write the spectral clause once and it is accepted today, gaining the later behaviour automatically as those layers light up. No schema migration is required between stages.
Key concepts
Section titled “Key concepts”| Concept | Meaning |
|---|---|
| Spectral null | A third foreign-key state: not null, not yet confirmed valid. |
| Convergence window | How long the engine keeps trying to resolve a spectral reference. |
| Expiry policy | What happens at window end: NULLIFY, DEAD_LETTER, or REJECT. |
_spectral_state | A virtual system column exposing the current resolution status of each row. |