Skip to main content

Dependency and change tracking

Vox tracks the inputs a derived result reads and dispatches changes to its dependent work.

For the team workflow, see When an input changes.

Dependencies come from actual reads​

A calculation, assessment, membership rule, cached reference or published entity projection reads through a Vox evaluation context. Vox records the data that was actually observed during that evaluation:

  • Entity properties, including properties inside nested objects.
  • Existing entities and entities that do not exist yet.
  • Relations, including a relation that is currently empty.
  • Context memberships, including memberships that are currently absent.
  • Singleton settings shared by many calculations.
  • Named application dependencies, such as an exchange rate or feature configuration.
  • Balances of tracked Accumulators, eg the stock on hand of a position, per entity and key: every change of the balance, or with a threshold read only a change that takes its available amount across one of the thresholds the consumer read with, eg from 6 to 5 but not from 100 to 99.
  • Future instants at which a time-dependent answer may change.

Tracking absence matters. If a product has no stock record today, its availability still depends on that missing record. Creating the first stock record must therefore make the product eligible for recalculation. The same applies to adding the first relation or context membership.

Dependencies are refreshed whenever the consumer runs. If a campaign stops affecting a product, the next successful evaluation removes that relationship from the graph instead of leaving a permanent subscription to obsolete inputs.

Queries depend on what can change their results​

A tracked query, see Calculations, doesn't depend on each entity it matched, so counting thousands of products stores a few dependencies. A change of an entity can only alter a result if the entity matches the query before or after it. A published save captures the values of the fields tracked queries use, before and after, and the dispatcher compares them with the queries the change reaches: through the values that every matching entity has, eg the brand of brand = acme && status = active, or, for a filter without such an equality, through the changes of the fields it reads. Links and memberships that a query filters by reach it through their published changes.

When the result is known not to change, eg a matching product changes another field, or one that's sorted after a full page stays after it, the consumer isn't calculated again. When it isn't known, it is: strings that a database's collation may compare differently, decimals that its column may round, relations, memberships, and values captured by a writer that didn't track the field yet all count as unknown, which only adds calculations, never misses one. A save by a release that doesn't track a field at all, eg the previous release during a deployment that starts tracking it, captures nothing for it, so such a release is deployed with downtime, see Calculations.

The fields a tracked query uses are known when the application is built, except those of a selector, which an editor writes. Saving a selector adds the fields it compares to the fields that saves of its target type capture, on every host and without a deploy. A save on a host that hasn't loaded the new fields yet still saves; its change reaches every tracked query of the type, which only adds calculations until the host has loaded them. Only saves that validate the entity add them, eg an editor's save; a selector written by an import or a calculation doesn't.

A field stops being captured once no saved selector compares it any more, in published content, a draft, a release or at a context. When a selector stops comparing a field, or a draft, release or entity holding one is discarded, published or deleted, Vox recounts the fields that the stored selectors of the target type compare about five minutes later, and at most once an hour per target type, and drops the others. Each host stops capturing a dropped field at its next save of the type. Fields that tracked queries in code use are never dropped. Until a field is dropped, saves keep capturing it and changes of it keep reaching the tracked queries of the type. Reverting a release or restoring a draft's publication that brings back an older selector adds its fields again.

Changes are recorded durably​

Entity, relation, context-membership and named dependency changes enter a normalized change journal. With transactional authoritative storage, the changed data and the records needed to propagate its consequences commit together. A process failure after that commit can delay work, but it cannot make the committed change invisible to the dependency system.

A change is dispatched to the consumers that depend on it once its save has committed, and the work it adds to their outboxes is claimed by a run before the run reads anything. A run completes only the work it claimed, so a change that commits while a consumer is being evaluated always leaves work for another evaluation, whatever order concurrent transactions commit in. Wakeups after a commit and Vox's loops on the processing hosts run the work around that state, which is itself the durable record.

A consumer's dependencies are what it read, so they're stored with its results, after it read. A change that's dispatched while the consumer reads, before its new dependency is stored, can't find the consumer through it. So once a publication has committed, its new dependencies are checked against the changes that were dispatched since the batch started reading, or that are being dispatched, and a consumer that read such a change is evaluated again as ordinary work. A change that no dispatch has picked up yet is left to its dispatch, which finds the stored dependency. The check costs a few statements per batch, whatever the number of fields and addresses its reads span. Dependencies that were stored before the read, eg from the consumer's previous evaluation, need no check: a change after the read reaches them through dispatch. A first evaluation that reads a change dispatched while it read is evaluated once more.

A threshold read of a balance stores, with its dependency, the range of available amounts within which its answer stays the same, and each change of the balance journals the available amount after it. Both the dispatch and the check skip a consumer whose range holds that amount. Comparing each change's amount with the range the consumer read, rather than the amounts before and after the change, keeps this right whatever order changes are dispatched in: a change that leaves the range evaluates the consumer, which reads the current amount and stores its new range. A dependency stored before the read only spares the check when its range is the same as the new one, since a change dispatched during the read was compared with the old range.

