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?


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.

  • 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. – Praweł Dec 16 '10 at 8:08
  • @PawełKarpiński, You'll still need to replicate the databases on a separate server group, otherwise the databases will be disconnected and their data will become out of sync. EC2 auto-scaling only supports creating new EC2 instances, not configuring servers running on those instances. I think RDS has this built-in. – Cerin Dec 7 '15 at 17:14

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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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