On Costs
As I was drafting a post in my head about the storage schemas and architecture used in Orphyx and Legion I realized I would first have to talk about cloud costs. A lot of the constraints on the schema are informed by the infrastructure we chose to use. This is not meant to be exhaustive or definitive. It is definitely biased by my own prior experience with various solutions. I’ve probably missed cost savings, and if you know of any please DM me in Discord: https://discord.com/users/1025270667970609182
There are primarily three things I am optimizing for:
- Monthly dollar cost of running the bots
- Time cost of maintaining the solution.
- Time cost to implement the solutions. This is incurred once.
From a technical point of view : I will seek to make reasonable choices between cost and reducing bot latency to respond to users. This, for example, may inform choices between using a VM or using Lambdas as the main way of interacting with Discord. The VM has much more predictable latency. The details of that are probably a different post.
I will not seek to make my solution infinitely scalable. We have a small number of users, so I can do things like hold all of them in memory easily if I need to and not feel guilty about it.
Things like Disaster Recovery are, however, important to me.
Ok, so breaking it down, we have the usual suspects:
- Compute cost of a background worker. Example is the bot responding to Discord events.
- Cost of hosting a front end
- Cost of storage.
There are other costs, like domain hosting, but there’s very little if any interaction with the code and tech choices which is why the post is focussed on cloud provider prices.
Finally, I will ignore any free-trial options or credits. I want to know what I will be paying per month in the steady state.
Baseline VM
So first, you can get both a front end and storage for $5 a month by getting a VM from Linode or Digital Ocean. That’s for 1GB and 1 shared CPU. Then put a web server and mysql on it. There are some drawbacks here: You are responsible for backup and disaster recovery. (Something we’ve already had to deal with once). It’s up to you to make sure you can rebuild the VM and not have lost any data. We do use this to host our alliance’s credit system, and it’s already pushing the resource limits of one cheap node despite not having anything complex in what it does. And interestingly, hosting the SQL and site on the same site led to some questionable design shortcuts which made it harder to extend the solution. This wasn’t my choice (we inherited the solution), but it was an observation I wanted to note.
You can get similar offers free from Google or Oracle. The 0$ to $5 options are a good baseline to compare against.
Front End
Both Google and Azure have free web hosting:
https://azure.microsoft.com/en-us/pricing/details/app-service/linux/#pricing https://cloud.google.com/free/docs/free-cloud-features#app-engine
While it is also free, the real win for me here is the potential of less maintenance, I don’t need to manage the VM in any way.
This only saves money if I have a place to get storage for $5 or less.
Storage
SQL
The basic SQL options exist in AWS, Azure, and GCP. The lowest I could estimate was probably $7 a month.
Cosmos
There’s a free tier of Cosmos now. Legion actually uses Cosmos DB. It pre-dates the free tier and I will have to move all the data to take advantage of this (kind of annoyed by this actually). A future blog post, maybe. Here’s the free tier: https://learn.microsoft.com/en-us/azure/cosmos-db/free-tier#best-practices-to-keep-your-account-free
I do have some reservations here as I’m not confident that Legion and Orphyx will predictably stay in the RU limit. But it is actually a very tempting offer because it is also easy to code against since it has something that SQL has, but the next option lacks: Secondary Indexes.
NoSql
Finally, there’s the NoSQL stores. Dynamo, Azure Table and Firestore or other equivalents. Orphyx is actually currently on this. And it runs me $0.01 a month right now. Google and AWS would have similarly priced (free) solutions. The major disadvantage is that without features of SQL that even Cosmos has there are some extra design constraints to navigate that often result in extra code you have to carefully write. And that will absolutely be the topic of future posts.
Summary
Currently where we are at is that we have one lineode for $5, and actually one Windows Azure VM with a reservation to bring it to $11 a month. The linode should eventually melt away into a free front end option and one of the storage options. Legion uses Cosmos, and Orphyx uses table storage. After moving Legion to the free tier of Cosmos or moving Legion to a NoSQL option the price of that will also be in range of a few cents a month. Maintenance costs and single points of failure (a VM) are minimized.