Most startups' and indie hackers' web apps can run on DigitalOcean's $6 VPS. It's inexpensive, dependable, and effective. There are numerous other cloud providers with comparable pricing.
You can test the market and gauge demand for your app on that VPS. Resize the VPS for more CPU power, memory, and disk storage once you've found a product-market fit.
But let's be real. Not all apps find a product-market fit. Most apps are shut down long before the need to scale the servers that run them arises.
If you're experimenting with a new app idea, do yourself (and your wallet) a favor and start with a six-dollar VPS and build your app with a mature and portable stack that can run anywhere.
By portable, I mean that you can easily move your app and data to any other cloud provider of your choice. Allow pricing competition among cloud providers to work in your favor. Don't tie yourself to a vendor just because you can't run your app anywhere else.
Assuming you've decided to use a PHP stack, this post will show you what you get for $6 per month on a VPS.
To get PHP to work on an Ubuntu 22.04 LTS VPS, you need to install the following:
Nginx is a web server that will handle incoming requests and forwared them to your PHP application.
PHP-FPM is a process manager for PHP, it starts a number of processes to handle incoming requests from Nginx.
Composer is a package manager for PHP. All modern PHP applications use Composer to install packages and libraries they depend on.
Installing all these libraries is straightforward:
apt update apt install -y nginx zip unzip php8.1-fpm php8.1-zip php8.1-mbstring php8.1-curl curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer
Apt is an Ubuntu package manager. It will be used to install libraries on your VPS. We used it to set up Nginx, a few composer dependencies, and a few PHP extensions.
You now have everything you need to run a modern PHP application. This is not a comprehensive tutorial. I just wanted to show you the PHP dependencies.
What you get
FPM will handle requests with 5 web workers by default. That means the server can handle up to 5 concurrent requests.
If we assume that the average request processing time is 100 milliseconds, your server will be able to handle 50 requests per second. If it's bombarded with traffic all day, that's 4,320,000 requests per day.
If your app interacts with external services, the average processing time per request may rise to 5 seconds (extremely slow, I'm exaggerating here), implying that the server will handle 86,400 requests per day. Still a lot, but other requests will queue up and appear slow to your customers during a 5 second window, some of these requests may be dropped as well.
I have a code that processes over 500,000 orders per month for a client on a nine-year-old machine with one CPU core and one gigabyte of memory. Ten web workers are active on the server.
The CRON scheduler is also installed by default on that VPS. It enables you to run background commands on a regular basis.
To increase capacity, configure FPM to handle more concurrent requests, which will consume more memory and CPU. You can gradually increase the number of FPM workers while monitoring your server's resource consumption until you find the sweet spot.
You can also optimize your app to process requests more quickly. This could imply improved indexing for DB records, resulting in faster queries. It could also imply delegating some tasks to a background process. As a result, your web workers will respond more quickly while the work is being done in the background.
Running background jobs can be configured using a library named "Supervisor". You can install it with apt:
apt install -y supervisor
Finally, if your app is 100% optimized and the server reached maximum capacity and you still want more. You can install the Swoole PHP extension (or it's fork Open Swoole).
PHP will be run in shared memory mode as a result of this extension. That is, your application will only be loaded into process memory once, and the same instance will handle all incoming requests. When compared to PHP FPM, this saves a few milliseconds.
What about the Edge
Having a single VPS in a single region of a cloud provider speeds up requests for users who are physically closer to that region. Because they are so close to the VPS, their requests will arrive faster. And the VPS response will reach them faster as well.
As a result, some businesses and cloud providers coined the term "Edge Computing." They distribute your compute workload across multiple regions around the world so that more users can interact with it more quickly.
But, as much as I hate to be the bearer of bad news, "Edge Computing" is a marketing term used by companies trying to sell you a solution to a problem you don't have. Milliseconds of latency will not have a significant impact on customer acquisition.
Once your product is profitable, consider reducing milliseconds of networking latency here and there. You can deploy your app on multiple servers across the globe and serve the fastest app ever.
Edge computing is used at the scale of Google, Amazon, and Netflix. Are you there yet? Probably not.
What about the database
Here you go:
apt install -y mysql-server
You have a MySQL database running on your VPS. Communication between your app and the database will be super fast because they live on the same machine.
You can use the CRON scheduler to create a backup of your database on a regular basis and save it somewhere safe. If anything goes wrong (or if you want to move to a different VPS), simply restore the backup and you're back up and running.
Check Pieter Levels? He is an indie maker, probably the most popular one.
At one point, he hosted all his creations on a single VPS:
I pay $40/m for a Linode with 4 GB RAM, 4 CPU cores, 96 GB SSD storage and 4TB transfer i/o. To give you an idea, every time one of my sites gets press or is featured on Hacker News or Product Hunt, it’ll get flooded with users (often >1000 concurrent users per second). It’s never went down yet either, except for the cases when I broke it myself.
And in another tweet he explains:
That single Linode VPS takes 50,000,000+ requests per month for NomadList, Remote Ok and all my other sites. This isn't a lot by the way, a VPS can take way more than that. An optimized VPS can handle 2,000+ reqs/second, or ~250,000,000+ requests per month easily
The bottleneck is usually not your server (NGINX, Apache etc) but your code executor that runs your JS, PHP, Ruby code etc. A lot of the strain on that can be avoided by aggressively caching by generating static files for most non-dynamic pages and keep dynamic pages to a min.
Consider how much money you could make if your app received 50,000,000 or more requests per month. All while shelling out $40 per month for infrastructure.
Try the $6 VPS and see for yourself. It's a perfect place to start if you're in the early stage of building an internet business. And if you don't want to handle the server setup yourself, there are many services that can help you. There's Forge, Ploi, Cloud Ways and many more.
If you plan on going big from the start, or if you're already big, invest more to get a VPS that works for you. Alternatively, multiple VPSs can be used to increase redundancy.
When you start with a $6 VPS, the scalability options are limitless.
I'm Mohamed Said. I work with companies and teams all over the world to build and scale web applications in the cloud. Find me on twitter @themsaid.