Continuous materialization
Materialized views and transformations keep serving relations current.
Serve user-facing analytics from relations that maintain themselves, and push each change to the client as it commits.
The problem
User-facing analytics has a budget a warehouse cannot meet: the dashboard has to load quickly, for many users at once, over data that changes constantly. Running the aggregation on every page load does not scale; running it on a cron and caching the result serves stale numbers.
The usual fix, a stream processor maintaining rollups into a serving store, adds a second system, a second schema and a freshness gap between the rollup and the source that users notice the moment they act and refresh.
You want a serving relation that is maintained from the source by change propagation rather than a timer, read as an ordinary table and followed live.
Architecture
A materialized view or a transformation keeps the serving relation current from every committed write. Parameterized materialized views are templates: CREATE MATERIALIZATION freezes one tenant’s arguments into a concrete, continuously maintained instance.
A materialized view template with typed parameters, or a keyed target table for a transformation.
One maintained instance per tenant, from CREATE MATERIALIZATION … OF …; a grouped transformation keeps the totals.
Committed changes reach the subscribers that read them, with no periodic full re-scan.
Dashboards read the instance by name; STREAM SELECT pushes each change to the client.
Examples
CREATE TRANSFORMATION balance_activity INTO balances ATTRIBUTE GROUP activity ASSELECT chain_id, recipient AS address, token, COUNT(*) AS transfer_count, MAX(transferred_at) AS last_transfer_at, MAX(_index) AS activity_indexFROM transfersGROUP BY chain_id, recipient, token;STREAM SELECT chain_id, token, SUM(amount) AS volume, COUNT(*) AS transfersFROM transfersGROUP BY chain_id, token;The examples use the same two tables on every page. See the SQL reference for full syntax.
Capabilities
Materialized views and transformations keep serving relations current.
Every committed write is published once and delivered to each subscriber.
One maintained instance per tenant, from a parameterized template and CREATE MATERIALIZATION.
Materialized views reseed from a source snapshot after a restart.
Counts, sums, minimums, maximums and averages stay current, maintained by transformations.
UI updates arrive without polling, with STREAM SELECT.
Learn more
Materialize a serving relation and stream it to the client.