Skip to main content
A freshness policy decides which changes you pay to judge, and how long an answer can stay out of date. Brussle judges a document when its policy says so, then not again until something it reads changes (the document itself, a related document, or another judgment’s answer that a relation shows). A payment that nobody changes for a year, and whose open invoices do not change, costs only its storage. Your cost comes from the changes each month (to the documents and to what they read), not from the number of documents.

Pick by how the answer is read

  • on_change is 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 stores periodic and manual answers, so you can filter or rank on them too. You cannot filter or rank on on_read answers, which exist only after something reads them.
  • on_read is 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 only on_read judgments costs nothing until someone reads an answer. The first read returns pending unless it sets wait_ms.
  • periodic judges again each document whose answer is older than the interval, whether or not anything that it reads changed. The interval is at least 1h, and Brussle refuses a shorter one with invalid_request. A change between runs does not judge the document, so its answer reads stale. In a large namespace a periodic judgment is a backfill that repeats, and Brussle bills it as a backfill, with its projected monthly cost in the namespace’s stats.
  • manual answers change only when you run a backfill.
When to use 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 jev current), and a new behaviour never makes an answer stale. A periodic judgment 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 periodic costs less than on_change only when most documents change many times in each interval.

Read whether an answer is current

Each answer has a freshness 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_changed or answers_changed: something that the answer reads changed, and the policy is on_read, manual or periodic.
  • interval_elapsed: a periodic answer is older than its interval.
  • judging_paused: something changed while judging is paused, for example by the budget.
  • limit_reached or referenced_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.
Add 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:
An on_change judgment needs an answer for each document, so you switch in three steps:
  1. 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.
  2. Read the estimate.
  3. Send the update again with confirm=True. Brussle switches the policy and starts the backfill.
The estimate for a judgment that reads related documents also has 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

Set debounce_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_ms ago. 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

Set max_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_ms passed since the oldest change that Brussle did not judge.
The example sets a 10-minute debounce and a 1-hour ceiling, so a burst of 100 writes in 5 minutes costs one evaluation, 10 minutes after the last write. A document that you write each minute for 3 hours costs 3 evaluations, because the debounce never ends and the ceiling decides. Brussle judges the document about 1, 2 and 3 hours after the first write, and the third evaluation includes the last write.
  • Defaults. The default ceiling is 12 × debounce_ms for a judgment with related documents and a debounce_ms above 0. With no debounce there is no wait, so there is no ceiling, and all other judgments default to no ceiling too. GET returns the value that applies.
  • Bounds. max_wait_ms must be at least debounce_ms, and null means 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.
For a judgment with related documents, a change also includes a write to a document that points at the judged document, and a change to another judgment’s answer that a relation shows. The ceiling counts from the oldest of these changes that Brussle did not judge. A busy customer can get new related documents or answers all the time, but the ceiling makes sure that its answer is not late for ever. The answer is late by the debounce (usually some minutes), and at most by the ceiling. Set wait_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 pending until then.
  • Brussle does not wait for an answer that reads stale (limit_reached or judging_paused), failed or unavailable, 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_ms has 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 as child_pending.
  • Only a judgment that reads answers can set wait_for_children, and other judgments refuse true with invalid_request. The default is false.
  • A change to it does not make a new version, as with the other freshness settings.

Fan-out: when a referenced document changes

Set freshness.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 (with stale_reason referenced_changed), so answers: "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_ms and max_wait_ms still apply to the writes of the judged documents, so Brussle judges a new judged document in some seconds.
  • Only on_change fans out. Under the other policies, a change makes the answers in the scope stale instead.
  • The namespace sets share. share is the maximum part of the namespace’s engine requests in progress that fan-out can use, half by default (see namespaces).
The answers in the scope are 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, with stale_reason limit_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 PATCH raises rolling_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, and fresh after that.
Judge a document with the document it points at shows what each setting saves.

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".
Brussle checks each backfill against the budget that is left before the backfill starts (see namespaces).

Budget per judgment

Set freshness.budget to cap how many engine calls one judgment makes in a UTC day or in your organization’s billing period:
A call is one document sent to the engine for this judgment, its retries included. A write that changes nothing the judgment reads costs no call, and neither do shadow samples. The budget is a setting: a 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 stale with stale_reason budget_reached. Documents that Brussle never judged read unavailable. A read does not judge them.
  • The events feed records one judgment.budget_reached for the period.
  • The judgment’s other documents, and the namespace’s other judgments, carry on.
At 00:00 UTC after the period ends, Brussle judges the documents that waited, oldest change first. A 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.