For many years, I considered all talk about scale to be irrelevant. If you throw enough money at it, any web stack can scale to handle more traffic.
With an abundance of free investor money, I've always believed that startups should choose the stack that allows them to move faster and further.
As focus shifted to profitability in the recent year or two, cost control has become an important concern.
PHP is my favorite programming language, but it blocks execution threads and network connections (DB, HTTP, Cache, etc.). Should we abandon PHP? NO! is my answer! Why should development speed be sacrificed for cost control? Why not have it both ways?
I placed a bet on PHP and added GoLang to the stack and the results exceeded my expectations.
Here's a look at my current stack (for cost control):
1. All web clients talk to a load balancer.
2. The load balancer handles SSL & routes most requests to the PHP monolith.
3. Requests to endpoints that receive high traffic & perform many I/O operations are routed to a Go web server.
4. The PHP monolith & Go server dispatch tasks to the queue & read/write from/to database & cache clusters.
5. A separate Go program handles background jobs (from the queue) and periodic tasks (scheduled).
What do I get from Go?
- Handlers waiting for I/O operations yield to the runtime so others can run.
- I can handle concurrent workloads without having to start new worker processes. Which translates to less memory consumption.
- Network connections are kept alive & re-used.
- Database connections are put back for reuse once the query finishes. They aren't kept hostage until a response is sent.
What do I get by keeping PHP?
The tooling available in the ecosystem (& Laravel in specific) is lightyears ahead. It allows developers to get things done faster by spending their time adding functionality rather than re-inventing the wheel.
Should you switch to this stack?
Are you struggling with compute infrastructure cost at the moment? If the answer is no, stick with PHP. It'll help you move faster, add value, onboard more customers, and hopefully get crazy traffic so you start having infrastructure cost concerns :) That's a nice problem to have, specially that solutions are available.