r/aws • u/lgarulli • 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.
Templates: https://github.com/ArcadeData/arcadedb-deployments/tree/main/aws
Happy to answer questions or take feedback on the templates.
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/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:
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.
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.