Clusters
View as MarkdownOverview
Clusters are pools of compute resources (CPU, memory, and scratch disk space) for running your workloads.
Clusters and workloads
The following operations require a cluster in Materialize:
- Maintaining sources, tables (or subsources) created from a source, and sinks.
- Maintaining indexes and materialized views.
- Executing
SELECTandSUBSCRIBEstatements.
Each session has an active cluster, which you can change with SET CLUSTER.
SET CLUSTER = 'my_transform_cluster';
SELECT and SUBSCRIBE statements run in the session’s active cluster.
Objects that require compute (e.g., indexes, materialized views, sources) are associated with a cluster when they are created, either:
-
the session’s active cluster by default, or
-
the cluster specified by the
IN CLUSTER <cluster>clause in theCREATEstatement.
Cross-cluster objects
Tables, views, and materialized views are accessible across clusters. That is, you can query or reference them from any cluster.
Cluster-local objects
Indexes are accessible only from their own cluster. Indexed results reside in the memory of the cluster where the index is created, and a cluster’s memory cannot be accessed from another cluster.
For more on indexes and clusters, see Indexes.
Resource isolation
Clusters provide resource isolation. Each cluster provisions dedicated compute resources and can fail independently from other clusters. All workloads on a given cluster compete for access to that cluster’s compute resources.
Workloads on different clusters are strictly isolated from one another. That is, a given workload has access only to the CPU, memory, and scratch disk of the cluster it runs on.
Resource isolation lets you place workloads on separate clusters to prevent them from competing for compute resources: for example, sources in one cluster, materialized views in a second, and indexes that serve queries in a third, as in the recommended three-tier architecture.
Cluster replicas
The replication factor of a cluster determines the number of replicas provisioned for the cluster.
Each replica of a cluster provisions a new pool of compute resources to perform exactly the same work on exactly the same data. That is, replicas are redundant copies of the cluster’s workload, not shards: each replica processes the full workload.
Materialize automatically assigns names to replicas (e.g., r1, r2). You can
view information about individual replicas in the Materialize console and the
system catalog.
Fault tolerance
Provisioning more than one replica for a cluster improves fault tolerance. Clusters with multiple replicas can tolerate failures of the underlying hardware that cause a replica to become unreachable. As long as one replica of the cluster remains available, the cluster can continue to maintain dataflows and serve queries.
-
For Cloud, each replica incurs cost, calculated as
cluster size * replication factorper second. See Usage & billing (Cloud) for more details. -
Increasing the replication factor does not increase the cluster’s work capacity. Replicas are exact copies of one another: each replica must do exactly the same work as all the other replicas of the cluster (i.e., maintain the same dataflows and process the same queries). To increase the capacity of a cluster, you must increase its size.
Availability guarantees
When provisioning replicas,
-
For clusters sized up to and including
3200cc, Materialize guarantees that all provisioned replicas in a cluster are distributed across the underlying cloud provider’s availability zones. -
For clusters sized above
3200cc, even distribution of replicas across availability zones cannot be guaranteed.
See also Hydration considerations.
Cluster sizing
When creating a cluster, you must choose its
size (e.g., 25cc, 50cc, 100cc),
which determines its resource allocation (CPU, memory, and scratch disk space)
and cost (for Cloud). The appropriate size
for a cluster depends on the resource requirements of your workload. Larger
clusters have more compute resources available and can therefore process data
faster and handle larger data volumes.
To gauge the performance and utilization of your clusters, use the Environment Overview page in the Materialize Console.
As your workload changes, you can resize a cluster. A resize triggers hydration. During hydration, the cluster keeps serving since Materialize provisions new replicas at the target size and hydrates them before retiring the old ones.
Hydration considerations
Hydration 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.
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.
Hydration is per cluster replica: when a hydration trigger occurs, the objects on the affected replicas hydrate. When a replica restarts, every object on it re-hydrates. A resize or an added replica hydrates only the new replicas.
For more information, including hydration strategies and the memory usage of hydrating objects, see Hydration.
Best practices
The following provides some general guidelines for clusters. See also Operational guidelines.
Three-tier architecture in production
In production, use a three-tier architecture, if feasible.
A three-tier architecture consists of:
| Tier | Description |
|---|---|
| Source cluster(s) |
A dedicated cluster(s) for sources. In addition, for upsert sources:
|
| Compute/Transform cluster(s) |
A dedicated cluster(s) for compute/transformation:
|
| Serving cluster(s) | A dedicated cluster(s) for serving queries, including indexes on the materialized views. Indexes are local to the cluster in which they are created. |
Benefits of a three-tier architecture include:
-
Support for blue/green deployments
-
Independent scaling of each tier.
See also Operational guidelines.
Alternatives
Alternatively, if a three-tier architecture is not feasible or unnecessary due to low volume or a non-production setup, a two cluster or a single cluster architecture may suffice.
See Appendix: Alternative cluster architectures for details.
Use production clusters for production workloads only
Use production cluster(s) for production workloads only. That is, avoid using production cluster(s) to run development workloads or non-production tasks.