So I’m curious… I understand that cross-az traffic incurs a cost. I’m over here playing around with RDS and wondering how one would go about eliminating cross-az traffic when using RDS.
Does the best solution involve using a global cluster with 1 cluster in each of 2 AZs with write-forwarding enabled?
Would this create a scenario where the cost of the additional cluster is (most likely) greater than that of the cross-az traffic I would incur using a single cluster?
if you want cross-AZ redundancy (which you likely do in production) there’s not much to do but pay the fiddler man
One thing we’ve done is to make sure that app servers and other services that speak to the DB are in the same 2 AZs as the DB (assuming a standard active/passive multi-AZ config)…this ensures that at least half of the traffic is intra-AZ while the other half comes from another AZ
Gotcha. After spinning up my idea (global cluster with 1 cluster in each of 2 AZs with write-forwarding enabled) and then looking at the cost of the smallest DB instance allowed (r5.large), it seemed intuitive that some cross-az traffic would be cheaper.
I’m new to AWS so this seems a little off to me. I guess it is what is!
One of aurora benefits is that replication doesn’t consume traffic (because it isn’t actually replication). We are running replica in each AZ and app is confiured to prefer local replica. It saved us so much money that is is cheaper for us to run three replicas than to run one and pay cross AZ traffic.
An error occurred (InvalidParameterCombination) when calling the CreateDBInstance operation: The requested instance class is not supported by global databases: db.t3.small
Fargate task that calls aws api every 10 seconds to get list of running replicas (with AZs) and running ECS tasks (with AZs). Replicas are duplicated in list 10x times and than iterated over to distributed between list of tasks (replica from same AZ is preffered) - each tasks ends up with list of replicas. Ideally it is 10x one replica from same AZ but if there is no replica in same AZ or there are many tasks in one AZ, list will contain different replicas. If it is distributed this way, database load is distributed evenly.
This list is than saved to redis with timestamp. App is reading this list (refreshing it every few seconds) and each request uses random replica from list. If the timestamp is too far from current time, something is broken and it will fallback on aurora cluster read endpoint.
It is surprisingly simple to implement - it requires maybe three lines of code in app and fargate microservice is ~50 lines of node.js that mainly pushes values from one array to another.
So you get a list of something like {replica, AZ} and tasks { task, AZ}, then duplicate those replicas 10x? so each task gets a list of replicas to use?
At first version we just assigned each task its replica. But that doesn’t work very well if cluster isn’t balanced between AZs. Duplicating list of replicas and assigning multiple to each task is easy way to keep same connection count to all replicas. It also can handle cluster where replicas have different instances sizes - duplicating in replica list can be determined by memory size etc.