Back to articles
AI & Cloud

Bring Serverless Home: Guide to Hosting Supabase Edge Functions on VPS

A detailed guide on deploying Supabase Edge Functions on a self-hosted VPS to create a private serverless environment, optimizing cost and infrastructure control.

DPTCloud Engineering4 min read
Bring Serverless Home: Guide to Hosting Supabase Edge Functions on VPS

Image credit: younizealous · Pixabay Content License

Introduction: Bring Serverless Home with Supabase Edge Functions on VPS

In the rapidly evolving landscape of web applications and APIs, deploying serverless functions has become increasingly common. Supabase Edge Functions offer a powerful solution for running server-side logic at the edge with extremely fast response times. However, these functions are typically offered as a SaaS service. For organizations seeking full infrastructure control, cost optimization, or strict data compliance, self-hosting Supabase Edge Functions on a high-RAM Cloud VPS presents a compelling alternative.

This guide walks you through each step to deploy Supabase Edge Functions on your own VPS, transforming your server into a complete, self-hosted serverless ecosystem – "bringing serverless home."

Overview of Supabase Edge Functions

Supabase Edge Functions allow you to run JavaScript/TypeScript code at the edge, enabling low-latency processing of HTTP requests, database queries, and interactions with other services. While Supabase provides this as a managed service, the source code for the edge runtime is not open-sourced for direct self-hosting. To achieve a similar setup on your own infrastructure, you must implement a compatible edge function runner.

Options include using open-source frameworks like serverless-framework or vercel with custom self-hosted configurations. These frameworks can emulate the edge function environment, allowing you to deploy functions as if they were running on a managed platform.

Prerequisites and VPS Configuration

To successfully deploy Supabase Edge Functions on a VPS, you need a server with robust specifications. The following are the minimum requirements:

  • RAM: At least 8GB (recommended 16GB for multiple concurrent functions)
  • CPU: Minimum 4 cores
  • Storage: SSD with 100GB or more
  • OS: Ubuntu 22.04 LTS or Debian 11
  • Static IP address

Choose a Cloud VPS with high RAM that meets your needs. Providers like DigitalOcean, Linode, or Vietnamese VPS hosts with SSD and high-RAM options are suitable.

Deploying Supabase Edge Functions on VPS

Since Supabase does not provide an open-source version of Edge Functions for self-hosting, we'll use a compatible framework. The serverless framework is a popular choice for deploying edge functions on custom infrastructure.

Here is an example configuration using the serverless framework:

# Install Serverless Framework
npm install -g serverless

# Create a new project
serverless create --template nodejs --path edge-functions

# Navigate to the project directory
cd edge-functions

# Configure serverless.yml
cat < serverless.yml
service: edge-functions
provider:
  name: aws
  runtime: nodejs18.x
  region: us-east-1
functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: /hello
          method: get
EOF

After configuration, deploy to your VPS by installing serverless and running:

serverless deploy --stage production

This will set up an edge function runner on your VPS, enabling you to deploy functions as if they were running at the edge.

Verification and Testing

After deployment, verify the function is working by accessing the URL:

curl http://your-vps-ip:3000/hello

If you receive a "Hello World" response, the function has been successfully deployed.

Alternative Solution: Self-Hosting Supabase Edge Functions

If you wish to use the exact Supabase Edge Functions, you can explore open-source projects like supabase/edge-functions for self-hosting. This approach requires a deep understanding of Supabase's architecture and may involve significant code customization.

For businesses requiring full control over infrastructure, self-hosting on a VPS is the optimal choice. You can integrate with monitoring tools like NetData to track performance metrics.

Troubleshooting

  • Cannot access the function: Check the VPS firewall and ensure the port (e.g., 3000) is open.
  • No response from function: Review the function logs using serverless logs to identify errors.
  • Low performance: Increase RAM or upgrade to a VPS with a more powerful CPU.

References

DPTCloud Tier III Infrastructure

High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02Recommended

VPS-4E

297.000 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe
ECO · vn-02

VPS-5E

614.900 ₫ / mo

10% VAT included

  • CPU: 8 vCPU
  • RAM: 16 GB
  • SSD: 100 GB NVMe
ADVANCED · vn-03Recommended

VPS-4T

548.900 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478