
Introduction: What is n-tier architecture?
When people talk about ān-tier architecture,ā theyāre describing a way of splitting an app into layers (or ātiersā) that each have a specific job. The ānā just means there could be two, three, or more tiers depending on how you slice things.Defining tiers
- Presentation tier: the UI/frontend of your app ā HTML/CSS/JS in a browser, or a mobile app interface ā that the user interacts with
- Web tier: the app servers/backend that handle requests and run business logic
- Data tier: stores, manages and provides access to application data
N-Tier Examples
Two tiers
web app + database. This is the most common case on Fly.io: your app servers run on Fly Machines and connect to a shared Postgres cluster.Three tiers
frontend + backend + database. Youāll see this if you have a separate frontend (like a React SPA served from a CDN, or a mobile app) that talks to your Fly backend.Mapping to Fly.io
- Web tier ā your app running on Fly Machines
- Data tier ā Fly Managed Postgres (our hosted Postgres that handles the messy parts for you)
- Optional presentation tier ā a separate frontend app (web or mobile) that talks to your Fly backend
Why use n-tier on Fly.io?
- Scale with one command: Add more Web/App machines whenever traffic spikes.
- Keep requests flowing: Flyās proxy automatically balances load across your Machines.
- Let the database do its job: With Managed Postgres, you donāt need to worry about setup, backups, or failover.
Quickstart: Deploying a n-Tier App
Letās spin up a simple n-tier setup.1. Launch your app
First, deploy your app to Fly:2. Add a database (Managed Postgres)
Now create your data tier with Fly Managed Postgres:- Provision a new Postgres cluster in the same region as your app to keep latency to a minimum (though you can choose another region).
- Configure monitoring, daily backups, and automatic failover.
flyctl:
DATABASE_URL from the environment. Once set, your app is ready to talk to Postgres.
More details on creating and connecting a managed Postgres database can be found here.
3. Scale out your web tier
If traffic grows, add more Machines:Finishing up
At this point youāve got:- Optional presentation tier: a separate frontend app, if you use one (delivered to browsers or devices)
- Web tier: Fly Machines running your app (stateless and load balanced)
- Data tier: Fly Managed Postgres
Related reading
- Explore the features of Fly Managed Postgres
- Find out how to scale apps on Fly
- Read about Fly networking
- Learn more about n-tier architecture