How much can you spend on maintaining your own Mastodon server on AWS

Short description

An AWS Solutions Architect has detailed how they hosted their own single-user Mastodon server on AWS for about a month, along with the cost of the project. While stating that the project is not a guide to managing a server in a production environment with thousands of users, the project cost $52.74, with $32 spent on the first day of domain name registration. The architecture uses one instance of Elastic Compute Cloud (EC2) t4g.small, PostgresSQL database and Redis, Amazon Simple Storage Service (S3) for storage, and Amazon CloudFront for delivery, with other services used for monitoring, studying accounts and backups.

How much can you spend on maintaining your own Mastodon server on AWS

I hosted my own single-user Mastodon server on AWS for about a month. In this article, I will tell you how much it cost me.

Preface:

First, I need to say a few words. First, I work for AWS as a Solutions Architect. However, since this is my personal project, I ran it on my own AWS account, which I pay for without employee discounts and special terms. All my ideas and views in creating this project are my own and do not necessarily reflect the recommendations and instructions of my employer.

Additionally, I embarked on this project to achieve several goals. First, I just wanted to learn about Mastodon and how to set up a small custom single-user instance of it. This article is not a guide to managing a server in a production environment with thousands of users. It’s just my hobby. However, I know a lot of people are interested in this kind of thing, so I hope the information is useful.

Finally, there are several hosting providers that will set up and manage your own Mastodon server for a fee. But this is completely different. My experiment will be complex and confusing, I will try to follow my own path and change the route as I see fit. If you just want to host your own server, hosting providers might be the best place to start!


▍ Architecture

I already wrote

several posts

about setting up Mastodon and why he settled on the architecture he chose. Since then, some things have changed, but in general the architecture has remained unchanged.

  1. For compute – one instance of Elastic Compute Cloud (EC2) t4g.smallwhich runs Mastodon, its PostgresSQL database and Redis.
  2. I switched from static images to Amazon Simple Storage Service (S3) for storage, and I use Amazon CloudFront for delivery.
  3. Within AWS, I use a lot of other small services for monitoring, studying my accounts, and backups.

▍ Expenses

At the time of writing, $52.74 has been spent on the project. As you can see in the graph below, $32 of that amount was spent on the first day of domain name registration

micah.social

. In my opinion, this is expensive for a domain name, but I really wanted to show it off.

If you deduct the domain name registrar fee (which will have to be paid annually), I spent $20.74 on additional AWS services beyond the free plan and free trials.

▍ No compute costs until 2024

Here it is important to remember that you will have to spend money on the computer as well. Although in fact it is not so at all. You see a small spike in compute costs on the first day when I experimented with a different instance type, but overall I haven’t spent anything on compute yet. This is with the fact that the instance type I selected

Graviton2 ARM is based on t4g.small

has

free trial until the end of 2023

when used up to 750 hours per month. This means that once 2023 is complete, my instance will be billed hourly. When that happens, I have two options:

  1. I can start paying an hourly On-Demand rate of $0.0168 per hour, which is about $12.26 per month
  2. I can buy a Compute or EC2 Instance Savings Plan. I guess I will do that. The three-year EC2 Instance Savings Plan with full upfront cost is $165.56, which is $4.60 per month. This will allow me to use it with another instance type in the same family if I decide to upgrade to t4g.medium.

▍ Oops, CloudWatch costs!

You may have noticed the spike in spending in the middle of the graph above. In his

post about monitoring

I said I installed the Amazon CloudWatch Agent on the instance to monitor key metrics. However, I wasn’t able to filter out all the metrics I didn’t need, so it turned out that CloudWatch is sending a full data packet, which is quite expensive. As soon as I realized this, I disconnected the agent. After dealing with it, I went back to it and added the correct filter configuration.

▍ EBS Snapshots

This is a detailed schedule of EBS Snapshots storage costs. It has been increasing for a month, but based on my backup schedule I expect it to level off.

When I started this project, I was looking for an easy way to back up data on my EC2 instance. I wanted something easy to set up and manage, so I decided to go with EBS Snapshots. I’m aware that there are other, potentially cheaper ways to do this. My main concern was creating backups for data stored in PostgresSQL. All static resources are now stored in S3, so only the codebase, configurations and database reside on the server.

However, my snapshot schedule is a bit excessive for this project. I now create hourly, daily and monthly snapshots. Hourly snapshots are disposed of after 24 hours, daily snapshots after 30 days, and monthly snapshots are retained for approximately two years. Also, I back up the entire volume, and even with incremental backups, the volume can grow quite quickly due to data that I most likely don’t need.

It would be better to just make backups of the PostgresSQL database itself with a similar schedule and with proper database locking, but that is a project for the future.

▍ Elephant S3

The most significant costs currently comparable to EBS Snapshots costs are S3 costs. And they are the most difficult to deal with, but I will try!

Here are some notes on my S3 setup:

  1. Mastodon not only stores your own uploaded static assets, but also assets for all accounts and labels you’re subscribed to. It’s not entirely clear to me when it decides to make copies of them, but that’s likely the source of the largest amount of data stored.
  2. There are settings in Mastodon’s settings to limit these cached resources, but I haven’t turned them on yet because I was curious to know what data volumes we’re talking about. Currently, they are approximately 180 GB.
  3. As for storage itself, Mastodon loads resources using the S3 Standard tier. I haven’t found a way to change this, but I’ve filed an issue saying that it would be nice to add a configuration option. This would allow me to load resources directly into Intelligent-Tiering, which makes more sense to me.
  4. I set up a Lifecycle Policy to move all my S3 Intelligent Tiering data every other day. It’s a bit of a controversial decision, so I’ll have to wait and see how it turns out. S3 Intelligent-Tiering should automatically move my data from one tier to another based on access patterns. However, it does not count objects smaller than 128 KB and incurs a small data monitoring fee. To understand whether it justifies itself, it takes a few months.
  5. The hidden cost of Mastodon’s data storage on S3 is Requests. So many requests! I watch forty-fifty thousand requests a day! These are mainly PUT requests, and less than two thousand GET requests are made every day. At first this surprised me, but after understanding how Mastodon works, I realized that it makes sense. I think a lot of this has to do with how I set up Relay and the number of accounts and tags I’m subscribed to, but it’s definitely something to keep an eye on and look into. So far, I’ve set up Amazon S3 Storage Lens with advanced configuration, allowing me to easily explore aspects of my data activity in S3.

In total, my S3 storage costs for the first 30 days were $9. It’s a little more than I expected, and it seems to me that there are probably opportunities to lower those costs in the coming months. I transfer all my resources through

Amazon CloudFront

that has

generous free rate

which has cost me nothing so far.

▍ Budgets and unexpected expenses

In the future, I plan to control everything with help

AWS Budgets

.

If you’re running your own Mastodon server on AWS (or anything on AWS, for that matter), do yourself a favor and consider AWS Budgets by customizing it for yourself. There you can set different thresholds for sending email alerts if you exceed your monthly budget. My setup is pretty simple. I set a budget of $50 per month with a 50% alert ($25) so that as soon as I spend $25 I get an email alert.

Actually, it’s a bit more wasteful than I’d like. Ideally, I’d like the cost to be less than $20 (and it will be for this year because I’m on a free plan for my server for now). This can be done by reducing S3 data storage and reducing the number of EBS Snapshots or changing the way they are created. But for now, I’ll leave things as they are for a few months to get more data to analyze before making any further changes.

In an ideal world, it would be great if the total cost of all of this didn’t exceed $25 a month. It’s not much more expensive than Twitter Blue!

Telegram channel with prize draws, IT news and posts about retro games 🕹️

Related posts