The family atomics rule
The Great Houses of Dune keep their family atomics sealed. A house unseals its atomics only when it has three threats at the same time. Another house betrayed it, Sardaukar landed on its world, and an enemy threatened its heir. Different writes record the threats, and the writes can occur in any sequence. Thus the rule must operate after the write that completes the threats.
In this quickstart, you write a Go program that keeps these houses in a database. The program founds houses, records threats and shows a live list of the houses with the condition of their atomics. When the program records the last threat to a house, the list must show that its atomics are unsealed.
Without Stardust
A usual design starts with a database schema and a migration for each change to it. The application keeps a query for each write and each read, in an ORM or in its own code. To keep the list live, the application reads a change feed from the database or reads the houses again at an interval.
The unseal rule adds more work. After each write that records a threat, the application must examine the three threats of that house. Each new write path must call this check. A database trigger can do the check, but you write the trigger in the language of the database and not in the application code.
A write path that does not call the check leaves the atomics sealed. When the check runs in a separate transaction, the source write can commit before the derived facts. A failure between those transactions leaves the source facts committed without the rule's result.
With Stardust
Stardust keeps the definitions in the database with the data. The database generates a typed Go SDK from these definitions, so the program contains no query text. A subscription keeps the list of houses live without a change feed or an interval. The unseal rule becomes a reactor that the database runs in each write that changes a threat, in the same transaction as that write. Thus no write path can ignore the rule. All writes use one writer, so the reactor always finds the threats that the previous writes committed.