Request a demo
← All articles
Real-time

Real-time context: live, cached and as-of

Live queries at request time, TTL caches with stale-while-revalidate, nightly snapshots and an as_of on every answer: how fresh context stays honest.

· 7 min read · For data platform and architecture leads

An agent that answers from yesterday's numbers without saying so is worse than one that answers nothing. Real-time context is not about making every query hit the warehouse; it is about every answer knowing, and saying, how current it is, and about the owner of the context choosing that on purpose.

In InsightCompose a context is served from a governed contract: SQL with typed parameters, a declared row scope, masking rules and a freshness promise. This post is about the last of those. It covers the three ways an answer can be produced (live, cached, snapshot), what the cache is keyed on so two callers never see each other's rows, and the as_of stamp that travels with every answer to whoever consumes it.

Freshness is part of the contract, not a property of the pipe

Most data platforms describe freshness from the pipeline's point of view: the job runs at two, the table lands at three. The consumer of an answer does not care about the job. It cares whether the open-claims count it is about to quote to an underwriter is current enough for the decision in front of it.

So freshness is declared on the contract itself, next to the SQL and the parameters:

  • Cadence: live, hourly, nightly, weekly or static. This is how current the underlying rows are expected to be.
  • SLA in minutes: the owner's commitment that rows are never older than this. It is a number a consumer can hold the owner to.
  • A description in plain words, for people reading the catalog and for the assistant deciding whether this context suits the question.
{
  "key": "claims.ops.open_by_line",
  "version": 3,
  "freshness": { "cadence": "hourly", "sla_minutes": 90,
                 "description": "Claims system extract lands hourly" },
  "cache_ttl_s": 300,
  "cache_stale_s": 600
}

That declaration appears in the catalog row for the context, in the REST response and in the MCP tool description. An agent sees the promise before it calls and the stamp after.

Three ways an answer is produced

Live at request time

A context with no cache entry runs at the moment it is asked. The caller's scope is wrapped around the template, values are bound as parameters, the statement runs read-only with a timeout and a row cap, and the rows come back with their typed columns. This is the right default for operational questions where minutes matter: open submissions, claims reported today, stock on hand.

From a time-to-live cache

Twenty people opening the same dashboard at nine o'clock should cost one warehouse query, not twenty. Each contract can set cache_ttl_s, how long an answer is kept, and cache_stale_s, how long after that an older answer may still be served while one refresh runs in the background. That second window is stale-while-revalidate: the caller gets an answer immediately and the next caller gets a fresh one.

Live, cached and stale answersThe cache key decides which path serves a request. All three paths return the same shape, stamped with <code>as_of</code> and the contract's freshness.One request, three ways to answer itAgent or appasks a contextwith parametersCache keyparams + scope+ masking + versionHIT: fresh entryreturned at once, Age header setSTALE: inside the stale windowold answer now, one refresh in backgroundMISS: live queryone warehouse call, shared by concurrent missesEvery answer carries as_of, its freshness cadence and SLA, whichever path served it
The cache key decides which path serves a request. All three paths return the same shape, stamped with as_of and the contract's freshness.

Concurrent misses for the same key share one call. This is single flight: if forty agents ask the same question in the same second after an entry expires, the warehouse sees one query and all forty get its answer.

From a snapshot

Some contexts should not be live at all. A book-of-business summary computed overnight, a month-end loss triangle, a peer benchmark rebuilt weekly: these read from tables a pipeline writes on a schedule, and their contract says nightly or weekly. Declaring it is what matters. An agent reading a nightly context at four in the afternoon knows it is reading last night's numbers, because the contract and the answer both say so.

What the cache is keyed on

A shared cache in front of governed data is only safe if two callers who would get different rows can never share an entry. The key for a cached answer is built from everything the answer depends on and nothing else:

Part of the keyWhy it is there
NamespaceThe product, the tenant and the source that tenant is bound to. Tenants never share entries.
Contract key and versionA new version is a new answer, even for identical parameters.
Resolved parameters, normalisedDefaults filled in and keys sorted, so {"days": 30} and {"days": "30"} are one question.
Caller scopeThe book (owners) and the organisation the caller is confined to.
MaskingWhether masked columns apply. A cleared caller and an uncleared one never share rows.
Row capThe limit asked for is part of the answer.
Data versionBumped after a load; every older entry becomes unreachable at once.

