What does it mean to "architect your infrastructure to support scaling", when referring to a PHP/MySQL application?
-
When people talk about designing a PHP/MySQL application so it is scalable, are they talking about just using a MVC design pattern, or is there more to it than that?
-
Answer:
That is a pretty ambiguous statement because scaling usually quite dependent on what the app is doing. It's important to make a distinction between scaling and performance. Scaling is being able to handle more requests/second. Performance is being able to process each request faster. They're complimentary things that affect each other. Generally to make a PHP/MySQL app deliver services faster: Avoid shared state. The more shared resources/state there are, the harder it is to scale out by simply adding more servers. Avoid using $_SESSION, the PHP session handler. Sessions need to keep state somewhere, flat files (ugh), memcache, database, etc. Architecting your app to not need sessions goes a long way. Use APC, this is a no brainer, as you get a lot of performance for basically free. Besides the bytecode caching, APC gives you the ability to read/write values directly into it, like memcache. There are caveats in regards to parallel writes, but a good place to stuff cache data you use frequently, parsed confs for example. Using nginx as a proxy in front, make it serve static files directly. Use PHP-FPM on the back to handle dynamic request. Don't do blocking operations. PHP accessing stuff over the network (server to server API calls) is bad. Use a backend queue/worker system (gearman, beanstalk, etc). If you need this it will greatly affect your application's design. Also there is a distinction between scaling up and scaling out. Scaling up means using faster and bigger computers. Scaling horizontally means using more computers. Which ones gives you more requests per second depends on your application's needs. It'll also affect your application's design. Designing your app to scale horizontally, while harder, will usually mean scaling up is solved too.
Benson Wong at Quora Visit the source
Other answers
MVC is a design pattern. While it has nothing to do with how scalable your application is, using a framework (such as Yii) usually means you have much less things to worry about than someone not handling their database connection well. Scaling means to make your application's database layer able to handle multiple requests at a time. The more you can handle, the more scalable your application is. As an example, in Facebook, millions might be liking and commenting at once, which means lots of SELECT and INSERT queries are being run all at once. A scalable application is one that allows you to do various scaling methods (sharding for example) without the need to modify your application, because the underlying framework already supports it, or because you have specifically written such a code.
Parham Doustdar
I know some people might call me a pedant, but I would say there was a difference between architecting your "infrastructure" (as the question asks) to support scaling and architecting your application to support scaling. Architecting your application would be making smart / efficient coding and database query optimization. Architecting your architecture would be things like optimizing your storage (using appropriate storage, optimizing the path to storage, filesystem tuning) to remove bottlenecks, tuning databases, smart use of reverse proxies and caching, clustering your databases, use of (or at least planning around the use of) load balancers, and related concepts. It is an ambiguous question in that its specific meaning is dependent largely on what exactly the application is doing, but I think I've outlined the theme to any correct answer.
Christopher MacTaggart
First off lets get some concepts cleared out. Performance issues: when your application is slow for a single user. Scalability issues: when your application is fast enough for a single user, but slows down when many users use it at the same time. Scaling up(vertically): when you add more resources to your application servers, eg. more CPU, memory, etc. Scalling out(horizontally): when you add more nodes to the system, eg. adding more servers If your application can accomodate growth by either scaling up or out, then you have a "scalable system". To answer the last part of your question, using MVC design pattern is directly related to the problem of scalability, it just makes your life as a developer lot easier. Using MVC frameworks like Laravel, CodeIgniter, Yii, etc. is beneficial because they provide a good database abstraction layer and also internally implement efficient handling of database connections, sessions and caching. How do you make your application scale ? There are a lot of things to it. You will have to take particular care while designing your application, database and infrastructure. These things are application and design specific. has provided a brilliant answer and covered most of the general points. A quick search will also get you lots of resources you can refer to.
Dhruv Hari Baldawa
Some more points.. 1. Keep your architecture simple. Don't add/use things which generate complexity. It'll give you more grip for rapid development & easy handling. 2. Try to use loose coupling technique. Ref google for advantages of " loose coupling technique". 3. Use standard practices(design patterns, OOP's) for writing efficient codes.
Suresh Kumar Majhi
Efficient Coding . Less queries . Efficient Database design .
Challa Pradyumna
To me sounds like a boss is trying to protect their app from future over-success ;-) Allow me to offer a rather different answer: It means you can build your app in a way that is easier to scale in the future as opposed to building your app in a way that is harder to scale. This is not limited to Scaling though and one can say an app is built in a way that is easy to expand, make more secure, go mobile etc etc as opposed to an app that is built in such a way that makes it hard to got in any of the above directions. Now how exactly do we make a PHP/MySQL app that is easy to scale in the future ? Though it is possible to give some exact answers to that question, yet judging from your original question and my impression of your understanding of MVC and stuff, I would tell you this (the Agile way, by the way, so no classical "Architecture" is involved): You should follow the very basic guidelines and best practices and just code the best way you can and don't think about Scalability yet. Just basic code quality stuff: Pick up a framework that makes it easy for you to code. Almost all of them are MVC so don't worry about it. We are using Laravel. Yii and Symphony are great too. Symphony is the Enterprise one but it is also the most complicated. Don't pick Drupal or Wordpress or any of the less OOP frameworks. Why? books could be composed to answer that but in short the OOP paradigm would in the long run serve you better in your goal of being Scalable (and in many other ways). Most certainly use TDD. The de-facto unit testing library for PHP is PHPUnit and all the frameworks above has integrations with it. Learn about Normal Forms and good database design. Make sure you understand the surrounding stuff: Primary Keys, Foreign Keys, Relations, Integrity, Anomalies etc etc. Not a deep, academic understanding. A good guts understanding is enough. Also it serves well to learn ERD so you can better express your thoughts. Learn about de-normalizations and why they come handy (this is important actually) Finally wrap your head around actual Scalability and Performance concepts: Profiling, Response-Time, Throughput, Concurrency (in the relevant contexts), Horizontal vs Vertical scaling. Load Balancing etc etc. Begin with Performance and then make your way towards Scalability. You ought not to do that in that particular order though. Do the above and you will figure out the rest.
Ashkan kh. Nazary
Related Q & A:
- What does it mean when a patent fee status has lapsed?Best solution by info.legalzoom.com
- What are the points for and why do you lose them when you ask a question?Best solution by Yahoo! Answers
- What does per. mean on a job application?Best solution by Yahoo! Answers
- What does this mean on a job application?Best solution by Yahoo! Answers
- What to say when calling about a job application status?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.