Hydration
View as MarkdownHydration is the reconstruction of an object’s in-memory state by reading from Materialize’s storage layer and existing indexes; hydration does not read from the upstream system.
When hydration occurs
Depending on the object, hydration (or rehydration) occurs after:
- An object is created, triggering its hydration.
- This includes dropping and recreating objects to force re-planning. For example, after dropping an index, you can drop and recreate its dependent objects to force them to re-plan. The recreated objects then hydrate like any newly created object.
- A cluster replica restarts, such as during Materialize Cloud’s routine maintenance or after an out-of-memory event. Hydration can be memory-intensive and can itself trigger the out-of-memory event. The replica then restarts and rehydrates again, potentially creating a restart-and-rehydrate loop if the replica is undersized.
- A cluster resize. A cluster resize provisions new replicas at the target size and hydrates them before retiring the old ones. The cluster keeps serving throughout.
- Adding a replica to a cluster, which hydrates the new replica only. Existing replicas are unaffected and keep serving.
For when hydration occurs for each object type, see Objects and hydration.
Objects and hydration
Hydration is per cluster replica. When a trigger above occurs, the objects on the affected replicas hydrate as described below. When a replica restarts, every object on it re-hydrates. A resize or an added replica hydrates only the new replicas.
| Object | Hydration behavior |
|---|---|
| Materialized views |
|
| Indexes |
|
| Kafka upsert sources and associated read-only tables/subsources |
|
| Append-only Kafka sources and CDC database sources (PostgreSQL, MySQL, SQL Server), and their read-only tables/subsources |
|
| Webhook sources |
Not applicable. A webhook source is not maintained by a dataflow. It receives data pushed over HTTP and writes the data directly to storage, so it does not hydrate. |
| Sinks |
|
| Subscriptions |
|
Hydration strategies
Hydration primarily impacts memory usage, and its speed scales with cluster size. Some hydration-related strategies you may want to consider:
-
Use a dedicated cluster for sources.
-
In addition, use a dedicated cluster for upsert sources; i.e., do not co-locate with append-only Kafka sources or CDC database sources.
-
Keeping append-only Kafka sources and CDC database sources (PostgreSQL, MySQL, and SQL Server sources) on a separate cluster isolates ingestion from possible OOM loops caused by memory-heavy objects such as Kafka upsert sources.
-
Note: PostgreSQL, MySQL, and SQL Server sources run on a single replica, the oldest, and remain there until that replica is removed. As such, the use of a burst replica (through
AUTO SCALING STRATEGY (ON HYDRATION)) has no impact on these single-replica sources.
-
-
Add an
AUTO SCALING STRATEGY (ON HYDRATION)to your cluster with memory-heavy objects. With this strategy, Materialize automatically provisions an extra, larger replica (a burst replica) while the cluster has unhydrated objects, then removes it once a steady-size replica catches up. You pay for the burst replica while it is provisioned, but not at steady state.- If a steady-size replica runs out of memory during hydration, resize the cluster. During the resize, the cluster continues to serve from the burst replica.
-
Distribute materialized views and indexes across multiple clusters. Each cluster’s replicas hydrate their objects independently, which distributes the memory required for hydration, lets objects on different clusters hydrate in parallel, and limits how much must re-hydrate when any one replica restarts.
-
When changing a materialized view or index, or forcing dependents to re-plan (for example, after dropping an index and recreating the dependents), build the new version to the side to avoid downtime:
-
A blue/green deployment hydrates the new version alongside the old and cuts over when hydrated, with no serving gap. Note that blue/green requires sources and sinks to live on dedicated clusters that are excluded from the swap. For more information, see blue/green deployment.
-
For a single materialized view, creating and hydrating a replacement materialized view (public preview) and replacing the existing view in place may be simpler, but briefly reduces freshness. The replacement materialized view can be either on the same or different cluster.
-
In addition, consider the following strategies. These strategies trade off peak hydration memory against added operational complexity, extra objects, and potentially longer total hydration time. You can use them when peak hydration memory is the bottleneck rather than as a default modeling pattern.
-
If multiple objects in the same cluster consume the same view, add an index to that view before creating the consumers. Consumers in that cluster can reuse the indexed arrangement instead of each building equivalent in-memory state, which can reduce both memory usage during hydration and steady-state memory. Note:
- Index reuse is limited to the cluster the index is on, and the index must exist before its consumers are created for the optimizer to reuse it.
- For a view with only one consumer, an index generally adds memory instead of saving it.
-
For a very large materialized view, consider splitting it into several smaller materialized views, for example by a partition key such as customer, region, or date range. Smaller materialized views can hydrate as separate dataflows, which can bound peak memory compared with hydrating one very large materialized view.
- This helps most when a cluster runs only a few large materialized views, where a single view’s hydration spike can dictate the cluster size. A cluster with many materialized views already hydrates them as separate dataflows and gets this benefit naturally.
- A re-plan or replacement of one split view affects only that portion of the data. A replica restart still re-hydrates all views on the replica, though in smaller units.
- If the split views share expensive computation, put that computation in a common indexed view first, creating the index before creating the split views. Otherwise, each split view may rebuild its own copy of the shared work, increasing total memory.
- Queries must target or combine the split views.