If you application is business critical and you think high availability and disaster protection is too complex and expensive then this is for you. We will show you how to setup two sites and use a couple of SaaS services for site fail-over and monitoring. These powerful tools will cost you the massive amount of about $10 per month.

So this is how it will work. By using a CDN (Content Delivery Network) and a monitoring system that will tell the CDN where to send the traffic we will get a powerful and easy to use solution.
- Create sites
You will create two sites preferably at two different vendors or regions to make sure both sites never will be down at the same time. A good example would be two Virtuozzo (formerly Jelastic) sites, Elastx in Sweden and one of the other 14 sites available around the world. Deploy you application on both sites and set up data replication between the sites.
You can choose to have an Active/Active site or Active/Passive.
I will not cover database replication now but I will get back with a new blog post discussing some options and recommendations. Please contact us if you want to discuss options on data synchronization as it depends a lot on the application and database you use.
In this example we created two sites with the following URL and IP.
http://site1.jelastic.elastx.net88.80.172.123
http://site2.jelastic.elastx.net88.80.172.124
And the main site address we will use is http://jelastic.se
- Configure CDN
We need an external service to redirect traffic to the sites that are available. By using CDN you will at the same time also get better response times from other geographic regions. In this example we are using Cloudflare. They have a free plan and also a very nice price model for their other plans. They also have good geographic coverage with a local site here in Sweden https://www.cloudflare.com/network-map.
- Register an account at https://www.cloudflare.com/sign-up
- Sign in and follow the the instruction on how you transfer your domain to Cloudflare, it will take up to 24h. You have to transfer you domain to give Cloudflare control of your records and also to protect it from dns attacks.
- Save the account the API key for later use, you will find it under “Account”.

We are using public IP addresses in this example but you can use shared IP and add CNAME records instead of A records.
- If you want to configure an Active/Active solution add two A records with the same name.
- If you want a Active/Passive solution you will add a single A record.
You can add a CNAME for www or other.

Now you need to get the ID for your DNS entries using the Cloudflare API. Here is how you do it using Curl which available for every OS. Replace tkn with your API key and also email and z which is the domain name.
curl https://www.cloudflare.com/api_json.html -d "a=rec_load_all" -d "tkn=1f2eedac1c9bd7071f459effd8ad313bb38da" -d "email=joakim.ohman@elastx.se" -d "z=jelastic.se"
You can pipe the result to “python -mjson.tool” to get a pretty output.
Find the “rec_id” for the domain record(s).
- Configure Monitoring
You want to monitor your sites and we also need a way to take action when a site goes down. In this example we are using site24x7 which is the only SaaS monitoring service I have found where you can configure custom URL alert actions and is a good and stable service.
- Register an account at https://www.site24x7.com/signup-plans.html
You need to use at least a Professional account to have custom alerts. You can start with the free 30 day trial.
- Configure Custom alert actions that will modify the DNS entries at Cloudflare to make traffic only to be directed to available sites.
Select the “Alerts” tab and then “Add Action”.
For an A/A solution create 4 actions with the following configuration.
Configure all actions with: URL: https://www.cloudflare.com/api_json.html
Form Submission Method: POST

For an A/A solution create 2 actions with the following configuration.

You can also try this using curl just to make sure it works before we try the hole solution. Here is one example.
curl http://javaenv.jelastic.elastx.net/api_json.html -d "a=rec_edit" -d "tkn=1f2eedac1c9bd7071f459effd8ad313bb38da" -d "id=101849947" -d "email=joakim.ohman@elastx.se" -d "z=jelastic.se" -d "type=A" -d "name=failed" -d "content=88.80.172.123" -d "service_mode=1" -d "ttl=1"
Then check the Cloudflare records and make sure it was updated as expected.
- Create monitoring for both sites.
Select the “Home” tab, “New Monitor” and then “Website”.
For an A/A solution create 2 actions with the following configuration.

- Now test it.
Take down site 1, wait for the alert and check Cloudflare that the DNS record was updated as expected.
Bring the site 1 up and check the DNS record again.
If everything worked as planned then you are done!
Now you have High Availability and Disaster Protection!
Joakim Öhman