# Set up a cluster of Transformers

You can define two or more Transformers as a cluster. Here’s how to do this.

**📌 NOTE**\
For more about clustering, see [Transformer Clustering features and concepts](transformer-clustering.md).

## Clustering Transformers without the Caplin Deployment Framework

Here’s an example of how to configure a Transformer cluster when you’re not using the Deployment Framework. Here we’ve assumed there are just two Transformers in the cluster, but the same approach applies when you’re clustering more.

**Config for the first Transformer in the cluster:**

**transformer.conf**

```
add-module cluster
```

**cluster.conf**

```
cluster-index 0
heartbeat-time        5
heartbeat-slack-time  1.5

add-cluster-node
   cluster-addr <First-Transformers-network-interface-address>
   cluster-port <First-Transformers-network-port-number>
end-cluster-node

add-cluster-node
   cluster-addr <Second-Transformers-network-interface-address>
   cluster-port <Second-Transformers-network-port-number>
end-cluster-node
```

**Config for the second Transformer in the cluster:**

**transformer.conf**

```
add-module cluster
```

**cluster.conf**

```
cluster-index 1
heartbeat-time        5
heartbeat-slack-time  1.5

add-cluster-node
   cluster-addr <First-Transformers-network-interface-address>
   cluster-port <First-Transformers-network-port-number>
end-cluster-node

add-cluster-node
   cluster-addr <Second-Transformers-network-interface-address>
   cluster-port <Second-Transformers-network-port-number>
end-cluster-node
```

Here’s an explanation of the configuration items that we’ve used:

