Load Balancing with DNS

Você pode ler este post em português também.

Hello! The article of this month will show how is easy to balance the load of an application using your DNS. However, you must be able to do the following actions:

  1. Take from your web server the responsibility of storing the session data of your application;

  2. To have access to the DNS server that holds the records of your domain;

  3. To have more than one web server to holds the requests (obvious, but it’s good to say…).

If your application is written in PHP, you can treat the first item above trough the session_set_save_handler. It’s beyond the scope of this post to show how to do this, but a visit in PHP website will detail the use. The big trick is really on the configuration at DNS server (2nd item). You must configure, to the same A record of your application, the both (or more) IP address which can handle the requests.

The piece of code bellow has been taken from a zone configuration file of a DNS server: ns1 IN A www IN A mta IN A **app IN A app IN A**

This feature of balancing the hits of a host to different IP addresses at DNS server could be done via SRV records. The screenshot below shows us (by Apache logs) that both servers are treating the hits. Application Load Balancing with DNS.

The scenario will complicate a little bit more if your application needs to receive data via upload, which will implies in a common place to save the files.

See you ;-)

Published At (Updated At)