The two moments are compared through a database sequence that only counts up, drawn when a batch's work is claimed and when a change's dispatch has looked up its consumers, so the order doesn't depend on any server's clock. Dispatched changes are kept for VoxProcessingOptions.MaxEvaluationAge (10 minutes by default) plus twice VoxDeploymentOptions.LivenessTimeout, and purged in bounded chunks; an evaluation that started longer ago is evaluated again. If a processing host crashes between a publication and its check, the host that takes its expired claim over dispatches the recently dispatched changes again, which reaches every consumer whose check was lost. Work is only completed after its checks, so a crash always leaves a claim behind: a page of recalculations, or a whole batch of assessments, which the host that takes it over evaluates again. A host that stops gracefully finishes the checks it started and releases its claims, so it replays nothing.

A change can have any number of consumers, eg a market that every product depends on. Its consumers are found and scheduled a page at a time, each page committed with the pending work it adds and how far the change has come, so a worker that stops leaves nothing half done and another continues from there. A dependency stored after the dispatch claimed the change belongs to a consumer whose publication is checked, so it doesn't matter whether the pages find it, or the check after its publication does. A turn of dispatching gives both the new changes and the largest ones a bounded number of pages, and holds the largest ones back while the outboxes have a large backlog, so ordinary saves keep being processed meanwhile. The dispatching is part of the change processing that every processing host runs (see background work), and IVoxDependencyChangeDispatcher.GetBacklogAsync tells the lag and the fan-outs in progress.

A consumer also runs at the addresses of drafts, releases and contexts, eg draft or published|Language=sv, where something it reads has content of its own. A change there reaches it through its dependencies. When a consumer records a dependency on something that already has content at a more specific key, eg a Swedish cell of a product that was written before the product's assessment first ran, it's scheduled at that key too, since the change there was dispatched before the dependency existed.

Where consumers run​

What an entity has at a key or in a draft counts only for the consumers that read it: a value counts for a consumer only if the consumer read that field of that entity, or the whole entity. Say a campaign has a Swedish variation of its Title, and each of the 10,000 products in the campaign has a badge calculation that reads the title and a price calculation that reads only the campaign's DiscountPercent:

  • Only the badge calculations run at Language=sv, and only the readers of the products' Badge follow them there, where the Swedish badge differs.
  • The price calculations stay in published content, and so do the readers of the products' other fields, eg a category's product count.

That holds for every kind of content of its own:

  • Calculated results at a key: the results of a calculation that followed a variation of its inputs, and results at chosen keys.
  • Variations, in published content, a draft or a release, eg the Swedish title.
  • A draft's or release's changes: the owned fields it changed. A draft that changes a product's description runs only the description's readers in the draft, and keeps dependencies there only for them, since a draft reads every field it didn't change from published content, see Authoring.
  • Cached reference values at a key count for a consumer that read any field of the entity.

The consumer's own entity counts the same way, by the fields the consumer read of it. Explicit existence, a created or deleted entity and the variation groups a draft changes count for every reader of the entity, and links at a key count for the readers of their relation. A cell that only has values of varying properties, eg the Swedish name of a published product, doesn't count either: every read has those values, so the consumer reads the same at that key as in published content. Memberships are the exception, since those values give them, and are still evaluated at the key.

Nothing is lost by this. A reader at a key gets the fields a cell holds from the cell, and every other field from the general content, so a consumer that read none of them reads the same at the key as in general and has nothing to calculate there. If the entity later gets a value at the key in a field the consumer did read, that is a change of that field at the key, which reaches the consumer through its dependencies, and it runs there. A consumer that reads the whole entity, eg by serializing it, records a dependency on the whole entity and still runs wherever the entity has content of its own. The same rule decides where an explicit recalculation runs a consumer, and which contexts a publication that enumerates contexts gives documents for, see Entity projections.

This is deliberately an at-least-once model. Vox does not depend on the fragile promise that a message is handled exactly once. Repeated wakeups and evaluations are safe; losing the consequences of a committed change is not.

Only affected work runs​

Before queuing work, Vox matches new journal records against the stored dependency graph. Several changed inputs for one product are coalesced into one product evaluation. A burst of price, stock and campaign updates therefore does not need one calculation per input change, nor a scan of every product.

The dependency graph is shared by several kinds of consumer:

  • Calculated fields maintain derived entity data.
  • Context-membership calculations determine where an entity belongs.
  • Evaluated assessments maintain quality, readiness, risk or health results.
  • Cached references refresh denormalized target data.
  • Durable entity projections publish application-facing representations incrementally.

Each consumer keeps its own progress. A failure in one output does not make another consumer forget what it has already processed, and retrying one consumer does not require rebuilding every other output.

The stored graph also explains a change: the admin's Effects tab reads it to show, for a draft or release, which readers' stored results differ there, a level at a time. That inspection only reads; see Effects of drafts and releases.

Policy entities reach what they select​

