Congratulations, your server is melting.
This is a good problem to have (server heat is proportional to # of users). And it’s not so difficult to deal with if make a few preparations in advance.
After launching a number of web services and viral social media apps, some of which grew to hundreds of concurrent users and zillions of hits within days, I’ve had to learn “on the job” about scaling websites. Here I present to you my thoughts and some simple suggestions on how you can prepare ahead of time.
Part 1: Think Modular
Really the most important principal to take on board is modular design. If you look at any high volume platform you’ll quickly see evidence of how the components of the service are split up into separate independent units. Wikipedia is classic example of this, cheek out the architecture behind wikipedia.
If you can separate all the different components of your website/web app, then you can easily apply more resources where they are needed. Just upgrading to a bigger server won’t get you far, long term you need to be able to identify where the bottle necks are and apply resources efficiently. In fact even identifying the bottlenecks can be surprisingly hard, modular design makes this much easier.
So some examples of the typical components your website/web app will be using:
- media, images, static files (javascript, css etc)
- db server
- batch processing (webstats, image resizing etc.)
- front end (normal user area)
- back end (control panel)
Separating these components needn’t be rocket science, here’s some simple examples of how you could apply modularity to the components above:
- media -> move all media and static files on a dedicated domain/subdomain (or better still in a CDN) e.g. <img src=”http://media-server.mydomain.com” />
- db server -> always use a central config file for db settings, so you can easily change the hostname when the time comes to use a dedicated db server: $db_hostname = ‘mydomain.com’ -> $db_hostname = ‘dbserver.mydomain.com’;
- mail -> again make sure mail settings are in a central config and ideally use a framework/library that allows you to change to an external SMTP server/service
- batch processing -> create an independent system for any batch processes, for example use a standalone phpthumb installation for image resizing.
- separate front end / back end -> make use of different a domain for control panels e.g. www.mydomain.com and controlpanel.mydomain.com, so later on it’ll be easy to move these onto different servers
In addition to thinking modular, always be monitoring and profiling your systems then you know exactly where the bottlenecks are and can deal with them more effectively.
Part 2: Other Key Principles
1. Queuing/Batching
Typically there may be parts of your application that involve heavy processing. If these don’t need to be real time, or can tolerate slight delays then separate the processes and make use of queuing/batching so your web application isn’t held up.
Google Analytics is a good example of this, generally there’s no need to have real time webstats, so the collected stats are batch processed at regular intervals. Another example could be image processing, I’ve written about this in more detail here.
2. Partitioning
Taking modularization a step further and we have partitioning i.e. splitting data up in to smaller manageable chunks which can be stored/operated on separately. If you have a multi user system you could split users across servers, so for example your could have 1000 users per server, or split users by user id odd/even, divisible by X etc. Again you could do this ahead of time with subdomains:
odd user id: controlpanel-a.mydomain.com
even user id: controlpanel-b.mydomain.com
Another example of partitioning is database partitioning, here’s a quick introduction, but this would come way later, having a dedicated db server or db cluster will scale you a long way.
3. Code First, Profile and Optimize Later
Slightly contrary to the idea of scalability, but definitely on topic: don’t start your code design with optimization, this is a waste of time. Not even the mighty He-man could predict where all your bottle necks will be. Always focus on writing easily maintainable code, and then in the later stages of development you can profile your application to find out where you need to optimize your code.
4. Cache Cache Cache
Caching is probably the simplest and cheapest way to dramatically improving performance. There are a variety of stages at which you can use a cache and whilst some require a little care at least a couple are almost trivially easy to implement. It’s good to be aware of all the options even if you don’t need to implement them yet.
Super Easy
- Opcode Cache/Acceleration (like APC, xcache ) -> once installed require minimal maintenance and are completely transparent to your application. They simply keep copies of your complied scripts in memory.
- DB Cache -> again usually very simple to install and will be transparent to your application and keep the result of queries in memory. for mysql users, see here.
Easyish
- Cache server/HTTP accelerator (squid nginx varnish etc.) -> This is very common with high traffic sites, Caches can easily multiply the capacity of your website. Again this kind of cache is outside of your application so is relatively easy to work with. However you may need to take some precautions to ensure certain items aren’t cached, and are expired in good time and you’ll need a higher level of sysadmin skills to set up and maintain a cache server.
- Built in framework cache -> many code frame works come with a cache system out of the box (e.g. codeigniter) this is a lot easier than rolling your own, but still you’ll need to be aware of how it works to avoid caching pages that should stay fresh.
Harder
- Application object cache -> this kind of solution involves using a library/framework that allows you to cache arbitrary objects/variables across sessions. For example you might have a widget that appears on multiple pages, you could cache the object that generates this widget (or even the HTML output itself).
- Setting HTTP headers -> you can of course manually set HTTP headers that tell web browsers how long to cache pages for. This gives the best performance boost as the data is stored locally on the end users machine. However this is no trivial task and requires a full understanding of how browsers respond to HTTP cache headers, here’s more info on the subject
Part 3: Quick and Practical tips
Within 10 mins his app was performing about 10 – 50 times faster. All I did was add a few basic indexes.
1. Database Indexes + Query Optimisation
This isn’t strictly about scaling, but it’s such a good performance tip: Learn how to do good DB Indexes, they are really simple and without them you’re hemorrhaging your DB’s potential performance away. here’s a quick tutorial.
I was having a geek cafe session with my good friend Craig Mod one afternoon and he asked me to look at his application as it was a bit slow. Within 10 mins his app was performing about 10 – 50 times faster. All I did was add a few basic indexes.
As mentioned above, don’t forget to turn on the DB query cache.
2. Use a separate database reader and writer
There are a number of reason why at some point you’ll need a DB master and slave(s) (load balancing, redundancy, zero downtime backups), you can prepare for this now by having two DB objects e.g $db_reader and $db_writer
$db_reader = new db_object(SLAVE_DSN);
$db_writer = new db_object(MASTER_DSN);
//reads go to the slave (or master)
$db_reader->query("select * from user where id = 1");
//writes only go to the master
$db_writer->query("update user set status = 'kool kat' where id = 1");
With a simple change to your DB config this allows you to instantly use a master/slave(s) setup to spread the load on your database.
3. Account For DB Reader Delays
Allow for the DB reader to be slightly behind the master – replicated slaves are likely to periodically lag behind the master even if just for a second or two. If you are using the tip above and sending reads to a slave then this could cause problems in your application. For example say a user is logged into a control panel making changes, if the DB reader is behind the DB writer, then trying to fetch the new changes from the database will potentially show the old values if the DB reader is behind.
4. Separate Server For Media/Static Files
I’ve mentioned this already above, but it’s worth mentioning again. Set up your site to host all images, js and css on a domain different from your main website. I’d recommend you have some sort of central configuration so the static server url is automatically included in all image urls e.g.
//hand coded (not recommended)
<img src="http://images.mywebsite.com/images/1234_an_image.jpg" / >
//simple variable
<img src="<?php echo $image_server; ?>/images/1234_an_image.jpg" / >
//or full managed image urls using a special class to generate urls
<img src="<?php echo $this->images->get_image_url($image_id); ?>" />
5. Mail Config
If your application sends emails, make sure the mail config can be changed easily and can use SMTP. Part of modularizing + queuing would involve having a separate server for sending, it’s most likely you’ll connect to this from your app via SMTP. Particularly now as there are a number of 3rd party SMTP services that can reduce the increasing headache of reliably sending mail.
If you are using a standard mail library like phpmailer, or as part of a framework, then this is probably set up already – see the docs. if you have your own DIY mail functions, it’s probably best to swap to some established library (e.g. phpmailer) anyway, no need to re-invent the wheel.
6. Avoid local file system dependencies – separate your data storage.
Separating storage of data from your application is an essential part of being modular. Probably most of your data is in a database already so without too much sweating and grunting this is most of the battle won. However you may be storing uploaded files, images etc. which you definitely don’t want to store in a database. But you shouldn’t just write these to the local file system either, if you use a cluster of application servers then you’ll need some sort of shorted storage system. A good example of this would be Amazon S3, there are plenty of client libraries and example code that means it should only take a matter of hours to integrate. An NFS server could be an option, but NFS can be nasty!.

7. Efficient Backups
Large backups can really slow down or even stop a server (particularly large DB backups), but chances are you could significantly reduce this load by
- Not backing up temp/cache files
- Using git/svn etc. and backing up the repository not the web application docroot
- Database dumps/snapshots using a slave, so write locks will not affect your DB server
- For your data storage use a filesystem/system that support snapshots (e.g. ZFS)
8a. Get into the Cloud
Using virtual servers/cloud computing will give you a certain amount of scalability for free. Most virtual server providers make it very easy to up the power on your machines, whilst this may not be the most elegant solution, it saves a massive amount of work compared to the task of migrating dedicated servers.
However that’s not the only scalability benefit. You get many of the suggestions I’ve made here for free with Cloud/Virtual computing, e.g.
- Easy to clone machines (for setting up multiple identical servers)
- On demand computing/per hour billing is great for batch processing
- Filesystem snapshots
- Robust Storage Solutions (e.g. Amazon S3)
8b. Services Above The Clouds
And last but not least I should mention there are now a number of higher level services, RightScale.com, Scalr.net, Google App Engine to name a few that offer automatic scalability. If you are able to work within their constraints (for example App Engine only supports Python + Java) then they can be a very attractive offering. Google App Engine:
Automatic scaling is built in with App Engine, all you have to do is write your application code and we’ll do the rest.
Closing Comments
As technology advances, a lot of scalability issues become easier to solve or disappear – we have cloud computing, easy to use CDN’s and services like Google App Engine. However until we have the Holodeck, I’m pretty confident most of the principles I’ve raised today will still be important in your design considerations.
…oh and hopefully your server has stopped melting now.
Further Reading
Here’s a few books that have helped me:
Check out a real world example, wikimedia:
http://meta.wikimedia.org/wiki/Wikimedia_servers
highscalability.com has some good resources:
http://highscalability.com/blog/category/blog
Amazon s3 versioning
Amazon now offers what I would veritably call “indestructable fool proof” file storage. S3 already provides an extremely high level storage durability – multiple geographically separated copies of your data. Now Amazon have taken it a step further with versioning, so even if you accidentally delete your data it’s still safe.
The amazon S3 announcement which just popped into my inbox:
We are pleased to announce the availability of the Versioning feature for beta use across all of our Amazon S3 Regions. Versioning allows you to preserve, retrieve, and restore every version of every object in an Amazon S3 bucket. Once you enable Versioning for a bucket, Amazon S3 preserves existing objects any time you perform a PUT, POST, COPY, or DELETE operation on them. By default, GET requests will retrieve the most recently written version. Older versions of an overwritten or deleted object can be retrieved by specifying a version in the request.
You can read more about how to use versioning here.
Obviously you’ll have to pay for the extra space taken up by versions, but this looks like a really top class option for storing data that’s not regularly updated e.g. an image archive.
Also be interested to see if this spawns any new uses for Amazon web services…
Cloud Computing Price Comparison
Apples and Lizards
I’ve just been researching the estimated cost of cloud computing on some of the various providers out there who want to absorb your servers into their clouds.
Doing this research has been like comparing apples to lizards. The providers all have their own way of billing you, and there’s a whole host of extra features offered, some free, some not. To help you on your quest I present some nice tables with the results of my investigations here.
data
I tried taking a fixed monthly budget and seeing what best value I could get for the money as I think this is a fairer and more realistic comparison. I have as far as possible searched for the best deals (e.g. using amazon’s reserved instances and GoGrid’s pre-pay plans).
| Price | Resource | EC2 | GoGrid | RackSpace | VPS.net |
| $100/Month | CPU | 3×1GHz | 1Xeon | 2GHz* | 2.8GHz |
| Ram (GB) | 4.2 | 1 | 2 | 1.7 | |
| Storage (GB) | 480 | 60 | 80 | 70 | |
| B/W (GB) | 130 | 0 | 80 | 1750 | |
| $200/Month | CPU | 2xDual2Ghz | 1Xeon | 4Ghz** | 6GHz |
| Ram (GB) | 15 | 1.5 | 4 | 3.8 | |
| Storage (GB) | 1700 | 90 | 160 | 150 | |
| B/W (GB) | 100 | 206 | 80 | 3750 | |
| $500/Month | CPU | 4xDual2Ghz | 3×1Xeon | 4×2Ghz* | 3×4.8Ghz |
| Ram (GB) | 30 | 9 | 8 | 9 | |
| Storage (GB) | 3400 | 420 | 320 | 360 | |
| B/W (GB) | 550 | 0 | 500 | 9000 | |
| $1000/Month | CPU | 8xDual2Ghz | 3×3Xeon | 2xquadx2Ghz | 6×7.2Ghz |
| Ram (GB) | 60 | 12 | 16 | 28 | |
| Storage (GB) | 6800 | 520 | 620 | 1080 | |
| B/W (GB) | 1200 | 1000 | 1000 | 27000 |
* The 2Ghz is actually 1/8th of a 2xquad core 2Ghz machine
* The 4Ghz is actually 1/4th of a 2xquad core 2Ghz machine
Alas GoGrid only displays “Xeon” for the CPU, no further info seems to be divulged.
If the shoe fits
It’s become evident to me that you have to find the best fit for your needs (and future needs) in terms of price and features. It seems Amazon is the cheapest in terms of Memory and CPU, VPS.net by far the best for B/W while GoGrid throws in great freebies such as 100% SLA + Load balancing.
Here’s some quick facts to throw into the mix:
Amazon
- No persistant storage (you can use EBS or S3 for this at extra cost)
- No SLA
- Support costs $100/month or $400/month
- Lot’s of complementary services (Storage, RDB, Billing etc.)
GoGrid
- 100% SLA
- Free Load Balancer
- Free 24/7 support
Rackspace
- Free “Fanatical Support“
VPS.net
- Free Daily Backups
- Support $99/month (includes 100% SLA)
Some price comparison tools
- amazon AWS price calculator
- rack space cloud pricing
- GoGrid pricing calculator (doesn’t include bandwidth though)
Anyway, I’d be interested to hear anyone’s real experiences with hosting services in the cloud.
Cyber Mercenaries For Hire
I have one or two allegedly white hat friends and enjoy stories of lore and legend regarding their chivilarous and well contained sporting activites. However when it comes to professional cyber crime, I feel my Tokyo life is somewhat sheltered from the darker forces that glide through the veins and fibre cables of the internet (this may be in part to being a non-windows user), so I was rather intreiged by one of this morning’s comments on my blog:
Tired of a competitor’s site? Hinder the enemy? Fed pioneers or copywriters?
Kill their sites! How? We will help you in this!
Obstructions of any site, portal, shop!Different types of attacks: Date-attack, Trash, Attack, Attack, etc. Intellectual
You can work on schedule, as well as the simultaneous attack of several sites.On average the data, ordered the site falls within 5 minutes after the start. As a demonstration of our capabilities, allows screening.
Our prices
24 hours of attack – $ 70
12 hours of the attack – $ 50
1 hour attack – $ 25

I note that perhaps a copywriter/proof reader might benefit this particular ‘Cyber Mercenary’, or perhaps there is a subtle difference in the third line between ‘Attack’ and ‘Attack’ to which I am not yet attuned.
Oh, and here’s an example attack that was “clearly ordered by someone”.
Just at the end of my trip to the UK, highlights include:
- A visit to the Tate Modern
- A stroll down Brick Lane with master painter Darvish Fahkr
- And lunch with ‘Philospoher’ David Pearce
My Secret Voodoo SEO Technique
I’ve been on the fringe of the SEO industry for over 10 years now. I’ve have watched it change from the good old days of when keyword stuffing would get you at the top of AltaVista to the modern day which uses some of the worlds most sophisticated software and technology.
And after experimenting, researching, listening to White Hats, Black Hats and an entourage of other SEO guru’s I’ve come to the conclusion that now-a-days effective “SEO” has become pretty simple. Not necessarily easy, but it is simple. The 3 steps below are my ’secret’ formula which has worked well, for instance most of our business leads for The Artists Web come from natural search and our advertising budget is practically zero.
Step 1. Get a high Page Rank
This is more important than anything else and also significantly more difficult than the following steps. I’m sure you already know what Page Rank is – and that getting a high PR is basically down to how many quality incoming links you have. In essence what the rest of the internet is doing is more important than what you do on your own site.
In my opinion, the most effective long term ways of getting incoming links are
- Have a regularly updated interesting website/blog
- Create a great web service
- Create some viral content
- Make lots of friends
Step 2. Know your target subject and keywords
Your website has a theme, and you have a target audience you wish to attract. Obviously the theme and the search terms your target audience use must align. Moreover use keyword tools to find out the specific language most commonly used – for example is which term is most searched “sell artwork” or “sell paintings”?

Step 3. Create a high PR page for the subject/keyword in question and apply a few simple techniques
Finally you create a page on your site, give it as much page rank as you can and make sure you are using the keywords appropriately. These techniques will help, but they are no silver bullet – really the without the first step (getting the high page rank) any SEO ‘technique’ is going to be of limited use.
- Link to the page from every page on your site, or at least from your higher PR pages e.g. the home page. This ensures you are allocating as much page rank to the page as you can.
- Put the main keywords in the page title
- Write a compelling Meta Description, the meta description is often used on the search results page, this is your chance to write some compelling copy which encourages people to click on your link. Don’t worry about keywords, consider it similar to writing the copy on a paid search advert.

- Phrase your copy to natuarlly include search phrases. This is the only ‘trick’ that I use, just bare in mind your target search phrases. e.g. for the phrase “sell paintings”:
Okay
Selling paintings online is easy with our service.
Better
Our service helps you easily sell paintings.
- Use appropriate keywords in the url e.g.
Bad/page.php?id=1232
Good
/how-to-sell-paintings
Surely it’s not that simple?
Well actually I think it is. Basically google (for now english language search is pretty much all about google) has some of the best brains and technology continually working to ensure it has the most relevant, useful and authoritative results. It’s therefore simple enough to presume that long term the most relevant, useful and authoritative results will tend to feature first, so really all you have to do is be relevant, useful and authoritative – simple, but not necessarily easy. Yes there are plenty of other techniques and factors (HTML validation, link anchor text, page cachebility) but none of them
Finally, don’t cheat
And don’t be tempted to go for any ‘black hat‘ SEO technique – do not run the risk of being penalised. Think long term and focus on quality.
So Mr Kirkland has just launched Artweet, a handy little service for pimping your profile with a customized twitter background.
Even peeps with photoshopping ability will still find it a useful as you can create your own personalised background with mug shot, message and might in 3 clicks and a few taps.
It’s new so the paint’s probably still a little sticky, but give it a go and lemme know what you fink. I’ll be adding more backgrounds and open to your demands/requests/pledges of marrage.
If you’re reading this, I’m guessing you’ve got a roof over your head, a non polluted water supply and do not need to dodge death escaping from lions/godzilla etc. every day. In fact chances are you have graduated to the higher ranks of Maslow’s hierachy of needs and maybe even some designer crockery in which to serve your Gordon Ramsay Goat Cheese Salad. So I put it to you that the prehistoric fight or flight reaction called stress which is ultimately for saving you from imminent death is simply not relevant to your modern life.
How to reduce stress from work – work smart
There’s tomes of material on reducing stress, particularly at work, but on a micro level I think it all simply boils down to to what you do with your thoughts. Simply, being more aware of yourself rather than locked in ‘toxic thought’ is all it takes. There’s plenty ways of doing this, but for todays Mr Kirkland blog post, I’d like to explore the idea of working smart, not working hard.
To me, working smart means actively being aware of how you are working and looking for ways you can be more efficient, getting more done with less effort – a total no brainer! Working Smart is an attitude more than a specific technique, all it really takes is to stop regularly and ask yourself “am I working smart here?” For example I try dedicate some of my work time every week to reading up on techniques/practices that will make me more efficient or better at what I do.
In addition to the attitude of working smart, it’s important to identify where you’re not working smart and still working hard.
Tell tales signs of working too hard
- It’s good to work hard, I feel like I’m getting more done.
This is a convincing and difficult habit to break – I almost equate this thought to burying one’s head in the sand. If you’re too busy working and not thinking about how you work, then chances are you’re not as efficient as you could be. Moreover if you motivation is driven by the feeling that you’re getting more done, then you’re not living in reality. Come back to reality, stop, go home early and think about how you could work smarter if you’re working smart then you’ll get twice as much done - If I don’t work hard, someone else/a competitor will move in
Maybe, but if your competitor is working smart then they’ll overtake you regardless of how hard you work. - Thinking about your work outside of the office
Simple, when you’re not at work, you shouldn’t be working. Even if you run your own business, take time out to relax and think of other things, you’ll come back to work fresher with more energy. - Putting off doing your real passions
If you’re not making time everyday to pursue your life passions, start now – don’t put it off. Don’t make the make “having to work” a half arsed excuse for not pursuing your dreams – it’s your life make the most of it now. - I feel stressed but I just want to finish this task
I think this is a classic symptom of working too hard, even though you know you are tired/stressed you get caught up wanting to finish some (usually trivial) task before you stop. If you realise you are stressed, stop immediately, do some breathing exercises, relax until you feel noticebly better – and if you can’t de stress in a few minutes get away from work completely for a while. - Irrational Fear of Lizards
It’s okay, lizards just want to be your friend – meditate, breath and relax.
Conclusion
Okay, I think that’s enough for today – write “I always work smart” on a post it note and stick it onto your forehead. No go out and play.
After many years of toil, sweat and sacrifice I believe I have finally unraveled the secret to obtaining long term ‘excellent’ keyword search results.
Firstly, one needs to understand what “excellent keyword search results” actually means. And of course (as I’m sure you’re wise enough to know without being told), they refer to the most amusing results.
Top 10 Keywords, Sentence Game, January 2009

amazing!
5 steps to success
- Start a simple word game website
- Wait for ‘mature’ males to start playing
- Stand back and watch the endless reams of nonsense and toilet humour amass
- Soon google will have enthusiastically sucked up all your “original” content
- Success! long term page 1 ranking for “spastic porn”, “frotage” etc.
Conclusion
Now-a-days, having retired from fortune acrued of the tens of $0.01 google adsense clicks each month, I spend most my days idling on the deck of my San Tropez yacht being fed organic grapes whilst simultaneously being massaged and bathed in goats milk.
Further reading check out the sentence game.
- Start the day with an important task – do this before you check your email/phone/SNS etc
You’re probably aware of how much time you fritter away swapping between email, work, text message, news etc. I fritter my time away too, however I make a point of starting the day with a focused and ‘important’ task and do this for at least an hour before I even open my email client.
- Regular Breaks every 45 mins
Sure you know this one – concentration/efficiency starts to nose dive the longer you go without a break – doesn’t have to be long, even just a few headstands will do
. - Work Standing Up
Seems to be plenty of discussion on this subject, and I just started this recently. If you’ve not done martial arts/tai chi then I recommend you learn the tai chi stance – basically relaxed, balanced posture with slightly bent knees (all the time).
- Less multi tasking
I’m not so cool, I find attempting to do multiple tasks at the same time usually results in me achieve multiple inefficienies.
- Finish Early
When I work late (as in past an 7 hour work day) I’m simply wasting my life. I’m less efficient, more prone to making mistakes, causing stress in my body and chances are if I’m not getting my work done in a reasonable time frame then I need to take time off anyway and think about why I’m so inefficient (or setting un realistic goals).


