That last line is the only refresh trigger we describe, because it is the one that exists: when a load finishes, the loader calls bump on the namespace and the cache stops serving anything computed before it. There is no separate invalidation list to maintain and no entry that survives a reload by accident.

What is never cached

Caching the wrong thing is how stale context does real damage. The rules are deliberately narrow:

  • Only answers that came back are kept. A refusal, a bad parameter, a timeout or a failure is never cached, so a transient outage does not become a five-minute outage.
  • An empty answer is kept for a shorter time than a full one, because a table that is still loading reads as empty.
  • A contract can set cache_ttl_s to zero. It is then always live.
  • A cache backend that fails falls back to memory and is retried after a pause. A cache outage never fails a query.
The life of one cached answerFresh, then stale-while-revalidate, then gone. A load bumps the data version and retires every older entry in one step.The life of one cached answerFresh0 .. cache_ttl_sserved as HITStale windowttl .. ttl + cache_stale_sserved as STALE, refresh runsGonenext caller pays onelive query (MISS)bump(namespace) after a load makes every older entry unreachable at oncerefusals, bad parameters and timeouts are never cached; empty answers are kept briefly
Fresh, then stale-while-revalidate, then gone. A load bumps the data version and retires every older entry in one step.

The as_of stamp, everywhere

Every answer, whichever path produced it, carries the same envelope: the contract key and version, the typed columns with labels and units, the rows, whether they were truncated or masked, how long they took, the freshness declaration and as_of, the time the rows were read.

{
  "key": "claims.ops.open_by_line", "version": 3,
  "columns": [{"name": "line", "label": "Line of business", "type": "text"},
              {"name": "open_claims", "label": "Open claims", "unit": "count"}],
  "rows": [["Commercial Auto", 412], ["General Liability", 268]],
  "truncated": false, "masked": false, "duration_ms": 184,
  "as_of": "2026-11-15T09:02:11+00:00",
  "freshness": {"cadence": "hourly", "sla_minutes": 90}
}

Over REST the cache state is also in the headers: X-DataAPI-Cache is HIT, STALE or MISS, and a hit carries an Age in seconds. Over MCP the same stamp is in the tool result, so an agent can quote it: open commercial auto claims are 412 as of 09:02 UTC. A dashboard tile shows it under the number.

Teach the agent to say it. The most useful line in an agent's system prompt about context is often the simplest: when you quote a figure, quote its as_of. Because every answer carries one, the instruction always has something to point at.

Refreshing on demand

Sometimes a person knows the cache is behind: a correction just landed, a load was rerun. An administrator can ask for a refresh, which skips the cached answer and replaces it. Other callers cannot, by design; a refresh is a warehouse query on someone else's budget, and an agent in a loop should not be able to force one on every turn. The refresh is recorded in the call audit like any other call.

Choosing a freshness per context

The choice belongs to the owner of each context, and it is usually easy once it is asked explicitly:

Kind of contextTypical choice
Operational queues (open submissions, claims reported today)Live, or a cache of a minute or two
Executive KPIs viewed by many at onceHourly cadence, a few minutes of TTL, a stale window
Book-of-business 360, peer benchmarks, loss trianglesNightly or weekly snapshot tables, cached for hours
Reference data (lines, states, class codes)Static, public scope, cached long

What matters is that the choice is visible. An agent comparing a live queue with a nightly benchmark can tell they were read at different times, and say so. Read more about how the same context reaches each consumer in one context, many consumers, and about the real-time options on the real-time context page.

Where people stay in charge

  • The owner sets the promise. Cadence, SLA, TTL and stale window are declared by the person accountable for the context, and reviewed when the contract is published.
  • The loader decides when the old answers die. A bump after a load is an explicit step in the pipeline your team runs, not a guess by the cache.
  • Only administrators force a refresh. Agents and applications cannot turn a cache off for themselves.
  • Every answer is dated. People reading an agent's reply can see when the numbers were read, and challenge them.

See your own context layer, on your data

Bring one source and three questions your agents or apps need answered. We will stand up governed contexts over them in your environment and connect an agent to them in a working session.

We reply within one business day. Next comes a 45-minute executive briefing for your CIO or CDO, then, if it fits, a 12-week Innovation POD in your environment.