Article
Introduction to Affordable, Scalable Websites
Page: 1 2
The Site Design
So how does all this help you design your site? Well, some of the lessons learned by exploring each of these alternatives include:
- Keep your site segmented into sections. For example, keep static content in one directory, and dynamic content in another, to allow easy splitting into multiple servers later.
- Try to allow for pages to only use SELECT SQL queries, or session-less pages, to allow for round-robin type Web serving.
- Never hardcode links to other pages on your site. This way, you can easily update your site if you change its location. Personally, I keep all my internal links in one file and then include them (i.e.
<a href="$global_mysiteURL/$home_url">Click here</a>) - Use caching whenever possible. It’ll reduce the load on your server and help balance things.
- Try to avoid server side sessions, but if you need them, be sure to set them up so that either the data can be shared with the other servers, or the user uses only one server.
One last note: a useful tool for synchronizing your Website between multiple servers is rsync, or, even better, cvs. If you make a change on the master server, simply commit your changes on that server, then run cvs update on the others. All customizations made on a slave server will be automatically kept intact by cvs.
Converting a Site
“Okay” you say, “I already have my site ...and I haven’t followed any of your suggestions! What should I do?” Don’t worry, there’s still a lot you can do to convert your site to run on multiple servers.
First, let’s get the easy cases out of the way. If your site is completely made of static HTML files, then you’re set. All you need to do is copy the Website to two different servers and setup a round robin DNS. If your site is almost completely static but has a few dynamic pages, simply put all the static material on one server and the dynamic material on another.
Now the hard cases: if you have a complicated user-input driven Website, some more work is necessary on your part. First, analyze your site. In particular, look at all the SQL code. Can you divide your site into distinct pieces -- such as parts which could use slightly out of date data (or read-only), and parts that write to the database? If so, you can simply setup master and slaver servers. Put the pages that write on one server, and the pages that read on another. This way, you can balance the load and reduce database traffic.
If none of the above suggestions works, look into setting up multiple distinct servers and send visitors to the server from which they signed up. In my opinion this is the easiest, though not necessarily the best way to go.
If none of the above options is successful, running several Web servers and a database server is your best bet. This will allow your Website to run virtually unmodified. Just be sure to store sessions in the database, and not in files, to allow them to be accessed from any server. Be sure to talk to your ISP to get a direct connection between the servers (or to obtain your own rack in a co-location facility) to avoid racking up huge bandwidth charges.
Conclusion
When your site suddenly starts growing like a beanstalk, it is both a joyous and worrisome event. If you have a big budget, no worries, but even with a minuscule budget you can keep your site running. If you start thinking about how to design your site to scale before problems start to crop up, you can prevent any downtime from occurring. In fact, there’s very little that needs to be done to prepare a site to scale -- with a properly designed site, you can simply drop in your new servers and be up and running in no time. Good luck, and here’s to your site!
Recommended Reading
- ArsDigital Systems Journal: Building a Scalable eBusiness Solution -- This is a good overview of how to build a proper scalable site. http://ccm.redhat.com/asj/building-scalable-ebusiness/
- CVS tutorial-- You should most definitely use CVS whenever possible. It’s your friend! http://www.sitepoint.com/article/831
- rsync homepage http://samba.anu.edu.au/rsync/
- Read more about the “Am I Hot or Not” story http://webtechniques.com/archives/2001/05/hong/
- Free round robin DNS from mydomain.com http://www.mydomain.com/help/mydomainplus/tut-robin
- A great description of round robin Web servers http://www.onjava.com/pub/a/onjava/2001/09/26/load.html
- mysql database replication. Automatically keep many slave databases the same as a master database. http://www.mysql.com/doc/en/Replication.html