Pick by how the answer is read
on_changeis the policy for filters and ranking, since each document’s answer stays current. It is also the most expensive policy, because Brussle judges each change to each document and to what it reads. Brussle storesperiodicandmanualanswers, so you can filter or rank on them too. You cannot filter or rank onon_readanswers, which exist only after something reads them.on_readis the default. Brussle judges the document the first time a get or a query includes the answer, and keeps the answer until something that it reads changes, so a namespace with onlyon_readjudgments costs nothing until someone reads an answer. The first read returnspendingunless it setswait_ms.periodicjudges again each document whose answer is older than theinterval, whether or not anything that it reads changed. The interval is at least1h, and Brussle refuses a shorter one withinvalid_request. A change between runs does not judge the document, so its answer readsstale. In a large namespace aperiodicjudgment is a backfill that repeats, and Brussle bills it as a backfill, with its projected monthly cost in the namespace’s stats.manualanswers change only when you run a backfill.
periodic. Brussle does not read the clock when it judges, and a relation’s window counts back from the newest write rather than from now, so a periodic run of a document that did not change gives the engine the same text again. Use periodic only when you need each answer judged again at least once in each interval, for example:
- The engine’s behaviour can change on an engine version that is not pinned (such as
jevcurrent), and a new behaviour never makes an answer stale. Aperiodicjudgment gives each answer the engine’s current behaviour, at most one interval late. - You prefer to judge changes in scheduled runs rather than as they happen. Each run also judges the documents that did not change, so
periodiccosts less thanon_changeonly when most documents change many times in each interval.
Read whether an answer is current
Each answer has afreshness field whatever the policy (fresh, pending, stale, failed or unavailable), so read it before you act on the answer. A stale answer gives its cause in stale_reason, and freshness gives every state and reason. The policy, the fan-out and the budget cause these reasons:
document_changedoranswers_changed: something that the answer reads changed, and the policy ison_read,manualorperiodic.interval_elapsed: aperiodicanswer is older than its interval.judging_paused: something changed while judging is paused, for example by the budget.limit_reachedorreferenced_changed: a fan-out waits, or does not include this document.budget_reached: something changed after the judgment used all of its own budget for the day or billing period.
answers: "fresh_only" to a query to read only current answers. The query leaves out each document whose included answers are not all fresh.
Switching to on_change
The policy is a setting, so changing it does not make a new version of the judgment:
on_change judgment needs an answer for each document, so you switch in three steps:
- Send the update without
confirm=True. The call changes nothing and returns a backfill estimate, with the cost and the duration, for the documents that have no current answer. - Read the estimate.
- Send the update again with
confirm=True. Brussle switches the policy and starts the backfill.
replay, the cost for one month from then on, replayed from your writes of the last 30 days. When you create such a judgment with on_change, Brussle returns the same replay estimate and creates nothing until you send confirm=True. See the replay estimate, and what “at least” means there.
Chatty documents: debounce
Setdebounce_ms to judge a document once when it stops changing, rather than on every save. Say the material_change judgment compares a contract with its previous version (see change detection), and an editor saves the contract every few seconds while they work. With debounce_ms set to 2,000, a burst of 50 saves makes one evaluation, which Brussle runs about two seconds after the burst ends.
- Any policy can set
debounce_ms, which defaults to 0, or to 10 minutes for a judgment created with features. - Brussle does not yet judge a document that changed less than
debounce_msago. When the document stops changing, Brussle judges only its newest revision. - Brussle merges fast writes even without a debounce, and the engine always sees the newest revision at the time that Brussle judges the document. A debounce adds a wait on top of that.
Documents that never settle: the ceiling
Setmax_wait_ms so that Brussle still judges a document that never stops changing, such as a contract that a team edits every minute for a full day, or a customer that gets a new payment every few minutes. Neither one ever ends its debounce.
Brussle judges such a document at the first of these two times:
- The document had no change for
debounce_ms. max_wait_mspassed since the oldest change that Brussle did not judge.
- Defaults. The default ceiling is 12 ×
debounce_msfor a judgment with related documents and adebounce_msabove 0. With no debounce there is no wait, so there is no ceiling, and all other judgments default to no ceiling too.GETreturns the value that applies. - Bounds.
max_wait_msmust be at leastdebounce_ms, andnullmeans no ceiling. - A setting. A change to the ceiling does not make a new version, as with the debounce. A lower ceiling gives fresher answers and more evaluations.
Loads of related documents: wait for their answers
Setwait_for_children to judge a document that reads other judgments’ answers once per load, after those answers land. Take the invoice_settlement judgment, which reads the payments that settles matched to an invoice (see read the matches from the invoice). When you load new payments, the invoice has a change at once, while the payments’ settles answers come some seconds later. Without the setting, Brussle can judge the invoice while those answers are pending and again when they land, which makes two or more evaluations for one load.
- Brussle does not judge the invoice while an answer that it reads is
pending. When the answers land, Brussle judges it once, so a load costs one evaluation of the invoice. - The invoice’s answer comes later, by about as long as the payments’ answers take, and reads
pendinguntil then. - Brussle does not wait for an answer that reads
stale(limit_reachedorjudging_paused),failedorunavailable, since no new answer is on its way for these. - The wait has a bound. Brussle judges the invoice at the latest when
max_wait_mshas passed after its oldest change that Brussle did not judge. With no ceiling in effect, the bound is 10 minutes. The invoice then reads the answers that it has, and its evaluation shows the payments that were behind aschild_pending. - Only a judgment that reads answers can set
wait_for_children, and other judgments refusetruewithinvalid_request. The default isfalse. - A change to it does not make a new version, as with the other freshness settings.
Fan-out: when a referenced document changes
Setfreshness.fanout to decide which documents Brussle judges again after a change to a referenced document, and when. The referenced document is the one that the judged document points at (an order line points at its product, for example).
When the part of the referenced document that the relation shows changes, Brussle judges again the judged documents that point at it, which we call a fan-out. A fan-out judges again only the judged documents inside the re-judge scope, and freshness.fanout sets which judged documents are in the scope and when Brussle judges them.
A change to the block of a blocking relation fans out in the same way, to the documents in the block.
The fanout keys are settings like the rest of freshness, and a PATCH changes only the keys that it sends, merges scope key by key and makes no new version.
- The scope counts from the time of the change, not from now, so the scope of one change stays the same, however long its fan-out waits.
- A judged document outside the scope is not judged again. Its answer reads
stale(withstale_reasonreferenced_changed), soanswers: "fresh_only"leaves it out, and its watermark shows which version of the referenced document it read. Its next own write judges it again. - Only a change to what the relation shows counts. An edit to a field that the relation does not show does not fan out, and neither does a move inside a band. Neither starts the debounce.
- The fan-out has its own debounce. The judgment’s
debounce_msandmax_wait_msstill apply to the writes of the judged documents, so Brussle judges a new judged document in some seconds. - Only
on_changefans out. Under the other policies, a change makes the answers in the scopestaleinstead. - The namespace sets
share.shareis the maximum part of the namespace’s engine requests in progress that fan-out can use, half by default (see namespaces).
pending from the change until Brussle judges them again.
When Brussle defers a fan-out past the rolling limit:
- The answers in the scope read
stale, withstale_reasonlimit_reached. - The events feed records
judgment.limit_reached. - Brussle judges as many of the deferred documents as the 30-day window has room for, at most 1,000 at a time, and the rest wait. They run as older re-judgments leave the window, or when a
PATCHraisesrolling_limit, usually within a minute, and need no confirm. - A fan-out larger than the full limit runs in parts as room appears, so raise the limit above it, or set the limit to
null, to run all of it at once. - No event marks the catch-up. Each answer reads
stale(limit_reached) until Brussle judges it again, andfreshafter that.
Budgets
Set a namespace budget to cap its judging cost in each billing period. Brussle prices each request to the engine before it sends it. If the next request does not fit in what is left, Brussle pauses judging and never spends more than the budget. Your organization’s owners and admins get an email. While judging is paused:- Documents that changed read
stale. - Documents that Brussle never judged read
unavailable. - For a large write, Brussle judges documents up to the last one that fits, and the rest wait until you raise the budget or the next billing period starts.
- Writes continue, unless the budget sets
"on_exceeded": "reject".
Budget per judgment
Setfreshness.budget to cap how many engine calls one judgment makes in a UTC day or in your organization’s billing period:
PATCH changes it without a new version, and null removes it.
When the judgment reaches its budget:
- Brussle sends nothing more to the engine for it, and bills nothing more for it, until the period ends.
- Documents that changed keep their last answers, which read
stalewithstale_reasonbudget_reached. Documents that Brussle never judged readunavailable. A read does not judge them. - The events feed records one
judgment.budget_reachedfor the period. - The judgment’s other documents, and the namespace’s other judgments, carry on.
PATCH that raises the budget starts them within seconds. When more than one worker judges the namespace at the same time, each other worker can send up to 16 calls past the budget before it sees the count.
A judgment with a budget below its rate of change stays behind by the difference: each period judges the oldest waiting changes first. budget_window on the judgment’s GET shows the calls so far, reached_at and resumes_at, and the last 7 days with a 30-day month projected from them, so you can choose a budget before you set it. For a judgment on your own provider key, the projection’s vendor_cost_usd is estimated at your provider’s list price, and is null when Brussle does not know the price. On a template, each namespace counts its own calls against the budget.