Skip to main content
A subscription sends you an event when a document starts or stops matching a filter, so your system can react to changed answers without polling. It is a saved query whose filter can read answers as it reads any other field. Brussle checks a document only when the answers that the filter reads are settled, so an answer that is about to change never sends an event.
  • When a document starts to match, you get a subscription.entered event.
  • When a document stops matching, you get a subscription.exited event.
Brussle pushes the events to a webhook endpoint, and the events feed also has each event. This subscription tells you when a payment joins the queue of unmatched payments, and when it leaves. It reads 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).
Brussle checks a subscription’s filter against the documents that change. On this page, one such pass over a namespace is a check.

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.
  • NotEq and NotIn on 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.
How sure a number is. On a judgment with features, a filter can read the bounds of the 95% interval of 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

  • name is 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.
  • events defaults to ["entered"]. If you keep a list of the matching documents, add exited, or you never learn that a document left.
  • endpoint defaults to none, and with no endpoint the events go only to the events feed. The endpoint’s namespace_prefix must cover the namespace, or each namespace of a template.
  • include names the attributes and answers to send with each event. Brussle always sends the attributes and answers that the filter reads, and never sends state.
  • bulk is summary (the default) or deliver. See bulk changes.

Status fields

  • status is syncing until the subscription’s first check in the namespace, then live, with the time in live_at.
  • lag_ms is 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_ms reads 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 null while the subscription is syncing.
  • warnings lists problems, such as judgment_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

  • update changes events, include, endpoint and bulk, and cannot change filters.
    • New events, include and bulk apply to the changes Brussle checks after the update.
    • A new endpoint also applies to events that were recorded but not yet sent.
  • delete removes 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, cursor and include, 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.synced event.

What is refused

  • invalid_request:
    • a filter on freshness or on state;
    • a judgment that does not exist, or that is on_read, in the filter or in include;
    • state in include;
    • 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 update that sends filters.
    See limits.
  • plan_required: a subscription on a template prefix below the Team plan, as for templates.
  • unavailable (503, with Retry-After): a create or update that 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: The chain then breaks, so the document can send 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

An entered or exited event has these fields:
  • subscription: its id, name and defined_on (the namespace or template prefix that the subscription was created on).
  • namespace: the namespace of the document.
  • document: its id, revision, incarnation and updated_at.
  • attributes and answers: the attributes and answers that the filter reads, and those that include names, as a get returns them.
  • cause: why the match changed.
    • change: a write or a new answer.
    • fanout or periodic.
    • backfill (with the backfill’s job_id) or resync: 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 (with id, type and timestamp) would be more than 63 KB, Brussle leaves out attributes and answers and sets truncated to true. url still 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’s id and incarnation.
A document that you create again with the same 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 sequence is 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 exited and entered with the same sequence, which the incarnation tells 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 a pending answer and come back when the answer lands.
  • A filter over two judgments waits for both.
  • A subscription’s filter cannot use the freshness field, because it sees only settled answers.
  • Brussle waits only for the answers that the filter reads, so an answer named only in include is sent as it is, and it can be pending.
Freshness says how this rule uses the freshness states, and is a judgment caught up? says how to know when a judgment has settled each answer after a batch of writes. Events follow answer commits by a few seconds.

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 one synced event, with all their job_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.
A judgment that reads another judgment’s answers is judged again when the thresholds or calibration of that other judgment change, and these re-judges are bulk too, counted under 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 the job_id;
  • or cause: "resync".
Live changes win. Answers from fan-outs and periodic judging are live changes, never bulk. When a document has a live change and a backfill at the same time, the live change wins. A definition change is different, because Brussle cannot tell whether the definition change or a live change moved a document. Each document that a definition change moves counts toward its 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.synced event with reason: "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 bulk setting. With summary, it counts in a backfill, thresholds_changed or weights_changed synced event rather than in created. With deliver, it is sent with cause: "backfill" or cause: "resync".
Take a document that matched when you created the subscription and stopped matching before the first check. It sends no 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 as acme/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_on names 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 syncing in 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 id or 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.
See multi-tenant platforms to set up templates.

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.
See limits and pricing.