- When a document starts to match, you get a
subscription.enteredevent. - When a document stops matching, you get a
subscription.exitedevent.
settles, which matches a payment to an open invoice and whose unmatched threshold is true when no invoice is a confident match (see match one record to another).
Write the filter
The filter uses the same grammar as a query, with exactly the same meaning, including the rule for missing fields:- A comparison on a missing field is false.
NotEqandNotInon a missing field are true.
["answers.a.p", "NotEq", 0.5] therefore matches documents that have no answer yet, and you leave them out by adding ["answers.a.p", "Exists", true].
Features. A filter can read a judgment’s features, such as ["answers.invoice_settlement.features.matched_payments.count", "Gte", 2], and a threshold on a feature by its name, as for any threshold.
- The feature must be one of the judgment’s features.
- The judgment counts toward the fields that the subscription carries.
- A feature moves when the answer moves, after the judgment’s debounce, so the event follows the related documents by that same delay.
p, such as ["answers.invoice_settlement.interval.lower", "Gte", 0.8]. The event then comes when the corrected p is above 0.8 with 95% confidence, rather than whenever p itself passes 0.8. The bounds are missing while p is the engine’s. On a judgment without features these fields are invalid_request, since there the corrected numbers are for reading only. When the calibration changes (a new fit.id), Brussle checks the filter again, as it does for p. The bounds can also narrow under the same fit.id as outcomes arrive, and a subscription reads those bounds at the document’s next evaluation. See filter on how sure a calibrated number is.
Filters are fixed. To change a filter, create a new subscription and delete the old one. Brussle would have to check each document against a changed filter again, so the filter would have no true edges. A new subscription does exactly that, and its new name makes it clear.
Create, list and query
Settings
nameis 1 to 128 letters, digits,_and-. A create with the same name and the same settings returns the existing subscription, so you can safely retry it.eventsdefaults to["entered"]. If you keep a list of the matching documents, addexited, or you never learn that a document left.endpointdefaults to none, and with no endpoint the events go only to the events feed. The endpoint’snamespace_prefixmust cover the namespace, or each namespace of a template.includenames the attributes and answers to send with each event. Brussle always sends the attributes and answers that the filter reads, and never sendsstate.bulkissummary(the default) ordeliver. See bulk changes.
Status fields
statusissyncinguntil the subscription’s first check in the namespace, thenlive, with the time inlive_at.lag_msis how long the oldest change that the subscription has not checked has waited.- It is good to about one minute, since a quiet subscription records its progress about once a minute.
lag_msreads 0 until a change waits longer than that. - Use it to find out whether the subscription is stuck, rather than whether it is a few seconds behind.
- It is
nullwhile the subscription issyncing.
- It is good to about one minute, since a quiet subscription records its progress about once a minute.
warningslists problems, such asjudgment_inactive, which means that a judgment the subscription reads or includes was deactivated or deleted. That judgment’s answers stop changing, so the subscription sees nothing new from it. Brussle never pauses or deletes the subscription for this cause.
Update, delete and query
updatechangesevents,include,endpointandbulk, and cannot changefilters.- New
events,includeandbulkapply to the changes Brussle checks after the update. - A new
endpointalso applies to events that were recorded but not yet sent.
- New
deleteremoves the definition, and the next check drops the subscription’s matching set.- Deliveries already queued for an endpoint still go out.
- Events recorded before the delete but not yet sent go only to the events feed.
- The query runs the saved filter with your own
rank_by,top_k,cursorandinclude, and is billed like any query.- It takes a namespace, never a template prefix.
- Its body cannot have
filters. - Use it to fill a new receiver with the current matches, and after each
subscription.syncedevent.
What is refused
-
invalid_request:- a filter on
freshnessor onstate; - a judgment that does not exist, or that is
on_read, in the filter or ininclude; stateininclude;- empty or repeated
events; - more than 24 fields, counting the fields that the filter reads;
- a name that the namespace already has or inherits;
- an endpoint that does not exist, or does not cover the namespace;
- a 101st subscription in a namespace, counting the inherited subscriptions;
- an
updatethat sendsfilters.
- a filter on
-
plan_required: a subscription on a template prefix below the Team plan, as for templates. -
unavailable(503, withRetry-After): a create orupdatethat names an endpoint when Brussle cannot check the endpoint. Nothing changed, so retry the request.
Events are edges, not states
A subscription sends an event when a document’s match changes, and never while the match stays the same. While each change is live, the events for one document alternate (entered, exited, entered, and so on). A document can also join or leave without an event:
- in the first check;
- in a bulk change.
exited with no entered before it. A subscription.synced event always tells you about these silent changes, and that is when to read the members again to correct your receiver.
Event fields
Anentered or exited event has these fields:
subscription: itsid,nameanddefined_on(the namespace or template prefix that the subscription was created on).namespace: the namespace of the document.document: itsid,revision,incarnationandupdated_at.attributesandanswers: the attributes and answers that the filter reads, and those thatincludenames, as a get returns them.cause: why the match changed.change: a write or a new answer.fanoutorperiodic.backfill(with the backfill’sjob_id) orresync: only for the bulk changes that you asked to receive.
sequence: the number of the check that recorded the event in the namespace.url: the get of the document, which you use with your own key to get the rest of the document.truncated: a request body is at most 64 KB, so if the whole event (withid,typeandtimestamp) would be more than 63 KB, Brussle leaves outattributesandanswersand setstruncatedtotrue.urlstill has them.
exited has a reason.
no_longer_matches: the event has the current values, which show why the document left.deleted: the event has only the document’sidandincarnation.
id starts a new life, with a new incarnation, and enters like any new document.
How sequence orders events.
- All events of one check have the same number, and a later check has a higher number, with gaps.
- A higher
sequenceis newer for one subscription and one document, so a receiver drops an event that is older than the one it has. - A document can be deleted and created again in one check, and it then sends
exitedandenteredwith the samesequence, which theincarnationtells apart. - The numbers start again when you delete a namespace and create it again, so forget the sequence numbers you kept for a namespace when you delete it.
Only settled answers count
Brussle checks a document only when each answer that its filter reads is up to date with the document’s current revision, so a write never makes a document drop out on apending answer and come back when the answer lands.
- A filter over two judgments waits for both.
- A subscription’s filter cannot use the
freshnessfield, because it sees only settled answers. - Brussle waits only for the answers that the filter reads, so an answer named only in
includeis sent as it is, and it can bepending.
Bulk changes
A backfill, or an edit to a threshold that your filter reads, can move thousands of documents at once, even though nothing happened to any of them. By default ("bulk": "summary"), these moves update the subscription without an event for each document, and you get one subscription.synced event instead:
reason is one of these values:
created: the subscription’s first check in the namespace is done.backfill: a check finds no more of the backfill’s answers, or 10 minutes passed after the first one, whichever comes first. Backfills that overlap share onesyncedevent, with all theirjob_ids.thresholds_changed: someone edited a threshold that the filter reads, or a new version changed it.weights_changed: a composite judgment that the filter reads got new combiner weights, or a judgment with features that the filter reads now reads a different fit (its first fit, a clearly better one, a pin or a withdrawal). A fit that changes nothing a filter reads changes nothing for the subscription.
thresholds_changed and weights_changed.
Timing. thresholds_changed and weights_changed come within seconds of a change to the setting itself, and for the re-judges it causes, as those re-judges land. Either way they come even if nothing else happens in the namespace. For a template’s judgment, they come from each tenant where Brussle already runs checks, while a tenant where the subscription has not started yet starts with the new settings.
When you get synced, read the current members again with the subscription’s query.
"bulk": "deliver". Use it when your receiver must see each change, since the subscription then gets an event for each document that a backfill or a definition change moves:
cause: "backfill"with thejob_id;- or
cause: "resync".
subscription.synced, or is sent with cause: "resync", even a document that also changed at about the same time.
A new subscription starts from now
A subscription sends events for changes from the time that you create it.- The first check is silent. The documents that already match join without an event, and then one
subscription.syncedevent withreason: "created"says how many joined. Brussle sends it even when no document joined, so it tells you that the subscription is live in that namespace. - Changes after creation are not lost. A document that you write after you create the subscription sends an event as usual, and so does a document that gets a new answer after that time.
- Bulk changes after creation. A backfill or a re-judge can move a document after you create the subscription but before the first check, and that document follows the
bulksetting. Withsummary, it counts in abackfill,thresholds_changedorweights_changedsyncedevent rather than increated. Withdeliver, it is sent withcause: "backfill"orcause: "resync".
exited and never sent an entered, so a receiver built from events and from the reads after each synced event stays correct, while a receiver that listed the matches with a query at creation time does not.
Subscribe across every tenant
A subscription that you create on a template prefix, such asacme/prod/*, applies to each namespace under the prefix, including tenants created later. See templates.
- For each tenant. Each tenant has its own matching set, and its events name the tenant in
namespace.subscription.defined_onnames the prefix that the subscription was created on, so a platform can route events without a lookup. - The start is late. A tenant starts to check a template’s subscription at the next check that Brussle runs in that tenant, which a change in the tenant starts, so idle tenants cost nothing. Until then, the subscription reads
syncingin that tenant. - No opting out. A tenant cannot change, delete or detach a template’s subscription, so to leave a tenant out, add a condition on
idor on an attribute to the filter. - Names. A tenant cannot create a subscription with the name of a subscription that it inherits. A template can create a name that a tenant already has, however, and then both subscriptions run, with the tenant’s own subscription first in the list.
Limits
- A namespace can create a subscription only while it has fewer than 100, counting the subscriptions that it inherits from a template. This limit is the same on all plans, and subscriptions that its template gets later can take it past 100.
- A subscription sends at most 24 attributes and answers, counting those that its filter reads.
- Subscriptions and their events are never billed, but the query is billed like any query.