Skip to main content
Some answers depend on one other document that the judged document names. Brussle reads that document beside it and judges the answer again when it changes. Each answer says which revision it read and whether it is still current. An answer to “Does this order line agree with the product that it names?” depends on the product (its unit, its price and whether you still sell it). The judged document holds the id of that other document in one of its attributes, and the document that id names is the referenced document:
  • an order line reads its product
  • a message reads its conversation
  • a task reads its project
Brussle judges again the documents that point at a referenced document when that document changes. This work is a fan-out, the main cost of this kind of judgment. Control what a change re-judges shows what it costs and how to bound it. Related documents covers the other direction, where many documents point at the judged document (a contract and its amendments), and relations compares the kinds.

Define one

The relation’s join is {"theirs": "id", "mine": "attributes.<name>"}, where the judged document’s mine attribute holds the id of the referenced document. Here each document of kind order_line points at a product through attributes.product_id:
  • applies_to sets which documents the judgment judges, answers and bills (here the order lines, not the products).
  • One document. The relation reads one document at most, so related.product has one record at most and count is 0 or 1. It takes no window (a window is invalid_request), and with a last_n it reads a list of documents instead. match, fields and aggregate work as for any relation.
  • What it points at. The relation is empty when the mine attribute is missing, null or not a valid id, or names a document that does not agree with match. Brussle judges a document whose relation is empty. When the attribute names a document that does not exist, Brussle does not, as a missing referenced document explains.
  • One snapshot. Brussle reads the referenced document at the same point in the namespace’s writes as everything else, so the answer’s watermark also says which revision of it the answer read, and the evaluation’s related_documents names that revision.
  • Bands. {"path": "state.stock", "bands": [1, 50], "labels": ["none", "low", "plenty"]} shows the band a number is in, so a stock of 0 shows as none and 1 to 49 as low. A stock of 50 or more shows as plenty. A stock count that changes each day then changes what the order lines read only when it crosses a band. See bands.
  • fanout sets which order lines a change to the product re-judges. Here it is the open lines created in the 30 days before the change, at most 300,000 in any 30 days. See the controls.
  • confirm. Brussle returns a replay estimate for a version with related on an on_change judgment, and creates nothing until you send confirm: true. What you confirm includes the rolling limit, and after that no fan-out waits for a person.

The reference index

Brussle finds the judged documents that point at a referenced document through a reference index on the mine attribute. The first version that needs the index builds it with a reference_index job (the create response lists it in job_ids), and the judgment’s answers are unavailable until the job is done. The index counts toward the 8 reference indexes a namespace can have, and an attribute that you use in more than one way is one index. A version that needs documents the index does not cover yet (one with a different applies_to, or one that uses the attribute in the other direction) gets a job that builds the index again, and its answers wait for that job in the same way.

Name several documents

The judged document can name a list of documents:
  • the invoices that a payment’s remittance advice names
  • the clauses that a renewal depends on
  • the listings that a complaint names
Your system or a person writes the list as an array of ids in the mine attribute, and a relation with a last_n reads the documents it names. Brussle calls this a named list:
The payment reads the three invoices its invoice_ids names, in list order. Brussle judges again each payment that names an invoice when that invoice changes in a field the relation shows.
  • In list order. related.invoices shows each named document once, at its first place, and at most last_n of them (last_n is 1 to 254). An order, {"by": "created_at"} included, sorts the documents before last_n applies. latest reads the newest by creation of the documents the relation shows.
  • What renders nothing. An id that names no document, or a document that does not agree with match, renders nothing, and the evaluation’s related_documents lists it with unresolved: true. Each document read is listed with its revision. Brussle ignores an entry that is not a valid document id.
  • Arrays and single ids. A relation with a last_n reads arrays only, and one without reads a single id only, so each renders nothing for the other shape.
  • At most 254 ids. Once a judgment reads an attribute as a list, a write of more than 254 different ids to it is invalid_request, and the error names the attribute.
  • Lists that are already too long. Brussle checks the existing documents at create. If a document holds more than 254 ids, the reference_index job fails and names the documents, and the answers stay unavailable. Shorten those lists and create the version again. Arrays in attributes that no judgment reads as a list are not limited.
  • Fan-out. A change to any named document fans out to the documents that name it, with the same scope, debounce and rolling limit as a single referenced document. Each named document has its own debounce, so when several change at once, Brussle can judge a payment once for each of them.
  • Cost. Each id in the list counts whatever last_n shows, so a list of 254 ids is 254 documents whose changes can re-judge the payment. The replay estimate compiles its sample with each judged document’s list, so its size classes follow the lengths of your lists.
  • No window. Brussle refuses one with invalid_request.

Fan-out

A write to the referenced document re-judges each judged document that points at it and is inside the judgment’s re-judge scope, as long as the write changes what the relation shows. What a fan-out costs works through the numbers, so read it before you rely on a fan-out.

The controls, in order of effect

The re-judge scope, bands and the fan-out debounce bring the cost down. The controls lists each one with its default.

The rolling limit

The re-judges count against the judgment’s rolling limit, 300,000 in any 30 days by default. Past the limit the rest waits, and its answers read stale (limit_reached) until there is room (see the rolling limit).

