DEV Community

Cover image for Self-Hosting Supabase on VPS with Coolify v4
Bijak Technology
Bijak Technology

Posted on Originally published at bijaktechnology.com

Self-Hosting Supabase on VPS with Coolify v4

💡 Originally published on Bijak Technology Enterprise Journal with full interactive parameter benchmarks.

Commercial Supabase Cloud Pro bills spike aggressively the moment your application crosses the 100,000 Monthly Active Users (MAU) threshold, while surges in Auth and Realtime function calls drain your egress bandwidth allowance. For engineering teams managing tight operational budgets, relying on commercial Backend-as-a-Service (BaaS) without infrastructure control is a fast track to FinOps inefficiency.

This article is a comprehensive production runbook to migrate your full Supabase stack to a self-hosted infrastructure using Coolify v4 and Traefik v3 on top of a Hostinger KVM VPS, cutting operating costs by up to 85% without sacrificing PostgreSQL database performance.

Infrastruktur di atas mendukung skalabilitas proses operasional jangka panjang.

FinOps Analysis: Supabase Cloud Pro vs Self-Hosted VPS

Before executing the migration, let's dissect the Total Cost of Ownership (TCO) between managed platforms and independent infrastructure control.

Comparison Parameter Supabase Cloud Pro Hostinger KVM VPS ($20/Month)
Monthly Cost $25 + Usage Overages $20 Flat (8 vCPU, 16GB RAM)
Database Storage 8 GB (Extras incur charges) 200 GB+ NVMe Standalone Storage
Egress Bandwidth 50 GB (Extra $0.09/GB) Unlimited (Fair usage 8TB)
Root Access & Tuning Restricted (Shared Parameter) Full access to sysctl, pg_hba.conf, and extensions

System Architecture & Traefik v3 Routing

To secure communication between containerized services without exposing raw ports, we rely on Traefik v3 API gateway architecture to handle automated SSL termination and wildcard subdomain routing.

flowchart TD
 Client([Client / Frontend]) -->|HTTPS Port 443| Traefik[Traefik v3 Reverse Proxy]
 Traefik -->|Subdomain: api.*| Kong[Kong API Gateway / Supabase Kong]
 Traefik -->|Subdomain: db.*| Postgres[(PostgreSQL Database)]
 Kong --> GoTrue[GoTrue Auth Service]
 Kong --> PostgREST[PostgREST API Engine]
 Kong --> Realtime[Realtime WebSocket Engine]
 Kong --> Storage[Storage API Service]

Prerequisites & Server Environment

Ensure your Hostinger KVM VPS instance meets these minimum specifications:

  • OS: Ubuntu 22.04 LTS
  • RAM: Minimum 8 GB
  • Storage: NVMe SSD
  • Kernel Tuning (/etc/sysctl.conf):
fs.file-max = 2097152
vm.max_map_count = 262144
net.core.somaxconn = 65535
Enter fullscreen mode Exit fullscreen mode

Hands-On Implementation Steps

1. Configure Supabase Docker Compose Stack

Create a working directory on your server and prepare the docker-compose.yml file to deploy all core Supabase components modularly.

version: '3.8'

services:
 postgres:
 image: postgres:15.5-alpine
 restart: always
 environment:
 POSTGRES_DB: postgres
 POSTGRES_USER: postgres
 POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
 volumes:
 - db_data:/var/lib/postgresql/data
 command: postgres -c max_connections=200 -c shared_buffers=2GB
 networks:
 - supabase-net

 kong:
 image: kong:2.8.1
 restart: always
 environment:
 KONG_DATABASE: "off"
 KONG_DECLARATIVE_CONFIG: /var/lib/kong/kong.yml
 KONG_PROXY_ACCESS_LOG: "/dev/stdout"
 KONG_ADMIN_ACCESS_LOG: "/dev/stdout"
 volumes:
 -./volumes/kong/kong.yml:/var/lib/kong/kong.yml
 networks:
 - supabase-net
 labels:
 - "traefik.enable=true"
 - "traefik.http.routers.supabase.rule=Host(`api.yourdomain.com`)"
 - "traefik.http.routers.supabase.entrypoints=websecure"
 - "traefik.http.routers.supabase.tls.certresolver=letsencrypt"
 - "traefik.http.services.supabase.loadbalancer.server.port=8000"

volumes:
 db_data:

networks:
 supabase-net:
 driver: bridge
Enter fullscreen mode Exit fullscreen mode

2. Coolify v4 Integration & Traefik v3 Management

Log in to your Coolify v4 dashboard, select Add Resource -> Docker Compose, and paste the configuration above. Coolify will automatically detect the Traefik labels and issue Let's Encrypt SSL certificates dynamically without manual intervention.

Gotchas & Troubleshooting

  1. Realtime WebSocket Connections Drop Periodically: Solution: Ensure your Traefik v3 enables proxy-read-timeout and proxy-send-timeout headers set to at least 300 seconds to prevent the proxy from prematurely terminating persistent WebSockets.
  2. Disk IOPS Slows Down During Backup: Solution: Limit pg_dump utility bandwidth using ionice limitations in your automated daily cron scripts.

The takeaway of this independent architecture is total sovereignty over your data, slashed latency due to geographical server proximity, and significant long-term budget efficiency.

Transparency: Some links in this article are affiliate links that support the continuity of our research publications at no additional cost to you.


Explore more in-depth system architecture blueprints, FinOps strategies, and enterprise implementations at Bijak Technology.

Top comments (0)