Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Let's say I have web application that runs on a single EC2 instance (PHP + PostgreSQL). Now I create Load Balancer and set Auto Scaling.

The question is: how do I replicate database on the fly when AutoScaling starts new EC2 instance? How do I replicate files and folders of my application? And finally, how do I sync changes made on every single instance to my main instance?

share|improve this question

3 Answers 3

You have to separate PostgreSQL instance from your PHP/Apache instance. And setup autoscaling for your PHP/Apache instance.

PHP/Apache instances can get sync getting files via s3,git,or svn. Or use shared filesystem like NFS.

That way you can have 1-N of PHP/Apache instance with only 1 DB.

share|improve this answer
    
OK, I can sync my files and folders using s3, git and svn. But I would like to have my PostgreSQL database replicated, because complicated SQL calculations also take time. –  Paweł Karpiński Dec 16 '10 at 8:08

When you're only running two instances, I would wait with the load balancer and start by dividing up server roles. So you run the PHP application on one server and the PostgreSQL on another.

You will get more efficiency, since it's easier for a server to always do the same task, than it is to jump between the database and the php scripts. Especially for the database.


When the time comes to add the third server, you can add a front end server and set a load balancer between those two, but both of them will be connecting to the same database.

But there is another issue with the load-balancer scheme which you didn't mention, but you will definitely run into and that is maintaining sessions. But if you don't have logged in users, that's probably not a problem for you.

share|improve this answer

I would also suggest to separate the web servers from the database. Scaling out web servers (= starting more instances of it) is usually simple using one of the filesystem synchronization or sharing options described in the other answers.

However this will not be as easy with the database.

If you have the option to change your application you could also give Amazon's Relational Database Service as try. However, since this is a MySQL clone, it is not identical regarding features with PostgreSQL.

If you would want to give a totally different storage option a try, you might want to take a look at SimpleDB - which is one of these "modern" NoSQL storage options. But do not expect to be able to do everything you are used to from a relational database.

Both of these storage options (RDS and SimpleDB) are scalable by design, so you should not have problems when using these with lots of load-balanced web servers in front.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.