My team was discussing the pros and cons of using more or less AZs in a region to host our high availability DB servers. We have several pairs of replicated DBs and we always put them in different AZs. But we’ve got a dozen instances in this configuration and we only use 3 different regions to spread them out. We are still automating a lot of the failover process, so if we need to promote a follower to a leader in the case of an outage it’s a fair amount of work. In a recent outage, we needed to promote several instances at once because the AZ held about a third of our instances.
So the question came up, should we spread out our instances to more than 3 AZs with the intention of reducing the potential amount of work we need to do after an outage or should we stay in 3 AZs knowing that the more AZs we reside in, the more likely we are to be in an AZ with an outage. Are there other questions we should be asking ourselves, as well? Are there any best practices around this? I’ve done some searching but there aren’t a lot of articles that go past saying you should spread out to more than one AZ. TIA
If you hope to effectively automate failover and prevent data divergence via consensus, you’ll need three zones with at least two holding data (if one is only for quorum). It is up to you if you need more than that, though I would not recommend less.
In most cases, three is sufficient to accomplish reliable autonomous high availability. If you employ fencing (you didn’t state how your DBs are managed), you may be able to get away with two - though configuring such a thing (2n with fencing) is a very strict process that punishes configuration errors harshly.
or should we stay in 3 AZs knowing that the more AZs we reside in, the more likely we are to be in an AZ with an outage.
You’re asking good questions. Ideally your system should gracefully handle AZ outages without you having to do manual failover. If you can fix this then the math becomes easier. Sounds like you’re trying to do this already.
What is the impact to your business if one AZ goes down? How is your system bound? Network, CPU, memory?
Running more AZs increases IMR because you pay for cross AZ traffic, but it means that you can spread hosts across multiple zones and you can run with lower head room (which can lower EC2 cost). Lower head room means that if you originally run with 3 AZs and need to handle one AZ outage, you need to run with 17% extra capacity in the other AZs. If you have 4 AZs, you only need 5% extra capacity in each AZ.
In my experience the region goes down as often as the AZ goes down, especially if you are in us-east-1. You are better off adding regional or provider redundancy than adding a 4th AZ.
A secondary argument for regions is there is typically a cost to adding AZs. If you don’t think you’ll actually gain much from the 4th AZ, why add the cost?
If you’re not autoscaling something here, then in general you want 3 AZs where 2 AZs could maintain the entire load expected.
To put it in a more generic way:
Lets say you had X requests per second needing to be supported by your infrastructure. You decide that Y instances are needed. You spread this over 3 AZs. But 1 AZ goes down, now (2/3)*Y instances are trying to support the full X requests a second, but they may not not be able to manage this scale.
So what you should instead do is ensure that you put Y instances in 2 AZs but then scale this to 3 AZs, leaving you with a total of (3/2)*Y instances over the 3 AZs. So if 1 AZ goes down, then the remaining 2 AZs will be able to support your traffic.
(now this all depends on what matters for your scaling etc)
If you have autoscaling, ensure your autoscaling methods allow for increasing instances “quick enough” (“quick enough” determined by your business) that if an AZ goes down, there is little/minimal erroring as your AZs scale up. You can simulate this by load testing your server, or, chaos engineering style, simulate AZ outage. Then adjust autoscaling parameters until this suits your needs.
EC2 - As many AZs as you can get in the region for Spot Instance pool purposes (there is one region in us-east-1 that is missing a bunch of generations of instance so we avoid that one and only run 5 AZs)
If 3 AZs in one region go down, what are the odds of the 4th AZ in the same region not getting affected? If you are going for multi-region, can you tolerate the data loss the extra replication lag due to cross region network latency?
If you have 3 AZs and you need to be able to handle 1 AZ outage, then your remaining 2 AZs need to have enough capacity to handle the full load of one AZ.
3 AZs = One AZ handles 1/n = 1/3 = 33% of all traffic. If that AZ goes down you will distribute it’s load across the remaining AZs. Thus, each AZ needs to be able to handle 1/n + (1/n)/(n-1) = 1/3 + (1/3 / 2) traffic = 33% + 16.6%. The 33% is from healthy traffic levels, the 16.6% component is excess capacity to handle a one AZ outage. This 16.6% is being wasted since you have to add it on top of any short-term spike protection (i.e. increase in TPS faster than your ASGs can scale up.)
5 AZs = One AZ again handles 1/n = 1/5 = 20% of all traffic. Thus, each AZ needs to be able to handle 1/5 + (1/5) / 4 traffic = 20% + 5%. Thus 5% capacity wasted just for AZ outages.
This is just one component of capacity planning for a service. There’s a lot more that I had to do when working on my prod services.
Thanks for the reply. These DBs contain partitioned customer data, but the impact is generally very low for our customers because of the HA configuration. The primary impact is currently on the team having to manually promote a follower in a healthy AZ and build a new follower in another functioning AZ.
We aren’t considering a multi-AZ outage in our conversation, but we probably should. Right now we use one region as I described above but also use another region entirely for disaster recover. We use a similar replication strategy there as we do in the intra-region HA configuration. We’re not as worried right now about DR or HA issues – we have those concerns on the roadmap for a later date – but we’d like to minimize our hands-on time in as MVP a way as possible. And if that’s migrating a few of our instances to another AZ over the next couple of weeks, yay us! =) Thanks for your reply.
Thanks for your reply. In my description above, I don’t describe the DR side of our DB architecture that is hosted in another region entirely. Did that to make the problem simpler to describe. We are already buying into the need to pay for cross-AZ data, so really the only thing we’re hoping to gain is less work in the inevitable case of an AZ outage. If we have fewer instances in the failed AZ because we spread them out to a 4th AZ, then we have less work. But if we are now responding to more AZ failures than we did before because we’re now in more AZs, then maybe that’s not a great trade-off after all. I appreciate your input.