A campaign, collection or offer whose rule selects the products it applies to doesn't store a dependency per product. A calculation declares that the policy type reaches it, and a change of a policy entity queues, in the transaction of its save, the entities its rule selected before the change or selects after it. Say "Outlet" changes its rule from season = SS25 to season = SS26: the products of either season are calculated again, and the other million aren't, nor do they run to find out.

  • Paged like a recalculation. The processing pages through the matching entities by their published values in the authoritative database, a page at a time, shared between hosts. A host that stops part way through leaves the rest of the pages in the journal, and the next host continues; calculating a page again is harmless.
  • Sitewide policy entities cost what they reach. A campaign that reaches every product calculates every product each time it's saved, and saving it five times in a minute queues five such runs, since queued reaches aren't merged. Change sitewide policy entities in a draft or release, and publish once.
  • The entity's own side. A product whose own change makes it start or stop matching a rule is calculated by that change: Vox keeps the fields that saved rules use per entity type, and a reached calculation runs when one of them changes, also a calculated one in the same pass, eg whether the product is in stock.
  • Concurrent changes. A product that changes while a rule changes ends up calculated with both: a calculation that read the policy entities is checked after it commits, and runs again when a page of a reach of that type was looked up while it ran.
  • Drafts and releases. A policy entity changed in a draft or release reaches the entities in that scope only, and the Effects tab lists them as readers of the change. Rules select by published values, so the reach in a draft or release also includes the entities of the target type that the same scope changed. A policy entity changed in published content doesn't reach the entities that open drafts and releases changed themselves: they get its change when they change again there or are published.

Opting an entity type out​

Some entity types are never part of a dependency chain, eg the stock carriers of a warehouse, which change all the time and that no calculation, projection or assessment reads. Recording their changes in the journal only costs a write per change and its dispatch. A transient entity type, eg a cart, is always left out, whether or not it's declared, and so is every entity type stored in Redis, which stores only transient ones. [VoxNoDependencyTracking] leaves another such type out:

[VoxNoDependencyTracking]
public class StockCarrier : IVoxEntity
{
// ...
}

Its writes record no dependency changes, and neither do the changes of the links of its relations, eg StockCarrier.Location. Its changes still reach the change handlers and subscriptions that want them, see events.

Because nothing records its changes, nothing may depend on it. A calculation, projection, assessment or tracked query that reads a stock carrier, or the carriers at a location through the inverse of StockCarrier.Location, fails when it's evaluated, with an error that names the consumer and the type, rather than silently missing changes. Reads of relations of other types that refer to stock carriers are tracked as usual, since their links change with the entities they're from. The type can't have derived work of its own either: Vox refuses to start when it has calculated fields or calculations, context memberships, projections, evaluated assessments, cached references that refresh when what they refer to changes, or is a context type, and when a cached reference of another type refreshes when it changes. Cached references that refresh when the entity is loaded, or explicitly, work as usual, eg the variant summary of a cart line.

Settling creates a reliable handoff​

A save publishes the saved entity with its own calculated values. Say an import changes a variant's purchase price, and its margin is calculated from it: the save evaluates the margin and publishes the new purchase price and margin together, with one event of the complete change. See Calculations. The product whose price range reads the variant is recalculated in the background, and gets an event of its own when it's published.

Each event is therefore a safe handoff for subscriptions and other consumers: an event never describes an entity with calculated values that don't match its inputs. Vox's search flow indexes the published versions through a durable outbox, and version checks prevent stale work from replacing a newer document. Read caches are refreshed from committed authoritative data and fall back to it on a miss or failure. Durable projection publications keep their own pending work and build state. A channel therefore gets settled results without inventing an arbitrary delay.

Draft and release scopes keep their own dependencies and derived data. A preview therefore shows results calculated from its own graph without contaminating the published flow. A draft or release keeps them only while something a result reads differs there from published content, eg the draft of a category that a product calculation reads. Where nothing it reads differs, the result is the published one, so the draft or release keeps nothing of its own, also once the draft is published or reverted. It thereby stays proportional to what's changed in it rather than to how much of the catalog its changes were checked against. A release that's been published or deleted keeps nothing at all.

Time is an input too​

Some results become stale without an entity write: a price expires, a campaign begins or an offer reaches its end. During evaluation, ReevaluateAt records the earliest future instant at which the answer may change. Vox schedules that recalculation durably and replaces the schedule when a later evaluation discovers a different boundary.

Time-dependent rules therefore use the same dependency and settling model as data-dependent rules. They do not need a periodic scan to discover which records crossed a boundary.

Where the future values are known in advance, eg dated price list entries and scheduled campaigns, a calculation stores them as a timeline instead. Nothing then runs at the boundary: the stored value already holds the next period, and only readers that resolve the current value, with context.Current, run there.

From defensive rebuilds to trusted deltas​

A full rebuild remains useful for initial population, deliberate backfills and recovery. It should not be the normal mechanism that makes an incremental flow eventually correct.

Vox makes the delta path the correctness path: dependencies say what may now be stale, the change journal ensures a committed change is remembered, claimed outboxes make progress explicit, and an event is sent only once the result is ready for delivery. This is what lets a team trust that a change in one source reaches every affected rule and channel without recomputing the entire estate each night.

See Calculations, Events and subscriptions, Entity projections and Infrastructure.