What the answers show

  • In scope. An answer is pending from the moment Brussle acknowledges the write to the referenced document, so no read after the acknowledgement sees it fresh against the old revision. It is fresh again when an answer arrives with a watermark at or above the change.
  • A write that changes nothing shown. The answer stays pending only until Brussle checks the write, a moment later, and is then fresh again with no engine call.
  • Deferred past the rolling limit. The answer is stale, with stale_reason limit_reached, and the change in its referenced_changes has deferred: true.
  • Outside the scope. Nothing judges the answer again, so it reads stale with stale_reason referenced_changed, and answers: "fresh_only" leaves it out. It keeps its numbers until Brussle judges the judged document again.
  • Only on_change fans out. A change makes the answers in scope stale under periodic and manual, as any related write does, while under on_read a get or query of such an answer judges it again at once.
  • updated_at changes on each write. A relation that shows the referenced document’s updated_at fans out on every write to it, so the create response warns you.
An answer outside the scope still tells you which revision of the referenced document it read:
  • Its watermark and its evaluation’s related_documents give that revision, so if the referenced document’s revision is above the watermark, the answer read an earlier one.
  • On a get, the answer lists in referenced_changes the newest write to each document it points at that changed what the relation shows, with its revision and time.
  • The next write to the judged document itself judges it again, against the referenced document as it is then.
The dashboard’s document view says which of these cases applies.

A missing referenced document

The mine attribute can name a document that does not exist (you deleted it, or the id is wrong), and Brussle never judges the document as if the relation were empty:
  • Only the referenced document changed: no engine call. The answer keeps the numbers of its last evaluation and reads stale, with stale_reason referenced_missing, whatever the policy, and Brussle bills nothing for it.
  • The document itself or its other related documents changed: Brussle judges it. The relation’s entry in the context shows missing: true, so the engine reads that the referenced document is gone. The answer gets the new numbers, is billed as any other, and still reads stale (referenced_missing). A project whose platform page you deleted still shows a blocker in its own new updates.
  • Say what a missing document means. Some engines read missing: true as a sign of risk and some do not, so if a document can be removed on purpose, say so in the question (for example, “If the platform page is shown as missing, it was removed on purpose: ignore it.”). Measure the answers with and without the sentence on your outcomes. You can also unset the reference attribute when you remove the document, which leaves the relation empty, and the answer can then read fresh.
  • Its numbers still count. Queries, thresholds and subscriptions read them as they read any stale answer, so an order line that a threshold flagged stays flagged. answers: "fresh_only" leaves the answer out.
  • A document that was never judged. Brussle does not judge such a document when you first write it, so it has no numbers. Its answer reads stale (referenced_missing), and Brussle judges its next change, as above.
  • When it happens. The answers in scope read pending under on_change until the fan-out reaches them, then referenced_missing, and each counts toward the rolling limit. Under on_read, the first get or query after the delete holds the answer, and later reads do not judge it again. An answer outside the scope reads referenced_changed until something judges the document again.
  • When the document comes back. Write a document with the same id, and Brussle judges the answers again, since the write is a change to the referenced document. If the document shows the same as before the delete, and nothing else the answer reads changed in the meantime, the answers are fresh again with no engine call.
  • Missing is not empty. An attribute that is missing, null or not a valid id names no document, so the relation is empty and Brussle judges the document. The same holds when the document exists but does not agree with match.
  • A named list is different. In a named list, an id that names no document renders nothing, and Brussle judges the document with the rest of the list.

The document a match picked

The document a judgment reads does not have to be in an attribute. It can be the one a matching judgment picked. The matching judgment settles picks the invoice a payment settles, and a payment judgment can read that invoice through a join on the answer of settles, behind one of its thresholds:
settles picked invoice 102 for this payment, below its unmatched threshold, so the payment judgment reads invoice 102 and none of the other invoices in its block. The payment reads the invoice only when all of these are true:
  • settles judges the payment.
  • The current answer of settles names the invoice, and the unmatched threshold is false.
  • The invoice is live, agrees with the relation’s match, and has the same key as the payment.
Otherwise the relation reads nothing. It takes no last_n and no window, like any relation that reads one document. It requires when, and reads nothing else of the answer of settles. Brussle judges the payment again in two cases:
  • The pick changes. settles picks a different invoice for the payment, or starts or stops a link to it. A new answer that keeps the same pick causes nothing.
  • The invoice changes. A write fans out to the payments linked to the invoice, as a change to a referenced document does, when it changes what the relation shows of the invoice, whether the invoice is live or agrees with match, or its key. The fan-out uses this judgment’s debounce, scope and rolling limit, and finds the payments in the invoice’s block through the answers of settles. A block with more documents than the block_cap of settles waits, as any block does. The payment reads pending from the moment Brussle acknowledges the write to its invoice.
Other judgments can read a judgment of this kind only if it has no fan-out scope, as for any judgment that reads a referenced document (see when other judgments read its answers).

Many-to-many, as membership documents

A user can be in many teams, so write one membership document for each pair of user and team, pointing at both with attributes.user_id and attributes.team_id. Then:
  • a judgment on each membership reads its user as the referenced document
  • a judgment on each team rolls up the answers of its memberships (roll-ups)
You need no other join. One user in two teams is two memberships, so a change to the user re-judges both memberships, and each team where the band of its membership’s answer changes. The cost of this design:
  • The team judgment reads the membership judgment, so the membership judgment has no fan-out scope.
  • A change to what the membership judgment shows of a user re-judges every membership of that user, for all time, and these re-judges count against the membership judgment’s rolling limit.
  • Each membership whose band then changes re-judges its team, which counts against the team judgment’s rolling limit.
A user in 50 teams whose plan changes daily makes 50 membership re-judges a day (about 1,500 a month). The same change makes at most 50 team re-judges a day, when it moves their bands. Use applies_to to keep ended memberships out, such as by judging only active ones.