# How to set up a LavinMQ cluster on CloudAMQP

By Lovisa Johansson. Last updated 21 October 2026.

LavinMQ clustering improves message broker availability by replicating data across multiple nodes. If the leader node fails, a synchronized follower can take over, allowing applications to recover with minimal manual intervention.

With CloudAMQP, you can create and manage a LavinMQ cluster without manually configuring servers, replication, or etcd.

In this guide, you’ll learn how LavinMQ clustering works, how to create a three-node cluster on CloudAMQP, and how to verify that your cluster is running correctly.

## How does LavinMQ clustering work?

LavinMQ uses a leader-follower architecture. One node acts as the leader, processing client operations and replicating data to follower nodes.

A LavinMQ cluster has three main components:

- **Leader:** Handles client operations, including publishing and consuming messages.
- **Followers:** Maintain synchronized copies of the leader’s data and can take over if the leader fails.
- **etcd:** Coordinates leader election and tracks which replicas are synchronized.

When a producer publishes a message, the leader processes it and replicates the data to its followers. If the leader becomes unavailable, etcd coordinates the election of a new leader from eligible synchronized replicas.

Clustering is primarily designed for **high availability and fault tolerance**, not for distributing message-processing workloads across multiple leaders.

## Choosing the right LavinMQ cluster size

CloudAMQP offers different LavinMQ cluster configurations depending on your availability requirements.

| Configuration | Description | Best suited for |
| --- | --- | --- |
| 1 node | No replication or automatic node failover | Development, testing, and workloads that tolerate interruptions |
| 3 nodes | One leader and two followers | Production applications requiring high availability |
| 5 nodes | One leader and four followers | Workloads requiring additional redundancy |

A single-node cluster avoids replication overhead but has no other node to take over if it fails.

Three-node and five-node clusters provide replication and automatic failover. However, additional nodes also introduce replication overhead and infrastructure costs.

For most developers exploring high availability, a **three-node cluster is a practical starting point**.

## How to create a LavinMQ cluster on CloudAMQP

CloudAMQP manages the underlying clustering infrastructure, so you can focus on configuring and using your message broker.

The following steps use a three-node cluster as an example.

### Step 1: Create a LavinMQ instance

1. Sign in to the [CloudAMQP Console](https://customer.cloudamqp.com/).
2. Click **Create New Instance**.
3. Enter an instance name and select a LavinMQ plan. Optionally, add tags to organize your instances.
4. Click **Select Region** to continue.

### Step 2: Select a region and data center

1. Choose your preferred **cloud provider and region**.
2. Select the **data center** where your LavinMQ cluster will be hosted.
3. Click **Configure** to continue.

For lower network latency, choose a region close to your applications.

### Step 3: Configure your LavinMQ cluster

1. Under **Nodes**, select the number of nodes based on your availability requirements and budget.
2. Configure Dedicated VPC and Automatic Updates according to your needs, or keep the default settings.

**Optional settings**

1. Specify preferred Availability zones for your nodes.
2. Under Copy settings, you can copy configurations from an existing instance.
3. Under Admin, you can customize advanced settings such as the hostname and DNS zone.
4. Click **Review** to continue.

You can leave the optional settings at their defaults if you don’t need additional customization.

### Step 4: Create your cluster

Review your configuration and click **Create Instance**.

CloudAMQP provisions the LavinMQ nodes and configures the underlying clustering infrastructure, including etcd coordination.

Once provisioning is complete, your cluster is ready to use.

## Verify your LavinMQ cluster

After creating the cluster, open your instance in the CloudAMQP Console.

Navigate to the **Cluster** section to inspect its nodes and status. You should see all the nodes you created.

## Connect your application

Once your LavinMQ cluster is running, you can connect your application using the AMQP URL provided in the CloudAMQP Console.

![CloudAMQP Console showing the AMQP URL for a LavinMQ cluster](/img/blog/lavinmq-cluster-setup-at-cloudamqp/cloudamqp-amqp-url.png)

For example, you can use Python with the Pika library to publish a message.

```py
import os
import pika

url = os.environ["CLOUDAMQP_URL"]

connection = pika.BlockingConnection(
    pika.URLParameters(url)
)

channel = connection.channel()

channel.queue_declare(
    queue="cluster-demo",
    durable=True
)

channel.basic_publish(
    exchange="",
    routing_key="cluster-demo",
    body="Hello from LavinMQ!",
    properties=pika.BasicProperties(
        delivery_mode=2
    )
)

print("Message published!")

connection.close()
```

Set the `CLOUDAMQP_URL` environment variable to your instance’s AMQP URL and run it.

The example connects to your LavinMQ cluster, declares a durable queue named `cluster-demo` and publishes a persistent message.

You can verify that the message was published by opening the LavinMQ management interface and checking the queue.

## What happens if the leader fails?

Suppose your three-node cluster has:

- Node 1: Leader
- Node 2: Follower
- Node 3: Follower

If Node 1 becomes unavailable, etcd coordinates a new leader election. An eligible, synchronized follower can become the new leader.

Applications can then reconnect and continue publishing and consuming messages.

This process is called **automatic failover**.

Failover improves availability, but it does not guarantee zero downtime. Applications may experience a brief interruption during leader election and reconnection.

For reliable message processing, use publisher confirms, consumer acknowledgments, persistent messages, and appropriate reconnection handling.

## Scaling a LavinMQ cluster on CloudAMQP

As your application’s requirements change, CloudAMQP lets you adjust your cluster size and resources or enable automatic scaling.

### Change your cluster size and resources

To modify your cluster configuration:

1. Open your LavinMQ instance in the CloudAMQP Console.
2. On the **Overview** page, locate **Active Plan** in the top-right corner.
3. Choose one of the available options:
   - **Upgrade plan:** Change your plan or the number of cluster nodes.
   - **Add Extra Disk:** Increase your instance’s disk capacity.
4. Review and confirm your changes.

### Configure autoscaling

CloudAMQP also supports automatic resource scaling based on usage thresholds:

- **Disk autoscaling:** Increases disk capacity when free space falls below a configured threshold.
- **Plan autoscaling:** Upgrades to a larger plan when CPU, memory, or disk usage exceeds configured thresholds for a specified duration.

To configure autoscaling:

1. Open your LavinMQ instance in the CloudAMQP Console.
2. In the left sidebar, under **Automation**, click **Autoscaling**.
3. Enable disk or plan autoscaling and configure your preferred thresholds.
4. Click **Save changes**.

**Note:** Autoscaling increases resources but does not automatically add cluster nodes. Disk and plan autoscaling are scale-up only, and upgrades can increase your monthly costs.

## Conclusion

LavinMQ clustering provides high availability through data replication and automatic leader failover.

With CloudAMQP, creating a managed LavinMQ cluster is straightforward. You choose a suitable plan, configure the number of nodes, and let CloudAMQP manage the underlying infrastructure.

**Ready to get started?** [Create a LavinMQ cluster on CloudAMQP](https://customer.cloudamqp.com/) or explore the [LavinMQ clustering documentation](https://lavinmq.com/documentation/clustering) to learn more.
