The amount of servers and the complexity of our application is growing and we now have servers in different regions (hosted on AWS). Certain database operations require low latency so we have stuck a database in each region (which is basically a user cache) to keep the network latency low. The way the application server currently knows which user cache/database to make its call to depends on an environemnt variable set in it. This has been working fine, but it seems hacky and not optimal. Is there any way for this to be done automatically?
I was considering using a package like fping and pinging each database when the app server reloads (or caching it the first time) and using the corresponding latencies to decide which database has the lowest latency for each app server. Not sure if this is the best idea though.