* [`cluster-index`](transformer-clustering-configuration.md#cluster-index): Uniquely identifies this Transformer in the cluster. Make sure each Transformer in the cluster has a different cluster-index in its configuration file; in this example, the first Transformer has cluster-index 0 and the second has cluster-index 1.

  Index numbers must start at `0` and correspond to the order of the `add-cluster-node` items in the configuration file.
* [`heartbeat-time`](transformer-clustering-configuration.md#heartbeat-time) is the time in seconds between each cluster heartbeat. The Transformers forming a cluster exchange heartbeat messages at regular intervals, allowing each of them to check that all the others are still present, and take appropriate action if one doesn’t respond.
* [`heartbeat-slack-time`](transformer-clustering-configuration.md#heartbeat-slack-time): When this Transformer doesn’t receive an expected cluster heartbeat from another Transformer in the cluster, it waits `heartbeat-slack-time` seconds before disconnecting from the cluster and trying to reconnect to it.
* [`add-cluster-node`](transformer-clustering-configuration.md#add-cluster-node): Each `add-cluster-node` item defines a Transformer in the cluster by its network interface address and port number. You define all the Transformers in the cluster through a set of `add-cluster-node` items. The set must be in ascending order of the Transformers' `cluster-index` values. You put the `add-cluster-node` items in the configuration of every Transformer in the cluster, so each Transformer identifies every node in the cluster, including itself. You can see that in this example, each of the two Transformers' configurations contains the same set of two `add-cluster-node` items.

## Setting up a secure cluster

Since Transformer version 8.0.4, communication between Transformer cluster nodes can now be protected with TLS. The Transformer includes example key and certificate files for testing and development.

**❗ IMPORTANT**\
Only use the example key and certificate files for testing and development. When you deploy to production, create your own keys and certificates.

**Configuration for the first Transformer in the cluster:**

**transformer.conf**

```
add-module cluster
```

**cluster.conf**

```
cluster-index 0
heartbeat-time        5
heartbeat-slack-time  1.5

cluster-global-ssl-enable
cluster-ssl-present-certificate %r/etc/certs/cluster.pem
cluster-ssl-accept-certificate  %r/etc/certs/cluster.pem
cluster-ssl-privatekey          %r/etc/certs/cluster.key
cluster-ssl-passwordfile        %r/etc/certs/cluster.pwd

add-cluster-node
   cluster-addr <First-Transformers-network-interface-address>
   cluster-port <First-Transformers-network-port-number>
end-cluster-node

add-cluster-node
   cluster-addr <Second-Transformers-network-interface-address>
   cluster-port <Second-Transformers-network-port-number>
end-cluster-node
```

**Configuration for the second Transformer in the cluster:**

**transformer.conf**

```
add-module cluster
```

**cluster.conf**

```
cluster-index 1
heartbeat-time        5
heartbeat-slack-time  1.5

cluster-global-ssl-enable
cluster-ssl-present-certificate %r/etc/certs/cluster.pem
cluster-ssl-accept-certificate  %r/etc/certs/cluster.pem
cluster-ssl-privatekey          %r/etc/certs/cluster.key
cluster-ssl-passwordfile        %r/etc/certs/cluster.pwd

add-cluster-node
   cluster-addr <First-Transformers-network-interface-address>
   cluster-port <First-Transformers-network-port-number>
end-cluster-node

add-cluster-node
   cluster-addr <Second-Transformers-network-interface-address>
   cluster-port <Second-Transformers-network-port-number>
end-cluster-node
```

The additional SSL configuration items are described in the [Clustering configuration](transformer-clustering-configuration.md) reference page.

## Clustering Transformers in the Caplin Deployment Framework

The [Caplin Deployment Framework](../deployment-framework/index.md), allows you to easily define a two-Transformer cluster for failover purposes. To enable failover, see How can I... [Set up server failover capability](../deployment-framework/cdf-set-up-server-failover-capability.md) in the Deployment Framework pages. You set up some configuration macro definitions in the `<Framework-root>/global-config/environment.conf` file on the primary and secondary server machines.

* To change the [`heartbeat-time`](transformer-clustering-configuration.md#heartbeat-time), add the macro definition `TRANSFORMER_CLUSTER_HEARTBEAT_TIME` to `<Framework-root>/global-config/environment.conf`

  ```
  define TRANSFORMER_CLUSTER_HEARTBEAT_TIME <new value>
  ```
* To change the [`heartbeat-slack-time`](transformer-clustering-configuration.md#heartbeat-slack-time) from its default, define a value in `<Framework-root>/global_config/overrides/servers/Transformer/etc/cluster.conf`

  ```
  heartbeat-slack-time <new-value>
  ```
* To change the [`cluster-addr`](transformer-clustering-configuration.md#cluster-addr) settings in the [`add-cluster-node`](transformer-clustering-configuration.md#add-cluster-node) configuration entries:

  The configuration macros `TRANSFORMER${THIS_LEG}_HOST` and `TRANSFORMER${OTHER_LEG}_HOST` specify the `cluster-addr` values. (These macros are defined in `<Framework-root>/global_config/hosts-defns.conf`)

  You normally use the [`./dfw hosts`](../deployment-framework/cdf-the-deployment-framework-command-utility-dfw.md#hosts) command to set up the hostnames in the macros. See [Configuring server hostnames](../deployment-framework/cdf-set-up-server-failover-capability.md#configuring-server-hostnames) in How can I... [Set up server failover capability](../deployment-framework/cdf-set-up-server-failover-capability.md) and [Change server hostnames](../deployment-framework/cdf-change-server-specific-configuration.md#change-server-hostnames) in How can I ... [Change server-specific configuration](../deployment-framework/cdf-change-server-specific-configuration.md).

  Also see Deployment Framework [Configuration macros and items](../deployment-framework/cdf-configuration-macros-and-items.md).

  If you want to set the `cluster-addr` values directly, edit them in `<Framework-root>/global_config/overrides/servers/Transformer/etc/cluster.conf`
* To change the [`cluster-port`](transformer-clustering-configuration.md#cluster-port) settings in the [`add-cluster-node`](transformer-clustering-configuration.md#add-cluster-node) configuration entries, put new values for the configuration macros `TRANSFORMER${THIS_LEG}_CLUSTER_PORT` and `TRANSFORMER${OTHER_LEG}_CLUSTER_PORT` in the `<Framework-root>/global_config/overrides/servers/Transformer/etc/cluster.conf` file.

  For example:

  ```
  define TRANSFORMER${THIS_LEG}_CLUSTER_PORT   ${THIS_LEG}6003
  define TRANSFORMER${OTHER_LEG}_CLUSTER_PORT  ${OTHER_LEG}6003
  ```

  where the value `6003` is the new base port number, replacing the default value `6001`.

**📌 NOTE**\
If you want to set up a cluster of more than two Transformers within the Deployment Framework, **please contact Caplin Support** for advice on how to do this.

---

**See also:**

* Transformer Features and Concepts: [Clustering](transformer-clustering.md)
* Reference: [Clustering configuration](transformer-clustering-configuration.md)
* Reference: [DataSource peers configuration](../datasource/datasource-datasource-peers-configuration-part-1.md)
* Reference: [Data services configuration](../datasource/datasource-data-services-configuration.md)
* Reference: [Deployment Framework configuration macros and items](../deployment-framework/cdf-configuration-macros-and-items.md)
