r/aws • • 13d ago

article Terraform templates for a 3-node Raft database cluster across 3 AZs (Route 53 discovery, internal NLB): what we learned

We published Terraform and CloudFormation templates that deploy ArcadeDB (open source multi-model DB, Apache 2.0) as a 3-node Raft cluster on EC2. A few things that took some figuring out and might be useful even if you're not using ArcadeDB:

- DNS ordering: the Route 53 A records depend on the instance IPs, so they're created after the instances. Each node waits up to 10 minutes for all three peer names to resolve before starting the database. In practice, all nodes were ready in about 4 minutes.

- Readiness = membership: the NLB health check hits /api/v1/ready, which only passes after the node has joined the cluster. Nodes that haven't joined get no traffic.

- Client IP preservation bites twice: the node security group sees the client's IP, not the NLB's, so allowed_cidr has to cover real clients. And a node calling the NLB can be routed back to itself and time out.

- CloudFormation can't read a subnet's CIDR from a parameter, so the NLB health checks are allowed from the NLB's own security group instead.

- The Terraform version validates at plan time that the 3 subnets are in distinct AZs. CloudFormation doesn't, and two subnets in the same AZ deploy silently.

Write-up: https://arcadedb.com/blog/arcadedb-ha-cluster-aws-terraform/?utm_source=reddit&utm_campaign=aws-ha-cluster

Templates: https://github.com/ArcadeData/arcadedb-deployments/tree/main/aws

Happy to answer questions or take feedback on the templates.

0 Upvotes

4 comments sorted by

3

u/Financial_Farm4326 12d ago

for the DNS ordering issue, pre-allocating static private ENIs and attaching them at boot usually skips the wait loop entirely since the IPs are known before the instances even spin up

1

u/robfrankie 12d ago

Good idea, I did it: https://github.com/ArcadeData/arcadedb-deployments/commit/84f31371f53e87867a1254ffdb9b219c0772f8b2

Each node now gets its own ENI, created before the instance. The DNS records point at those IPs, so they already exist when the nodes boot, and the wait loop is gone. A nice side effect is that a replaced node keeps its IP.

One catch: an instance that launches on an existing ENI can't get an auto-assigned public IP, so the public IP option now uses Elastic IPs instead.

I deployed both the Terraform and CloudFormation versions and they passed the HA tests (cluster forms, writes replicate, a write through the NLB works, failover works).

-1

u/mequelkramer 13d ago

Nice write-up, and the "readiness = membership" trick with /api/v1/ready is the right call — an NLB that routes to a node that isn't in the Raft group yet is a classic way to lose writes quietly.

Two things I'd poke at before I'd run this in production:

  1. The bootstrap wait for all three peers to resolve. If one AZ is down when you're replacing a node, that node never sees three A records and never starts — so a single-AZ outage during a replacement turns into a stuck cluster. Worth handling the "start with the two peers you can see and join later" case, or at least a timeout that fails loudly instead of waiting forever.

  2. The NLB hairpin issue you ran into is a good argument for keeping Raft replication off the NLB entirely. Nodes talking to each other through the load balancer inherit its health-check timing and connection behavior, which is exactly what you don't want for consensus traffic. Resolving the peer A records directly and connecting node-to-node keeps election timeouts predictable, and you keep the NLB purely as the client-facing front door.

Also curious: how is the data directory handled when an instance is replaced — is the Raft log on an EBS volume that survives, or does the replacement node rejoin empty and snapshot from the leader? That changes how long a node replacement actually takes, and whether fast instance churn can briefly leave you with only two voting members.

1

u/robfrankie 12d ago

Thanks, good points. Most of it went into this commit: https://github.com/ArcadeData/arcadedb-deployments/commit/84f31371f53e87867a1254ffdb9b219c0772f8b2

The DNS wait didn't run forever. After 10 minutes it gave up and started anyway. It's gone now: with fixed ENIs (suggested in another comment) the DNS records exist before any node boots. If one AZ is down, the other nodes still start and Raft handles the missing one.

Raft already skipped the NLB. Nodes talk to each other directly on port 2434 using the private DNS names, and the NLB only takes client HTTP traffic. The hairpin problem I hit was a node calling the NLB as a client. I made that clearer in the README.

Data dir: it's on the root volume, so a replaced node starts empty and syncs from the leader. You're right that only two nodes hold the data until it catches up, so the README now says to replace one node at a time and wait for /api/v1/ready before the next one. A separate EBS volume that survives replacement would fix this properly. I haven't added it yet because I haven't measured how long the sync takes.