---
title: "How to self-host Mastodon"
description: "Self-hosting a Mastodon instance on Fly.io comes down to a starter repo, a Dockerfile and two Fly config files: one runs the database setup, the other deploys the app."
url: "https://swe.quest/articles/how-to-self-host-mastodon-a9419721506c8665"
canonical: "https://neon.com/blog/self-host-mastodon"
source: "Neon"
published: "2023-01-26"
difficulty: "medium"
kind: "How-to"
reading_minutes: 8
tags: ["deployment","postgres","ruby","cloud"]
---

# How to self-host Mastodon

A post on [Neon](https://swe.quest/sources/neon.md), published 2023-01-26, 8 min read, How-to. Original: [https://neon.com/blog/self-host-mastodon](https://neon.com/blog/self-host-mastodon)

## Summary

Self-hosting a Mastodon instance on Fly.io comes down to a starter repo, a Dockerfile and two Fly config files: one runs the database setup, the other deploys the app. The guide covers Mastodon's architecture (Rails, Sidekiq, Node streaming server, Redis, Postgres, optional Elasticsearch and S3), generating app and VAPID secrets with rake, and provisioning managed services: Neon Postgres for scale-to-zero pricing, Upstash Redis and Postmark SMTP. A notable gotcha is passing the Neon project ID inside the password string, because the image's database client lacks TLS SNI support.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Deployment](https://swe.quest/tags/deployment.md) (Reliability & operations)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Ruby](https://swe.quest/tags/ruby.md) (Languages)
- [Cloud platforms](https://swe.quest/tags/cloud.md) (Infrastructure)

## Prerequisites

- command line basics
- Docker basics ([easy posts on Containers](https://swe.quest/tags/containers.md?difficulty=easy))

## Keywords

Mastodon, Fly.io, Neon, ActivityPub, Upstash, Postmark, Redis, AWS S3

## Related posts

- [Deploy a Dart App on Railway, Part 1](https://swe.quest/articles/deploy-a-dart-app-on-railway-part-1-9c43a3141edcb7ac.md): Railway · 2024-12-13 · Medium · 7 min read · Deployment, Containers, Cloud platforms, PostgreSQL
  A Flutter + Serverpod trivia app is deployed to Railway with a Railway-hosted PostgreSQL database, using the Railway CLI and a custom multi-stage Dockerfile that compiles the Dart server and bundles a Flutter web build into Serverpod's static webserver.
- [Fly Postgres, managed by Supabase](https://swe.quest/articles/fly-postgres-managed-by-supabase-c2ddce21256b3097.md): Supabase · 2023-12-15 · Easy · 4 min read · PostgreSQL, Cloud platforms, Replication, Virtualization
  Supabase and Fly.io launched Fly Postgres, a managed Postgres running on Fly Machines (Firecracker VMs) with Supabase features like Supavisor pooling, pgvector, PITR, branching and auto-generated REST/GraphQL APIs; the offering has since been deprecated.
- [Getting started with Ruby on Rails and Postgres on Supabase](https://swe.quest/articles/getting-started-with-ruby-on-rails-and-postgres-on-supabase-03d6ca4747754aea.md): Supabase · 2024-01-29 · Medium · 3 min read · Ruby, PostgreSQL, Deployment
  A Rails app can be wired to a Supabase-hosted Postgres database by scaffolding with \`rails new -d=postgresql\` and supplying the Supabase pooler connection URI through the \`DATABASE\_URL\` environment variable.
- [Deploy Authorizer on Railway](https://swe.quest/articles/deploy-authorizer-on-railway-6b6e28c962bd461a.md): Railway · 2022-01-28 · Medium · 3 min read · Identity & auth, React, Deployment
  Authorizer, an open-source self-hosted alternative to Auth0, can be deployed on Railway with a one-click template that provisions PostgreSQL and Redis automatically and wires up DATABASE\_URL and REDIS\_URL.
- [How Cedalio uses Neon for an efficient development workflow](https://swe.quest/articles/how-cedalio-uses-neon-for-an-efficient-development-workflow-265835e6a16f5a00.md): Neon · 2024-05-29 · Easy · 5 min read · PostgreSQL, CI/CD, Multi-tenancy, Serverless
  Cedalio, an ESG data verification startup, moved from DynamoDB to Postgres and picked Neon over RDS for a simpler API and console.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
