Events and subscriptions
Vox publishes one event per published entity change. Subscriptions select and deliver those events to other systems.
For the team workflow, see Follow a delivery.
Vox records published entity changes durably and delivers matching subscriptions through the configured transports, including webhooks, RabbitMQ, and Redis streams. Filters decide which entity types and changes a subscriber receives. The events and their deliveries are processed by Vox's own loops on every processing host, which keep the changes of each entity in order and retry failed deliveries, see Delivery.
Events are the handoff from Vox's dependency and change tracking to downstream consumers. An event is sent once a change is published, with its required calculations done, so a subscriber never sees a change before the values calculated from it, see Events are sent for consistent publications.
Using that common handoff across applications avoids a separate event convention and point-to-point synchronization mechanism for every new tool. Producers and consumers share the domain identity, change semantics and consistency boundary even when their user experiences are entirely different.
Draft changes are deliberately not subscription events. They may cause draft calculations, context memberships, caches, and search documents to update for preview, but they remain inside the editorial workflow. Publishing emits the normal published entity change, so downstream systems see only content that has gone live. Reverting a draft emits nothing; unpublishing emits a published deletion while retaining the entity in draft mode.
What a change describes
An entity-change event describes what changed rather than repeating the entity body. It contains:
- The entity type, ID, version and change kind.
- Changed field paths and the links that were added and removed, see Changes of links.
- The context keys whose varying values changed.
- Context memberships that were added or removed.
- Causes such as an action, import, calculation or deletion.
- The first and last time represented by a coalesced change.
This lets a consumer invalidate only the cache or projection affected by a change. A consumer that needs the complete representation can instead use an entity-snapshot subscription.
Changes of links
An event also has the links that were added and removed, in relationChanges, for both reference properties and
index-backed relations, and at both ends of each link. Changing a product's categories from c1 to c2 gives the
product an event with its categories changes, and the categories c1 and c2 events with their products changes,
by the name of the relation as seen from each of them:
{
"entityType": "Category",
"entityId": "c1",
"version": 7,
"changedFields": [],
"changedRelations": ["products"],
"relationChanges": [
{
"relation": "products",
"direction": "Inverse",
"owner": { "entityType": "Product", "id": "p1" },
"forwardRelation": "categories",
"address": "published",
"relationRevision": 108,
"added": [],
"removed": [{ "entityType": "Product", "id": "p1" }]
}
]
}
- Every link has the concrete entity type and id of the related entity, also of a relation that isn't polymorphic, so entities of different types with the same id are different links.
ownerandforwardRelationidentify the relation the same way at both ends. A link to an entity doesn't change its version:versionis its current version, or 0 if it doesn't exist (yet). An entity that links to itself gets one event with both directions.- A change of a reference property is a change of its field in
changedFieldstoo. A reorder of its references is a change of the field only, not of its links. changedRelationsnames the relations ofrelationChanges, and a subscription'srelationsfilter can name any relation of its entity types, in either direction, egproductsonCategory.- Links are sets. An event covers all the saves since the previous one of the entity, so a link that was added and removed again isn't in it.
- Each change has the
relationRevisionof the links of the owner's relation in the scope, which increases with every save that changes them. A consumer that keeps the links orders the changes of each link by it: it applies a change of a link only if its revision is newer than the one it applied to that link last, and keeps the revision of a removed link as a tombstone, so a duplicate or late event can't bring it back. A watermark per entity or per owner isn't enough, since an older event can have the changes of other links. TheeventIdidentifies duplicate deliveries; it doesn't order them. A consumer that lost track of the links reads them again with a snapshot or a synchronization, rather than replaying events. - An event with more links than one holds is delivered in parts, with the same
eventId, the event's other changes in each, andpart/parts, eg1of2. The parts can be applied in any order. - The links of a relation whose property has a data classification the subscription isn't allowed are left out at both ends.
Ordinary subscriptions and in-process handlers get the links of published content, at published. A raw subscription
that chose context types for its sidecar, or opted in to drafts or releases, also gets the links at those addresses, eg
published|Market=se or draft, as what the address does to the inherited links: added and removed for the links
it adds, suppressed and unsuppressed for the inherited links it hides, and overrides when a reference property
starts or stops being set there. Resetting an address to inheritance removes its additions and suppressions. A resolved
subscription with a selection gets the links as they're read in its selection, with its fallbacks, at published, eg a
link hidden in Sweden is a removal for a Swedish subscription and nothing for others. A change of the selection itself,
eg a new fallback, is delivered by synchronizing the subscription, not as changes of links.
A replacement of more links than a complete read of a relation gets (VoxReadBudgets.MaxRelationLinks), eg of a
million, is staged and carried out a page at a time by Vox's vox_relation_replacement background work, whose pages are delivered as
ordinary changes of links while the links converge. Ending a release, cleaning up a deleted context member and purging
an entity remove their links without a change per link: the deletion of the release or member, or the purge of the
entity, tells subscribers.
Events are sent for consistent publications
Vox sends an event when a change of an entity is published. A save publishes the entity with the values of its own calculations, eg a purchase price with the margin and selling price calculated from it, as one event. A calculation that later changes the entity because another entity changed, eg an exchange rate, is a publication of its own with its own event.
That consistency boundary lets a search feeder, storefront cache or external subscriber consume the current result without guessing how long calculations take or reproducing their dependency order. See Calculations for what a save calculates and what follows in the background.
In-process handlers
A change handler reacts to published changes inside each running application instance, eg to invalidate a local cache.
It implements IVoxEntityChangedHandler<TEntity> for the entity types it handles: those assignable to TEntity, so
IVoxEntityChangedHandler<Product> handles products, IVoxEntityChangedHandler<IVoxContext> every context type and
IVoxEntityChangedHandler<IVoxEntityBase> every entity type. A class handles several types by implementing the
interface once for each. Vox finds handlers in the scanned assemblies, like side effects, so there's nothing to register:
public class ProductSearchFeeder : IVoxEntityChangedHandler<Product>
{
public Task HandleAsync(VoxEntityChangedEvent change, VoxInstanceEventContext context) => ...;
}
The instance that publishes a change sends it to every instance as a Nexus instance event right after the commit that
published it: one event for each entity of a publication, also of the processing that publishes the calculations of other entities a
change reached. Unlike a subscription, which gets the changes of an entity since its last event merged into one,
a handler gets each publication: a link added in one save and removed in the next is two events. An event of an entity
whose links are all that changed, eg the category a product was added to, carries the entity's current version.
VoxInstanceEventContext.IsOriginInstance tells the instance where the change was published, so a
handler can separate work that should happen everywhere, such as invalidating a local cache, from work that should
happen only once.
Nothing is stored for the handlers, which keeps handling cheap, also for busy data. The other side of that is that
delivery is best effort: a change whose instance stops between its commit and sending the event isn't handled. Use a
side effect, IVoxEntityUpdateSideEffect<TEntity> (see
Calculations), for work that must follow every
publication, and a subscription to send changes to another system. Handle only the entity types you need, since each
change of a handled type is broadcast to every instance.
Only changes that something needs are events
Recording an event is a write of the change into the outbox, and its delivery and cleanup later. For busy operational data, eg carts in a webshop or stock carriers in a warehouse that change all the time, that's a lot of work for events nobody reads. So a change is only recorded as an event when an enabled subscription delivers its entity type, also one of every entity type. Change handlers get their changes without a stored event, see above. Side effects and the search index read the changes of their entity types as well, and a change of another storage, eg Redis, is still handed to the control plane for them.
A cart that no subscription, side effect, search index or dependency needs is therefore saved with nothing else: no event, no outbox row and no background work to wake, and only the instance event when a handler handles carts.
An application has none or a few subscriptions, so every instance keeps them in memory. Saving or deleting a subscription updates the instance that saved it at once and the others with an instance event, and every instance reads them again at least every 30 seconds in case an instance event was lost. A new subscription of an entity type that nothing wanted before therefore receives its changes from when the instances have picked it up, within moments; use a resend or a snapshot synchronization for what changed before.
Subscription filters
A subscription uses either EntityTypes for broad type selection or Queries for maintained entity-specific
selections. Each VoxSubscriptionQuery contains an entity type and an optional VoxFilter. The supported filter tree
is deliberately smaller than VoxQuery: field comparisons combined with and, or, and not. It has no sorting,
paging, count mode, read scope, draft or release content, unreferenced selection, or assessment filters. Filters have
an explicit JSON kind discriminator (field, and, or, or not).
{
"queries": [
{
"entityType": "Product",
"filter": {
"kind": "field",
"field": "status",
"operator": "Equal",
"values": ["Active"]
}
}
]
}
Vox stores the selected entity IDs as a manifest. Creating, changing, or enabling a query subscription starts a
reconciliation of the manifest with the current published entities. It runs in the background, a page at a time: it
stages the matches as a new generation of the manifest, which changes of single entities keep current meanwhile,
activates it in one short transaction once the scan is complete, and only then delivers what entered and left. A
reconciliation that stops isn't continued: it runs again from the beginning, as a new one, which may deliver some
entities again. Until it's activated the previous manifest stays in place, and the differences of one that was activated
are kept until they're delivered, before anything else, since the previous manifest is the only record of what left it.
Deleting a subscription, or removing its queries, empties its manifest at once, while the stored rows, which can be
millions, are removed in the background a page at a time; GET api/background-work shows how far that has come.
Later events maintain it and classify deliveries as Entered,
Updated, or Left. Change-event subscriptions receive the vox-subscription-event/v1 envelope with that selection
change and the underlying entity event. Snapshot subscriptions receive an upsert snapshot for Entered and Updated,
and a deletion tombstone for Left.
Assessments are asynchronous reporting sidecars and cannot be used in subscription queries.
Both subscription styles can narrow delivery to field paths, relations (by their names as seen from the entity type, in either direction) or contexts. An empty change filter means all relevant changes. Context filters understand both varying values and entity membership: a product is delivered when it changes inside a subscribed market and when it enters or leaves that market.
Subscriptions also declare which data classifications may appear in their payload. Classified values that are not allowed are omitted, just as they are from an ordinary API response. Filtering on a sensitive field requires the corresponding unrestricted classification permission so the filter itself cannot leak information.
Change events and snapshots
A change-event payload is appropriate for a consumer that understands the Vox event model and fetches any data it needs. It is compact and preserves detailed causes and changed paths.
An entity-snapshot payload contains the latest committed representation. It is intended for synchronizing external entities into another Vox application and deliberately permits only explicit locally owned entity types. Retried deliveries converge on the current snapshot, while delete and purge deliveries are tombstones.
A resolved subscription with a selection, eg Channel=ecommerce, keeps the entities it delivered: an entity that
leaves the selection gets a deletion with isWithdrawal, which tells the receiver to stop using it without treating it
as deleted in the source, and an entity it never delivered isn't withdrawn. Its synchronization delivers the members of
its selection and withdraws the delivered ones that left it.
Asset files
A subscription with IncludeAssetContent delivers assets, eg the images of the products in a channel, with an
assetContent descriptor: the file name, content type, length, content revision and an unguessable download URL of the
original, never the bytes. Snapshots carry it, and change events get the vox-subscription-event/v2 envelope with it.
The URLs are made with VoxApiOptions.PublicBaseUrl and served at api/asset-downloads/{token}, also when images
aren't delivered publicly:
- They don't expire, and keep working after the asset leaves the selection, so a paused receiver can finish its queue.
- They return the latest original, with its actual revision in
Vox-Content-Revisionand as the ETag, which range requests continue with only while it's the same. - Disabling or deleting the subscription, revoking its downloads with
DELETE api/subscriptions/{id}/asset-downloadsand deleting the asset stop them. An asset created again with the same id doesn't inherit them.
A grant is one per subscription, asset and selection, reused by every delivery. Only published content is exported, so the option can't be combined with drafts or releases in the sidecar. A receiver marks an asset imported only once its download is stored, and downloads again when the revision it has differs. The download of a broken asset, whose content is missing, returns 404 until its content is replaced, which delivers the asset again with a new revision.
Delivery
Published changes are turned into events, and delivered to subscriptions, by loops that run on every processing host (see background work). Each host claims different entities, so the hosts share the work, while the changes of one entity are handled together and in order.
One delivery per subscription and entity. A subscription has at most one delivery of an entity waiting. A newer change of the entity is merged into it, whether it hasn't been tried yet or waits for a retry, so the subscriber gets the changes in order, and the changes made while it couldn't be reached arrive as one event. Say a product changes twice: version 7 changes the price, then version 8 changes the stock. If the subscriber's endpoint times out on version 7, version 8 is merged into it, and the subscriber gets one event with both the price and the stock change, as version 8. It never gets version 8 first and version 7 after it.
A merged event grows with how much of the entity changed, not with the number of changes: a field that changed five
times is in it once, a link that was added and removed again isn't in it, and neither is a context the entity entered and
left again. It has the newest event's id, version and kind, and the earliest and latest times of the changes. An entity
that entered a subscription's selection and then changed again is still delivered as Entered, since the subscriber
never got it before. A snapshot delivery reads the entity when it's delivered, so it always sends the current state.
A delivery that's being tried right now is never changed: a change that arrives meanwhile waits, and becomes the next
delivery when the attempt succeeds, or is merged into it when the attempt fails.
Attempts. A delivery is tried 5 times, with a growing delay between the attempts: 10 seconds, 1 minute, 5 minutes
and 30 minutes. A delivery that the subscriber rejects, eg a webhook that responds with a 4xx status other than 408 or
429, is given up at once. A given-up delivery stays with the subscription, and nothing else of the subscription waits
for it. A newer change of the entity is merged into it and starts it again with 5 attempts, and so do Retry selected
and Retry all in the subscription's Given-up deliveries in the admin
(GET api/subscriptions/{id}/deliveries/given-up, POST api/subscriptions/{id}/deliveries/retry with the ids, or
without them for all).
A paused subscription. When the deliveries of a subscription have failed 5 times in a row, across its entities, the subscription is paused, so an endpoint that's down isn't tried for every waiting entity. When the pause ends, one delivery is tried. If it succeeds, the other deliveries continue; if it fails, the subscription is paused again, for longer: 5 seconds, 30 seconds, 2 minutes, 10 minutes, 30 minutes, 1 hour, 2 hours, and then 4 hours each time. A short glitch costs a few seconds, and a subscriber that's down for days is tried a few times a day. Deliveries that wait during a pause don't use up their attempts. Say a subscriber is down for 6 hours while 300,000 products change 4 times each: the subscription waits with at most 300,000 deliveries, one per product, and the outage costs about a dozen attempts.
The admin shows a paused subscription and until when it's paused, and the vox_subscription_deliveries health check
is degraded meanwhile, with the paused subscriptions and their last error. Once the endpoint is fixed, Send test
(POST api/subscriptions/{id}/test) checks it, and when the test is delivered it also ends the pause, so the deliveries
continue at once.
Transports. A delivery counts as done once the subscriber, or its broker, has the event:
- A webhook posts the event as JSON to the subscription's URL and is done when the URL responds with a 2xx status. Each
request has the headers
X-Vox-Event-Id(the event's id),X-Vox-Subscription-Id(the subscription's id, which stays the same when the subscription is renamed),X-Vox-Payload(ChangeEventorEntitySnapshot) and, when the subscription has a secret,X-Vox-Signature:sha256=followed by the lowercase hex HMAC-SHA256 of the body with the secret. - RabbitMQ publishes a persistent message to the subscription's exchange, with the event's id as the message id, and is done when the broker confirms it. A message that the broker refuses, or that's lost when the connection drops before the confirmation, is tried again. The exchange must exist. A message the exchange can't route to any queue, eg before a subscriber has bound its queue, is dropped by RabbitMQ without an error, so bind the subscriber's queue before the subscription starts delivering. A Vox application that receives entity snapshots fetches what it missed with its first synchronization.
- Redis adds the event to the subscription's stream.
Delivery is at least once. Consumers should use event IDs or entity versions to make processing idempotent. Disabling or deleting a subscription removes its waiting and given-up deliveries; a disabled subscription retains its definition without delivering new work.
See Import data from another system, Share entities between Vox applications and Users, roles and permissions.