This document describes how to create a Managed Service for Apache Spark multi-zone
cluster. In a multi-zone cluster, Managed Service for Apache Spark provisions and
distributes the Compute Engine VM instances of the cluster across
multiple zones in a single region, instead of placing all cluster nodes in one
zone.

Use a multi-zone cluster when you need to create or scale a large cluster and
the capacity of a single zone might not be enough to meet your request.

## How multi-zone clusters work

When you create a multi-zone cluster, Managed Service for Apache Spark provisions the
cluster nodes as follows:

- Master nodes: Managed Service for Apache Spark places the master instance group in a single zone in the cluster region by using [Auto Zone placement](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/auto-zone.md.txt).
- Worker nodes: Managed Service for Apache Spark configures the primary and [secondary worker](https://docs.cloud.google.com/managed-spark/docs/concepts/compute/secondary-vms.md.txt) groups as [regional managed instance groups (MIGs)](https://docs.cloud.google.com/compute/docs/instance-groups/regional-mig-distribution-shape.md.txt). These groups provision and distribute worker VMs across any eligible zone in the region that has available capacity.

Because Managed Service for Apache Spark distributes worker VM requests across
multiple zones, capacity constraints in a single zone are less likely to block
your request. This helps prevent `ZONE_RESOURCE_POOL_EXHAUSTED` errors when you
create or scale large clusters, clusters with Spot VM or preemptible secondary
workers, or clusters that use high-demand machine types.

## Requirements and limitations

To create a multi-zone cluster, you must use one of the following
[image versions](https://docs.cloud.google.com/managed-spark/docs/concepts/versioning/overview.md.txt) or a later
version in the same image version track:

| Image version track | Minimum supported image version |
|---|---|
| 2.2.x | `2.2.88` |
| 2.3.x | `2.3.37` |
| 3.0.x | `3.0.3` |

Multi-zone clusters have the following limitations:

- You can't specify both a single zone and a multi-zone configuration in the same cluster creation request.
- You can't create a multi-zone cluster with more than 1,000 primary workers in the initial cluster creation request. If your workload requires more than 1,000 primary workers, create the cluster with 1,000 or fewer primary workers, and then [scale the cluster](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/scaling-clusters.md.txt) after it is created.

## Network data transfer costs

> [!CAUTION]
> **Caution:** A multi-zone cluster can increase your network data transfer costs because of cross-zone data transfer between cluster nodes.

In a single-zone cluster, all VMs are in the same zone, and network traffic
that uses internal IP addresses between VMs in the same zone is offered at no
charge. In a multi-zone cluster, master and worker VMs can be in different zones in the
same region. Network traffic between VMs in different zones in the same region
incurs inter-zone data transfer charges.

For pricing details, see
[VM-VM data transfer pricing within Google Cloud](https://docs.cloud.google.com/vpc/network-pricing#vm-vm-data-transfer-pricing-within-google-cloud).

## Create a multi-zone cluster

You can create a multi-zone cluster by using the Google Cloud CLI or the
Dataproc API.

### gcloud

To create a multi-zone cluster, run the
[`gcloud dataproc clusters create`](https://docs.cloud.google.com/sdk/gcloud/reference/dataproc/clusters/create.md.txt)
command with the `--multizone` flag. Don't specify the `--zone` flag.

```bash
gcloud dataproc clusters create CLUSTER_NAME \
    --region=REGION \
    --multizone \
    --image-version=IMAGE_VERSION \
    --master-machine-type=MASTER_MACHINE_TYPE \
    --worker-machine-type=WORKER_MACHINE_TYPE \
    --num-workers=NUM_WORKERS
```

Replace the following:

- <var translate="no">CLUSTER_NAME</var>: the name of the cluster.
- <var translate="no">REGION</var>: an [available Compute Engine region](https://docs.cloud.google.com/compute/docs/regions-zones.md.txt#available) for the cluster, such as `us-central1`.
- <var translate="no">IMAGE_VERSION</var>: an image version that supports multi-zone clusters, such as `2.3.37-debian12`. For more information, see [Requirements and limitations](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/multi-zone.md.txt#requirements-and-limitations).
- <var translate="no">MASTER_MACHINE_TYPE</var>: the Compute Engine machine type of the master node, such as `n2-standard-4`.
- <var translate="no">WORKER_MACHINE_TYPE</var>: the Compute Engine machine type of the primary worker nodes, such as `n2-standard-4`.
- <var translate="no">NUM_WORKERS</var>: the number of primary workers in the cluster. This value can't be greater than `1000`.

### REST

To create a multi-zone cluster, send a
[`clusters.create`](https://docs.cloud.google.com/managed-spark/docs/reference/rest/v1/projects.regions.clusters/create.md.txt)
request. In the
[`gceClusterConfig`](https://docs.cloud.google.com/managed-spark/docs/reference/rest/v1/ClusterConfig.md.txt#GceClusterConfig)
object of the request, leave the `zoneUri` field empty, and set the
[`multiZoneConfig.targetShape`](https://docs.cloud.google.com/managed-spark/docs/reference/rest/v1/ClusterConfig.md.txt#multizoneconfig) field to `ANY`.

HTTP method and URL:

    POST https://dataproc.googleapis.com/v1/projects/PROJECT_ID/regions/REGION/clusters

Request JSON body:

```json
{
  "projectId": "PROJECT_ID",
  "clusterName": "CLUSTER_NAME",
  "config": {
    "gceClusterConfig": {
      "multiZoneConfig": {
        "targetShape": "ANY"
      }
    },
    "softwareConfig": {
      "imageVersion": "IMAGE_VERSION"
    },
    "masterConfig": {
      "numInstances": 1,
      "machineTypeUri": "MASTER_MACHINE_TYPE"
    },
    "workerConfig": {
      "numInstances": NUM_WORKERS,
      "machineTypeUri": "WORKER_MACHINE_TYPE"
    }
  }
}
```

Replace the following:

- <var translate="no">PROJECT_ID</var>: your Google Cloud project ID.
- <var translate="no">REGION</var>: an [available Compute Engine region](https://docs.cloud.google.com/compute/docs/regions-zones.md.txt#available) for the cluster, such as `us-central1`.
- <var translate="no">CLUSTER_NAME</var>: the name of the cluster.
- <var translate="no">IMAGE_VERSION</var>: an image version that supports multi-zone clusters, such as `2.3.37-debian12`. For more information, see [Requirements and limitations](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/multi-zone.md.txt#requirements-and-limitations).
- <var translate="no">MASTER_MACHINE_TYPE</var>: the Compute Engine machine type of the master node, such as `n2-standard-4`.
- <var translate="no">NUM_WORKERS</var>: the number of primary workers in the cluster. This value can't be greater than `1000`.
- <var translate="no">WORKER_MACHINE_TYPE</var>: the Compute Engine machine type of the primary worker nodes, such as `n2-standard-4`.

## What's next

- Learn more about [Auto Zone placement](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/auto-zone.md.txt).
- Learn how to [scale Managed Service for Apache Spark clusters](https://docs.cloud.google.com/managed-spark/docs/concepts/configuring-clusters/scaling-clusters.md.txt).
- Learn about [regional MIG target distribution shapes](https://docs.cloud.google.com/compute/docs/instance-groups/regional-mig-distribution-shape.md.txt).