Life the universe and everything

Archive for March 2007

Poor mans failover

with 18 comments

This ‘How-to’ blog is primarily intended for webmasters with database driven websites (but also covers effective but cheap IP failover for all webmasters) who need to achieve high availability without high expense and is based on my own experience.

So why am I writing this? Well … at the time of writing I am struggling to find any resources for cheap, high availability and fail-over techniques which cover the failover scenarios a web master might face. The articles I’ve found also tend to be highly technical. I hope I can offer you a method which offers effective failover and allows you to maintain high availability using simple, effective and cheap resources.

A word of warning! We all know that 5 nines of availability is the goal (99.999% uptime) but that kind of availability does not come cheap. This article is intended for website owners who can live with a few minutes of downtime now and again but would like to avoid a few hours.

Here is the summary of main points/requirements:

  1. You must control your own DNS
  2. You need multiple websites and/or multiple databases
  3. You pay for a DNS failover service

DNS nameservers

You must have control of your DNS nameservers in order to specify a DNS failover service. I have shared hosting which comes with its own name servers but I use a managed DNS service at ZoneEdit for my primary name server and list my hosts DNS as secondary name server. Experience has taught me never to keep all my eggs in one basket. I use Zone Edit because they offer the failover service.

[update]I have since swapped to as they offer a 2-4 minute failure detection/recovery time[/update]

Multiple Websites

Here’s my scenario. I have shared hosting for my database driven (MySQL) website and I have a server in my office which has the same files. I use this server for development and testing and it makes sense to use it as my failover server for when my main website fails. I also have an installation of MySQL on this server. The office has broadband with a fixed IP address.

OK, so not everyone has the luxury of a development server … but you do have the option of very cheap hosting at a different hosting company!!! If you need high availability you need somewhere else to take over when your primary site goes down. You simply need to ensure that the failover website has a reasonably up to date version of the live site.


I backup my live MySQL database every day and I ‘restore’ the latest backup to my office server as often as I remember.

I learned to my cost that database downtime accounts for the majority of my sites total down-time. Here’s where having a secondary database gives you another added advantage. With most database connections you can write script (php, asp etc) which checks the availability of a database and if it fails you instantly and seamlessly connect to your backup database and the page still executes on the primary website. I use such a script as a global connection which is used on every page. The classic ASP version is:

Set objConn=Server.CreateObject (“ADODB.Connection”) connstring, “”, “”
If objConn.errors.count>0 Then
objConn.close connstring2, “”, “”
End If

If my live database goes down (which it does) my users are unaffected because my scripts instantly switch to the secondary database.

Failover Service

For at most around $11 per year (multi-credit purchase is much cheaper) the ZoneEdit failover service will retrieve a specified page from your website every 10-15 minutes. It uses simple regular expressions to check for valid html content. If it cannot retrieve the page it dynamically changes the DNS pointers for your website to the IP address which you specify in the failover service. In my case the office IP address but could simply be a second hosting company IP address.

What happens then?

New visitors to the site will mostly be directed to the backup site. Visitors who were on-line at the time will lose the connection. This is because their browser will continue to attempt to access the ip address it has cached for the domain. This is another slight compromise.


Given a secondary website and/or database on a different server we can use simple scripting to connect seamlessly to a secondary database should the primary fail. Using a DNS IP failover service can provide high availability (10 mins average detection time at failover) by redirecting users to a specified secondary ip address.

This is my guerilla method for cheap fail-over and it has proved very reliable. I hope it is of use.


Written by barnabyfry

March 22, 2007 at 5:24 pm

Posted in How to