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.

  • 6
    What do you have against environment variables? Commented May 31, 2013 at 3:39
  • 1
    that is a good question, I guess my problem isn't with environment variables, but automating their getting set. I already use fabric for deployment, so I've probably given up my search on automatically setting them too soon.
    – tonyl7126
    Commented May 31, 2013 at 7:42

1 Answer 1

  1. You can use cloudformation templates to inject the database into configuration files or startup scripts. If the database changes ip address then you would need to automate via some orchestration script that changes the files and reloads. See fabric or saltstack.

  2. Use ec2 api calls to autodiscover the db ip address by quering list of machines by tag.

  3. Instead of rolling your own db. Use one if amazon's storage services such as simpledb.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.