← Back to Blog
SaaSSelf-HostingInfrastructure

Self-Hosting Your SaaS: Complete Infrastructure Guide

Running your SaaS on managed cloud platforms means paying 3–10x more than the hardware costs. Vercel, Railway, and Render make deploys easy, but the bills scale faster than your revenue. Self-hosting on bare metal gives you full control, predictable costs, and the performance your users expect.

Why Self-Host Your SaaS

Cost Control

Managed platforms charge per seat, per resource, and per GB of bandwidth. A typical SaaS stack on Render — web server, database, Redis, background workers — costs $200–$500/mo before you hit real traffic. The same stack on a single RAW bare metal server costs $6–$21/mo depending on your resource needs.

At $5k MRR, infrastructure should be under 5% of revenue. Managed platforms push that to 10–15%. Self-hosting keeps it under 2%.

Data Sovereignty and GDPR

If your customers are in the EU, GDPR compliance requires knowing exactly where your data lives and who can access it. Managed platforms spread data across regions and sub-processors. Self-hosting on a European bare metal server gives you a single jurisdiction, a single data controller, and an audit trail you actually control.

No Vendor Lock-In

Every managed platform has proprietary configuration. Vercel has vercel.json, Railway has nixpacks, Fly has fly.toml. Self-hosting means your stack runs on standard Linux. Move between any provider in minutes, not days.

What You Need: The SaaS Infrastructure Stack

1. Server

Start with a single server. Most SaaS products under 10k users run fine on one machine. RAW’s raw-4 ARM (4 vCPU, 8 GB RAM, 80 GB NVMe) at $11/mo handles your app, database, cache, and background workers comfortably.

npx rawhq deploy --plan raw-4

2. Database

PostgreSQL is the standard for SaaS. Install it directly on your server — no managed database surcharge.

apt install postgresql -y
sudo -u postgres createdb myapp_production
sudo -u postgres psql -c "CREATE USER myapp WITH PASSWORD 'secure-password';"
sudo -u postgres psql -c "GRANT ALL ON DATABASE myapp_production TO myapp;"

For connection pooling under load, add PgBouncer. It handles thousands of concurrent connections with minimal memory overhead.

3. Reverse Proxy and SSL

Nginx sits in front of your application, handles TLS termination, and serves static assets. Certbot provides free SSL certificates from Let’s Encrypt with automatic renewal.

apt install nginx certbot python3-certbot-nginx -y
certbot --nginx -d app.yoursaas.com --non-interactive --agree-tos -m you@yoursaas.com

4. Application Runtime

Your choice depends on your stack:

  • Node.js / Next.js: PM2 for process management with cluster mode
  • Python / Django / FastAPI: Gunicorn or Uvicorn behind Nginx
  • Ruby / Rails: Puma with systemd service management
  • Go / Rust: Compile a binary and run it directly with systemd

For any stack, register a systemd service so your app restarts automatically on crash or reboot.

5. Redis for Caching and Queues

Redis handles session storage, caching, and background job queues. Install it on the same server — no separate instance needed.

apt install redis-server -y
systemctl enable redis-server

6. Monitoring

At minimum, set up uptime monitoring and resource alerts. For a lightweight stack:

  • Node Exporter + Prometheus: Collect CPU, memory, disk, and network metrics
  • Grafana: Visualize metrics with pre-built dashboards
  • UptimeRobot or Healthchecks.io: External uptime monitoring (free tier available)

7. Backups

Automate PostgreSQL backups with a cron job and store them off-server. A simple approach:

# /etc/cron.d/pg-backup
0 3 * * * postgres pg_dump myapp_production | gzip > /backups/myapp-$(date +\%Y\%m\%d).sql.gz

Sync backups to S3 or another server daily. Test restores monthly.

Recommended Stack by Stage

StageServerCost
MVP / 0–1k usersraw-2 (2 vCPU, 4 GB)$6/mo
Growth / 1k–10k usersraw-4 (4 vCPU, 8 GB)$11/mo
Scale / 10k–50k usersraw-8 (8 vCPU, 16 GB)$21/mo
Enterprise / 50k+ usersraw-16 (16 vCPU, 32 GB)$41/mo

CI/CD: Deploying Updates

Set up a GitHub Actions workflow that deploys on every push to main:

name: Deploy
on:
  push:
    branches: [main]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: ssh root@your-raw-ip "cd /app && git pull && npm ci && npm run build && pm2 reload all"

Store your SSH key as a GitHub secret. Deployments take under 30 seconds.

Why RAW for SaaS Infrastructure

RAW gives you dedicated bare metal — not shared VMs — with NVMe storage, 20 TB bandwidth, and a CLI that deploys in 13 seconds. No noisy neighbors. No surprise bandwidth bills. No per-seat pricing on your database.

  • Dedicated resources: Your CPU and RAM are yours alone. No throttling during traffic spikes
  • NVMe storage: Database queries run 3–5x faster than on shared SSD
  • 20 TB bandwidth: Enough for millions of API requests without overage fees
  • Full root access: Install anything. Configure everything. No platform restrictions

The Bottom Line

Self-hosting your SaaS is not about being cheap — it is about being smart. You get better performance, full data control, GDPR compliance by default, and infrastructure costs that stay flat while your revenue grows. The managed platform tax is real, and it compounds every month.

Start with a single bare metal server. Deploy your full stack. Scale vertically until you genuinely need multiple machines. Most SaaS products never need more than one server — and the ones that do are making enough revenue to afford the upgrade.

Try RAW Free

npx rawhq deploy

7-day free trial. 13 seconds to deploy. No credit card.