>_
Dating App theory part 3 - VPS
This is the third part in a random series of posts Im writing about a dating app I would create, but wont. In the last
post we established our requirements for the app in terms of data storage and bandwidth. We will now start to look at the different infrastructure we could use for implementation within a £50 per month budget. Starting in this part with a VPS implementation.
As a quick overview of what we need, we have these data requirements as copied from the previous part:
- 300Gb bandwidth per month
- 450Mb photo/file storage per month
- 200Mb data storage per month
With these smaller levels of requirements Im quite convinced we could do all of this with just one server. Just to maths this up a bit more, with our 10Gb of bandwidth a day, lets say each request is 50Kb each time, this gives us:
10,000,000(Kb) / 50Kb = 200000 requests per day
200,000 / (12 * 60) = 277 requests per minute
277 / 60 = 4.6 requests per second
To note the 12 * 60 is 12 hours per day as we only allow access between midday and midnight. This is not much traffic at all, obviously traffic doesnt come in at a steady pace, but still this is not a large scale of traffic. Also remember this is if the app was at maximum capacity with maximum usage. With this in mind, this could definitely be achieved with a single bulky server.
This is ofcourse our simplest of implementations, as we dont need to stitch together different services. Aiming for simple, I would most likely use what I know best which is Python/Django, but would prefer say Golang or Elixir if I was experimenting. I would prefer to use SQLite and think it would fit fine, but again keeping it simple I would use Postgres with Django.
Fly.io
A while ago I read
this jvns article about an nginx playground app. They used a small instance with fly.io thats 1 shared CPU and 256MB RAM with the frontend served on a CDN. They were seeing just 400ms per request and while it wasnt over complex and had no database interaction, it wasnt entirely simple. So the first host I would like to look at is
Fly.
Ignoring any freebies we get, a shared single CPU and 2GB RAM would cost $10.70 a month with fly.io. I cant be too sure but I think this would be enough to serve our traffic and generate our matches in the off time. Not least because the next option for fly.io at time of writing would jump to $31 and get us 1 dedicated CPU with the same amount of RAM.
Fly is more aimed at deploying app servers close to users (it says so on the frontpage) and I think this is probably reflected in the pricing. I think it could be argued that this instance would be enough for our 10,000 users and deployed nearest those users (London most likely). Then expansion would mean more of these smaller instances. I would also setup a seperate instance to serve images/files, running nginx. This would just be the smaller instance for $3.19 a month, with 512MB RAM.
We also need our postgres database which I think would need to run seperately. You can actually get a single node with 3GB volume for free. So this would be fine for our usage as we only need ~200MB of data storage a month.
With Fly pricing storage and outbound data costs are seperated. We only require 450MB of data storage and this comes within fly's 3GB free tier. While inbound data is free, outbound (egress) is free for the first 100GB within Europe and then 2 cents per GB afterwards. Therefore for our 300GB requirement, we will need to pay for 200GB of egress which would be 0.02 x 200 = $4.
- compute: 1 Shared CPU, 2GB RAM - $10.70
- photos: 1 Shared CPU, 512MB - $3.19
- database: 1 node, 3GB Storage - Free
- data: 450MB - Free
- network: 100GB free, 200GB - $4
Total: $17.89
There is a possibility here to use a beefier server instead of two seperate. But as mentioned before the next jump up is to $31 which almost doubles this total. But because the database is seperated, there is a possibility to instead just add more smaller servers. So with that in mind lets also add:
- compute: 1 Shared CPU, 512MB - $3.19
New Total: $21.08
While there is a non-zero amount of complexity to adding this server, it looks like Fly allows for easy
autoscaling. So this additional server should not increase complexity by much.
When Ive looked at Fly before I just always think how can I use just the free parts. But coming in with a budget and an idea of what I need, I think this is really cheap. This does consider the postgres instance free too, which I think would maybe add on ~$3 if it was no longer free, but still its cheap even with that expense added on. The only unanswered question here is could this setup handle the 4/5 requests a second that we would need. Anyway, our total for 2 app servers, 1 media server, a database server and egress is $21.08 which is (currently) less than £20. Less than half of our budget.
Render
I never used Heroku, I always thought it was a bit expensive. Anyway, an alternative is
Render. Although Im looking at Cloudflare next time, I just wanted to get an idea of a Heroku alternative costs.
- Services Starter Plus, 1 CPU, 1GB RAM - $15
- PostgreSQL Starter, Shared CPU, 1GB RAM, 1GB SSD - $7
- Cron Starter, 0.5 CPU, 512MB RAM, 0.016/min - $5
- Egress, 100GB free, 200GBx0.10 - $20
Total - $47
Honestly I didnt do this to dunk on Render. So this assumes again that 1CPU and 1GB RAM is enough for our traffic. Also the Cron calculation is on the basis that we would have a single task that runs every day that sets up our potential matches ready for the afternoon and this task runs for an average of 10 minutes per day so 300 minutes per month.
Again I went into this pricing with no idea of what it would be, but I did know that Heroku's first non-free tier is around $7 so I knew that atleast. But yes this wouldnt be considered an option unless the whole setup for the app is very obviously simple. The advantage with this and Heroku is supposed to be simplicity, but this looks to come with a price.
Linode
I didnt mean to set a baseline with the Fly.io estimation, or to show pricing compared to just normal VPSs. Anyway, here is an idea of what $20 could get us with Linode.
- 4GB RAM, 2 Shared CPUs, 80GB Storage, 4TB egress
So we could host everything off this one server, but that may be risky plus overkill for what we need. Another setup may be:
- server: 2GB RAM, 1 Shared CPU, 50GB Storage, 2TB egress - $10
- backups - $2.50
Total - $12.50
We still have no redundancy here, if our server went down then we are stuffed. An alternative may be to use an even smaller server and then have a backup, but this adds complexity. Instead I think this is probably an okay setup for what we need, especially as we have backups too. Worth noting too the budget then allows for a smaller server to be used as a testing environment.
Also in regard to downtime, we havent accounted for this in the other estimations, so we can assume this is a perfect world with no downtime, however in this case we have a backup of our server. Im sure that Fly and Render have some form of guarantee that data is not lost.
One final suggestion here may be:
- server 1: 1GB, 1 Shared CPU, 1GB RAM, 25GB Storage, 1TB egress - $5
- server 2: 1GB, 1 Shared CPU, 1GB RAM, 25GB Storage, 1TB egress - $5
- Managed DB: 1GB, 1 Shared CPU, 1GB RAM, 25GB Storage - $15
- NodeBalancer (Load balancer) - $10
Total - $35
So this is with two servers and a load balancer and then a managed database. Obviously we could manage our own database and this would save $10, but this is more inline with what you would get with Fly or Render as they are managed databases as far as I can see. Personally I would go with the $12.50 option and scale up as needed, but I think its fair to highlight here what you would need to spend with Linode to get a similar offering to Render and Fly.
Hetzner
Finally, lets see what we could get from Hetzner. Hetzner operates in euros, so we are closer to the GBP budget that we have. If we were to use the majority of the budget we could go for this:
- AX41-NVME: 64GB RAM, 2x512GB Storage, 6 CPUs (Ryzen5 3600) - 48.91 euros
I couldnt find the euro symbol on my keyboard by the way. Theres a 46 euro setup fee with this. Spread across a year this would take us to 52.75 euros, which maybe with conversion would take us to our £50 budget.
This is alot more power than we probably need, so heres a more conservative setup:
- 4 Shared CPUs, 16GB RAM, 160GB Storage, 20TB egress - 20.71 euros
OR
- 2 Shared CPU, 8GB RAM, 160GB Storage, 20TB egress - 16.18 euros
Again, more than we need with the first option, so I would go with the second option. Its worth noting a couple of things here, firstly these servers are in Germany, so they may add on some latency. I wouldnt say alot, but certainly more than a server that is UK based. Also, I know this is anecdotal but I hear that theres a risk with Hetzner that they pause or delete your server and ask for identification. But this may be a minor put off.
There also doesnt look to be any options for backup, this may be configurable somewhere though. This is a very cheap price, I suppose we could also add a smaller server for backups. The downside here is that everything needs setting up manually, whereas even Linode offers cheap managed backups. But with such a gap in budget, adding more servers would not be a problem.
Conclusion
Overall we have the following:
- Fly.io - $21.80
- Render - $47
- Linode - $12.50
- Hetzner - 16.18 euros
I think after considering the relatively low requirements of the project, if I was going to go experimental I would go with something like Golang and SQLite, keeping it all working on a small $5 linode server and scaling up as required. Theres an argument with this setup between it being complex or simple. Anyway back to reality.
So we can say with a VPS setup we have an average of 10 to 20 dollars for system specifications that should cover our requirements. I havent looked at the other non-VPS options yet but I should disclose that I would be mostly in favour of a single server setup. I think the cost trumps the risk of losing it all, plus the low cost allows for backup solutions.
Next we shall look at Cloudflare.
7 Nov 2022, 12:17 p.m.
Home