How to scale a web application
My main question is, how do I get started building a web application that can grow rapidly?
Small background: a client asks me for a proposal for a web application. I can't go into details, but this is e-commerce and the crowd is funding something like this. Therefore, he wants to spend some money and expects the site to grow indefinitely.
I am planning to build it with Zend Framework 2 and MySql. My problem is that I have no experience with large scale web applications. I read everywhere: no problem, just run the project and if it grows to big, you can react to it and add caching, clustering, etc.
But is this really the case, or do I need to add some scalability mechanisms from the beginning? For example, cloud servers (Amazon EC2) have a different approach to the file system. Can I switch later? Or what about load balancing? Am I having problems with session processing or not? What about MySql? Or is it better to start directly with the NoSql approach?
So my current plan is:
- Step 1: Usually build a web application using ZF2 and MySql.
- Step 2: add caching like memcache and opcode
- Step 3: MySql or NoSql cluster or load balancing or cloud server
Okay, I know my question is too broad. So I'm trying to trace it down to a few specific questions:
- Is it better to start directly from the cloud server?
- Can a cloud server grow indefinitely?
source to share
Scaling is a complex issue and different projects have different needs. I recently read a good book on scaling PHP applications. Maybe this can help you: https://leanpub.com/scalingphp
Some tips from the book
- Load balancer for incoming requests
- 1 Master Mysql server for writing and slave mysql servers for reading (if master goes down the server can be promoted
- Using Session Store I think the book recommended Reddis (not sure if it's a few weeks ago).
- Start Nginx instead of Apache
And on a personal note:
- It might be about taste, but I would recommend Laravel as PHP Framework, it is lighter than ZF and (again, taste ..) more elegant.
At this point, I no longer remember from the book, but if you cannot get enough information, contact me by email and I will search for it.
Should I be concerned with scaling from the start, or is it easy to add these technologies like load balancing and session storage later?
What I learned from the book is that in their case (Twitpic) the scaling started after the project got large and experienced a lot of downtime. I think it's good to think about what scaling steps you want to take. Dedicated (My) SQL Server or Load Balancer can scale out when your project needs to scale. But when you plan on using the session storage service, I would recommend starting from scratch so you don't need to rewrite your code at the moment when scaling is required. Also, some session storage services store as much information as possible in RAM, which reduces execution time.
Also when you set up a server, I would say starting with Nginx, it uses less resources than Apache.
source to share
Step 1: Build the web application normally with ZF2 and MySql. Step 2: Add caching like memcache and opcode Step 3: MySql cluster or NoSql or load balancing or cloud server??
Here's my suggestion:
Step 1: Build the web app on CodeIgniter with MySQL (lighter, and faster than ZF2 with MySQL) Step 2: Do memchace, opcode and don't forget phpfpm Step 3: Use Amazon EC2 and use their Load Balancing features to load balance between servers.
source to share