ในยุคที่ Backend-as-a-Service (BaaS) กลายเป็นตัวเลือกหลักของนักพัฒนา Full-Stack หลายคนเริ่มต้นกับ Firebase ของ Google แต่เมื่อโปรเจกต์ขยายตัว ข้อจำกัดของ Firebase ก็ปรากฏชัดเจน ไม่ว่าจะเป็น Vendor Lock-in ค่าใช้จ่ายที่พุ่งสูง หรือความยากในการ Query ข้อมูลที่ซับซ้อน Supabase เกิดมาเพื่อแก้ปัญหาเหล่านี้ โดยเป็น Open Source Alternative ที่สร้างบน PostgreSQL ฐานข้อมูลที่ทรงพลังที่สุดตัวหนึ่งของโลก
บทความนี้จะพาคุณเจาะลึกทุกแง่มุมของ Supabase ตั้งแต่แนวคิดพื้นฐาน การตั้งค่า ฟีเจอร์หลักทั้ง 5 ตัว (Database, Auth, Storage, Edge Functions, Realtime) ไปจนถึงการใช้งานจริงกับ Framework ยอดนิยมอย่าง Next.js และ SvelteKit รวมถึงเปรียบเทียบกับ Firebase แบบจุดต่อจุดเพื่อให้คุณตัดสินใจได้ว่าเครื่องมือไหนเหมาะกับโปรเจกต์ของคุณมากที่สุด
Supabase คืออะไร?
Supabase คือ Open Source Backend-as-a-Service (BaaS) ที่สร้างขึ้นบน PostgreSQL เปิดตัวในปี 2020 โดยทีมจาก YCombinator มีเป้าหมายเป็น "Open Source Firebase Alternative" โดยให้บริการครบวงจรสำหรับการสร้าง Backend แอปพลิเคชัน ทุกอย่างที่คุณต้องการในการสร้าง Full-Stack App มีพร้อมอยู่ในที่เดียว ไม่ว่าจะเป็นฐานข้อมูล ระบบ Authentication การเก็บไฟล์ Serverless Functions และ Realtime Subscriptions
สิ่งที่ทำให้ Supabase แตกต่างจาก BaaS ตัวอื่นคือการเลือกใช้เทคโนโลยี Open Source ที่ผ่านการพิสูจน์มาแล้วหลายสิบปี แทนที่จะสร้างทุกอย่างขึ้นมาใหม่ Supabase ประกอบร่างจากเครื่องมือที่ดีที่สุดในแต่ละด้าน PostgreSQL สำหรับฐานข้อมูล GoTrue สำหรับ Authentication PostgREST สำหรับ RESTful API อัตโนมัติ Realtime สำหรับ WebSocket และ Deno สำหรับ Edge Functions ทำให้คุณไม่ติด Vendor Lock-in เพราะสามารถ Self-host ได้ทุกเมื่อ
Supabase ยังมี Supabase Studio ซึ่งเป็น Web UI ที่สวยงามและใช้งานง่ายมาก คล้ายกับ phpMyAdmin แต่ทันสมัยกว่ามาก คุณสามารถจัดการตาราง เขียน SQL Query ดู Logs จัดการ User และตั้งค่า Policies ได้ทั้งหมดผ่าน Browser ซึ่งเป็นจุดเด่นสำคัญที่ทำให้นักพัฒนาหน้าใหม่เริ่มต้นได้ง่าย
Supabase vs Firebase — เปรียบเทียบจุดต่อจุด
การเลือกระหว่าง Supabase กับ Firebase เป็นคำถามที่นักพัฒนาหลายคนเจอ มาดูความแตกต่างอย่างละเอียดกัน
| หัวข้อ | Supabase | Firebase |
|---|---|---|
| ฐานข้อมูล | PostgreSQL (Relational) | Firestore (NoSQL / Document) |
| Query Language | SQL มาตรฐาน | Firebase SDK / Query API |
| Open Source | ใช่ (Apache 2.0) | ไม่ (Proprietary) |
| Self-hosting | รองรับ (Docker Compose) | ไม่รองรับ |
| Auth | GoTrue (Email, OAuth, Magic Link, Phone) | Firebase Auth (คล้ายกัน) |
| Storage | S3-compatible + Policies | Cloud Storage |
| Functions | Edge Functions (Deno) | Cloud Functions (Node.js) |
| Realtime | Postgres Changes + Broadcast | Firestore Realtime Listeners |
| Pricing | เริ่มฟรี / Pay-as-you-go | เริ่มฟรี / Blaze plan |
| Vendor Lock-in | ต่ำมาก | สูง |
| Learning Curve | ต้องรู้ SQL พื้นฐาน | ง่ายกว่าสำหรับมือใหม่ |
ฟีเจอร์หลักที่ 1 — Database (PostgreSQL)
หัวใจของ Supabase คือ PostgreSQL ฐานข้อมูล Relational ที่ทรงพลังที่สุดในโลก Open Source ทุกโปรเจกต์ที่สร้างบน Supabase จะได้ Dedicated PostgreSQL Instance พร้อม Extensions มากมายที่เปิดใช้ได้ทันที เช่น pgvector สำหรับ AI/Vector Search, PostGIS สำหรับ Geospatial Data, pg_cron สำหรับ Scheduled Jobs และอื่นๆ อีกหลายสิบตัว
Supabase สร้าง RESTful API ให้อัตโนมัติจากตารางและ View ที่คุณสร้าง โดยใช้ PostgREST ซึ่งหมายความว่าเมื่อคุณสร้างตาราง คุณจะได้ CRUD API พร้อมใช้ทันทีโดยไม่ต้องเขียน Backend Code แม้แต่บรรทัดเดียว นอกจากนี้ยังมี GraphQL ผ่าน pg_graphql Extension อีกด้วย
สร้างตารางและ Query ข้อมูล
-- สร้างตาราง products ใน Supabase SQL Editor
CREATE TABLE products (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name TEXT NOT NULL,
description TEXT,
price DECIMAL(10,2) NOT NULL,
category TEXT,
in_stock BOOLEAN DEFAULT true,
created_at TIMESTAMPTZ DEFAULT now()
);
-- เพิ่มข้อมูล
INSERT INTO products (name, description, price, category)
VALUES
('Wireless Mouse', 'Ergonomic bluetooth mouse', 890.00, 'accessories'),
('Mechanical Keyboard', 'Cherry MX Blue switches', 2490.00, 'accessories'),
('USB-C Hub', '7-in-1 multiport adapter', 1290.00, 'accessories');
-- Query ด้วย SQL มาตรฐาน
SELECT * FROM products WHERE category = 'accessories' AND price < 2000 ORDER BY price;
Row Level Security (RLS)
Row Level Security คือฟีเจอร์ระดับ PostgreSQL ที่ Supabase ใช้เป็นกลไกหลักในการรักษาความปลอดภัยของข้อมูล แทนที่จะเขียน Authorization Logic ใน Backend Code คุณเขียน Policy ลงไปในฐานข้อมูลโดยตรง ซึ่งหมายความว่าไม่ว่าจะเข้าถึงข้อมูลผ่านช่องทางไหน ไม่ว่าจะ REST API, GraphQL หรือ Direct Connection กฎ Security จะถูกบังคับใช้เสมอ
-- เปิดใช้ RLS
ALTER TABLE products ENABLE ROW LEVEL SECURITY;
-- Policy: ทุกคนอ่านได้
CREATE POLICY "Anyone can read products"
ON products FOR SELECT
USING (true);
-- Policy: เฉพาะ Authenticated users เพิ่มได้
CREATE POLICY "Authenticated users can insert"
ON products FOR INSERT
TO authenticated
WITH CHECK (true);
-- Policy: เฉพาะเจ้าของแก้ไขได้ (ต้องมี column user_id)
CREATE POLICY "Users can update own products"
ON products FOR UPDATE
TO authenticated
USING (auth.uid() = user_id)
WITH CHECK (auth.uid() = user_id);
-- Policy: Admin ทำได้ทุกอย่าง
CREATE POLICY "Admins full access"
ON products FOR ALL
TO authenticated
USING (
EXISTS (
SELECT 1 FROM user_roles
WHERE user_id = auth.uid() AND role = 'admin'
)
);
ใช้ Supabase Client ใน JavaScript
// ติดตั้ง
// npm install @supabase/supabase-js
import { createClient } from '@supabase/supabase-js'
const supabase = createClient(
'https://your-project.supabase.co',
'your-anon-key'
)
// อ่านข้อมูล
const { data, error } = await supabase
.from('products')
.select('*')
.eq('category', 'accessories')
.lt('price', 2000)
.order('price', { ascending: true })
// เพิ่มข้อมูล
const { data: newProduct, error: insertError } = await supabase
.from('products')
.insert({ name: 'Webcam HD', price: 1590, category: 'accessories' })
.select()
.single()
// อัปเดตข้อมูล
const { error: updateError } = await supabase
.from('products')
.update({ price: 1490 })
.eq('id', 1)
// ลบข้อมูล
const { error: deleteError } = await supabase
.from('products')
.delete()
.eq('id', 3)
ฟีเจอร์หลักที่ 2 — Authentication
Supabase Auth สร้างจาก GoTrue ซึ่งเป็น Authentication Server ที่รองรับหลายวิธีการยืนยันตัวตน คุณสามารถใช้ Email/Password, OAuth (Google, GitHub, Discord, Apple, Twitter และอื่นๆ กว่า 20 Provider), Magic Link (ส่ง Link ไปทาง Email), Phone OTP (ส่ง SMS) และแม้แต่ SAML สำหรับ Enterprise ทั้งหมดนี้มาพร้อมกับ JWT Token Management, Session Handling และ Refresh Token อัตโนมัติ
Email/Password Authentication
// สมัครสมาชิก
const { data, error } = await supabase.auth.signUp({
email: 'user@example.com',
password: 'securepassword123',
options: {
data: {
full_name: 'สมชาย ใจดี',
avatar_url: 'https://example.com/avatar.jpg'
}
}
})
// เข้าสู่ระบบ
const { data, error } = await supabase.auth.signInWithPassword({
email: 'user@example.com',
password: 'securepassword123'
})
// ตรวจสอบ Session ปัจจุบัน
const { data: { user } } = await supabase.auth.getUser()
console.log(user.id, user.email, user.user_metadata)
// ออกจากระบบ
await supabase.auth.signOut()
OAuth (Social Login)
// เข้าสู่ระบบด้วย Google
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'google',
options: {
redirectTo: 'https://myapp.com/auth/callback',
scopes: 'email profile'
}
})
// เข้าสู่ระบบด้วย GitHub
const { data, error } = await supabase.auth.signInWithOAuth({
provider: 'github',
options: {
redirectTo: 'https://myapp.com/auth/callback'
}
})
Magic Link
// ส่ง Magic Link ทาง Email
const { data, error } = await supabase.auth.signInWithOtp({
email: 'user@example.com',
options: {
emailRedirectTo: 'https://myapp.com/welcome'
}
})
// Phone OTP
const { data, error } = await supabase.auth.signInWithOtp({
phone: '+66812345678'
})
// ยืนยัน OTP
const { data, error } = await supabase.auth.verifyOtp({
phone: '+66812345678',
token: '123456',
type: 'sms'
})
Auth Listener — ติดตามสถานะ Login
// ฟังการเปลี่ยนแปลง Auth State
supabase.auth.onAuthStateChange((event, session) => {
console.log('Auth event:', event) // SIGNED_IN, SIGNED_OUT, TOKEN_REFRESHED, etc.
console.log('Session:', session)
if (event === 'SIGNED_IN') {
// User เพิ่งล็อกอิน -> redirect ไปหน้า Dashboard
}
if (event === 'SIGNED_OUT') {
// User ออกจากระบบ -> redirect ไปหน้า Login
}
})
ฟีเจอร์หลักที่ 3 — Storage
Supabase Storage เป็นระบบจัดเก็บไฟล์ที่เข้ากันได้กับ S3 Protocol ออกแบบมาสำหรับไฟล์ขนาดใหญ่ เช่น รูปภาพ วิดีโอ เอกสาร PDF และไฟล์อื่นๆ คุณสามารถสร้าง Bucket จัดการสิทธิ์ด้วย Storage Policies (คล้ายกับ RLS) และใช้ Image Transformation ในตัวเพื่อ Resize หรือ Optimize รูปภาพได้ทันที
// สร้าง Bucket (ทำครั้งเดียวผ่าน Dashboard หรือ SQL)
// Bucket: 'avatars' (public), 'documents' (private)
// อัปโหลดไฟล์
const { data, error } = await supabase.storage
.from('avatars')
.upload('user123/profile.jpg', file, {
cacheControl: '3600',
upsert: true,
contentType: 'image/jpeg'
})
// ดาวน์โหลดไฟล์
const { data, error } = await supabase.storage
.from('avatars')
.download('user123/profile.jpg')
// สร้าง Public URL
const { data } = supabase.storage
.from('avatars')
.getPublicUrl('user123/profile.jpg')
// สร้าง Signed URL (หมดอายุ)
const { data, error } = await supabase.storage
.from('documents')
.createSignedUrl('report.pdf', 3600) // 1 ชั่วโมง
// Image Transformation (resize on-the-fly)
const { data } = supabase.storage
.from('avatars')
.getPublicUrl('user123/profile.jpg', {
transform: { width: 200, height: 200, resize: 'cover' }
})
// ลบไฟล์
const { error } = await supabase.storage
.from('avatars')
.remove(['user123/old-avatar.jpg'])
Storage Policies
-- Policy: ทุกคนดูรูป Avatar ได้
CREATE POLICY "Public avatar access"
ON storage.objects FOR SELECT
USING (bucket_id = 'avatars');
-- Policy: เฉพาะเจ้าของอัปโหลด Avatar ตัวเอง
CREATE POLICY "Users upload own avatar"
ON storage.objects FOR INSERT
TO authenticated
WITH CHECK (
bucket_id = 'avatars'
AND (storage.foldername(name))[1] = auth.uid()::text
);
-- Policy: เฉพาะเจ้าของลบ Avatar ตัวเอง
CREATE POLICY "Users delete own avatar"
ON storage.objects FOR DELETE
TO authenticated
USING (
bucket_id = 'avatars'
AND (storage.foldername(name))[1] = auth.uid()::text
);
ฟีเจอร์หลักที่ 4 — Edge Functions (Deno)
Supabase Edge Functions คือ Serverless Functions ที่รันบน Deno Runtime ถูก Deploy บน Edge Network ทั่วโลก ทำให้มี Latency ต่ำ เหมาะสำหรับงานที่ต้องเขียน Custom Logic ฝั่ง Server เช่น การประมวลผล Payment การส่ง Email การเรียก Third-party API หรือ Webhook Handler ข้อดีของ Deno คือรองรับ TypeScript โดยตรง มี Security ที่ดีกว่า Node.js (Permission-based) และเร็วในการ Cold Start
// supabase/functions/send-welcome-email/index.ts
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
serve(async (req) => {
const { email, name } = await req.json()
// เรียก Supabase Client ภายใน Edge Function
const supabase = createClient(
Deno.env.get('SUPABASE_URL')!,
Deno.env.get('SUPABASE_SERVICE_ROLE_KEY')!
)
// ส่ง Email ผ่าน Resend API
const res = await fetch('https://api.resend.com/emails', {
method: 'POST',
headers: {
'Authorization': `Bearer ${Deno.env.get('RESEND_API_KEY')}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
from: 'noreply@myapp.com',
to: email,
subject: 'Welcome!',
html: `สวัสดี ${name}!
ยินดีต้อนรับสู่แอปของเรา
`
})
})
// บันทึก Log ลง Database
await supabase.from('email_logs').insert({
recipient: email,
type: 'welcome',
status: res.ok ? 'sent' : 'failed'
})
return new Response(JSON.stringify({ success: res.ok }), {
headers: { 'Content-Type': 'application/json' }
})
})
# Deploy Edge Function
supabase functions deploy send-welcome-email
# เรียกใช้จาก Client
const { data, error } = await supabase.functions.invoke('send-welcome-email', {
body: { email: 'user@example.com', name: 'สมชาย' }
})
# ทดสอบ Local
supabase functions serve send-welcome-email
ฟีเจอร์หลักที่ 5 — Realtime Subscriptions
Supabase Realtime ทำให้คุณสามารถ Subscribe การเปลี่ยนแปลงของข้อมูลแบบ Real-time ผ่าน WebSocket ได้ทันที มี 3 โหมดหลักคือ Postgres Changes (ฟังการเปลี่ยนแปลงของ Database โดยตรง), Broadcast (ส่งข้อมูลระหว่าง Client แบบ Pub/Sub) และ Presence (ติดตามสถานะ Online/Offline ของ User) ฟีเจอร์นี้เหมาะมากสำหรับแอปแชท Collaborative Editing Dashboard แบบ Live และ Notification System
// Postgres Changes — ฟังการเปลี่ยนแปลงของตาราง
const channel = supabase
.channel('products-changes')
.on(
'postgres_changes',
{
event: '*', // INSERT, UPDATE, DELETE หรือ *
schema: 'public',
table: 'products',
filter: 'category=eq.accessories' // ฟิลเตอร์เฉพาะที่ต้องการ
},
(payload) => {
console.log('Change received:', payload)
// payload.eventType: 'INSERT' | 'UPDATE' | 'DELETE'
// payload.new: ข้อมูลใหม่
// payload.old: ข้อมูลเก่า
}
)
.subscribe()
// Broadcast — ส่งข้อความระหว่าง Client
const chatChannel = supabase
.channel('room-1')
.on('broadcast', { event: 'message' }, (payload) => {
console.log('New message:', payload)
})
.subscribe()
// ส่งข้อความ
chatChannel.send({
type: 'broadcast',
event: 'message',
payload: { user: 'สมชาย', text: 'สวัสดีครับ!' }
})
// Presence — ติดตาม Online Status
const presenceChannel = supabase
.channel('online-users')
.on('presence', { event: 'sync' }, () => {
const state = presenceChannel.presenceState()
console.log('Online users:', Object.keys(state).length)
})
.on('presence', { event: 'join' }, ({ key, newPresences }) => {
console.log('User joined:', newPresences)
})
.on('presence', { event: 'leave' }, ({ key, leftPresences }) => {
console.log('User left:', leftPresences)
})
.subscribe(async (status) => {
if (status === 'SUBSCRIBED') {
await presenceChannel.track({
user_id: 'user-123',
username: 'สมชาย',
online_at: new Date().toISOString()
})
}
})
ALTER PUBLICATION supabase_realtime ADD TABLE products;
Supabase Studio — Web UI ที่ทรงพลัง
Supabase Studio คือ Dashboard สำหรับจัดการโปรเจกต์ทั้งหมด ใช้งานผ่าน Browser ที่ app.supabase.com หรือ Self-hosted ได้ มีฟีเจอร์หลักดังนี้
- Table Editor — สร้าง แก้ไข ลบตารางและข้อมูลแบบ Spreadsheet UI ไม่ต้องเขียน SQL ก็ได้
- SQL Editor — เขียนและรัน SQL Query โดยตรง มี Syntax Highlighting และ Auto-complete พร้อม Template สำหรับ Common Queries
- Authentication — ดูรายชื่อ User ทั้งหมด จัดการ Provider ตั้งค่า Email Template และ Redirect URL
- Storage — สร้าง Bucket อัปโหลดไฟล์ จัดการ Policy ผ่าน UI ได้เลย
- Edge Functions — ดู Logs Deploy Status และ Error ของ Functions ทั้งหมด
- Database — จัดการ Roles Policies Extensions Triggers และ Functions ของ PostgreSQL
- Logs — ดู API Logs Auth Logs และ Postgres Logs แบบ Real-time พร้อม Filter
- Reports — ดู API Usage Bandwidth Database Size และ Auth Stats
Supabase กับ Framework ยอดนิยม
Supabase + Next.js (App Router)
// lib/supabase/server.ts — Server-side Client
import { createServerClient } from '@supabase/ssr'
import { cookies } from 'next/headers'
export async function createSupabaseServer() {
const cookieStore = await cookies()
return createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
getAll() { return cookieStore.getAll() },
setAll(cookiesToSet) {
cookiesToSet.forEach(({ name, value, options }) =>
cookieStore.set(name, value, options)
)
}
}
}
)
}
// app/products/page.tsx — Server Component
export default async function ProductsPage() {
const supabase = await createSupabaseServer()
const { data: products } = await supabase
.from('products')
.select('*')
.order('created_at', { ascending: false })
return (
<div>
{products?.map(p => (
<div key={p.id}>{p.name} - ฿{p.price}</div>
))}
</div>
)
}
Supabase + SvelteKit
// src/hooks.server.ts
import { createServerClient } from '@supabase/ssr'
import type { Handle } from '@sveltejs/kit'
export const handle: Handle = async ({ event, resolve }) => {
event.locals.supabase = createServerClient(
import.meta.env.VITE_SUPABASE_URL,
import.meta.env.VITE_SUPABASE_ANON_KEY,
{
cookies: {
getAll: () => event.cookies.getAll(),
setAll: (cookies) => {
cookies.forEach(({ name, value, options }) =>
event.cookies.set(name, value, { ...options, path: '/' })
)
}
}
}
)
return resolve(event)
}
// src/routes/products/+page.server.ts
export async function load({ locals }) {
const { data: products } = await locals.supabase
.from('products')
.select('*')
return { products: products ?? [] }
}
Supabase + Nuxt 3
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@nuxtjs/supabase'],
supabase: {
url: process.env.SUPABASE_URL,
key: process.env.SUPABASE_KEY,
redirect: true
}
})
// pages/products.vue
<script setup>
const supabase = useSupabaseClient()
const { data: products } = await useAsyncData('products', async () => {
const { data } = await supabase.from('products').select('*')
return data
})
</script>
Supabase CLI และ Local Development
Supabase CLI ช่วยให้คุณพัฒนา ทดสอบ และ Deploy แอปได้ตั้งแต่ Local Environment โดยรัน Supabase Stack ทั้งหมด (PostgreSQL, Auth, Storage, Edge Functions, Studio) บนเครื่องของคุณผ่าน Docker คุณไม่จำเป็นต้องเชื่อมต่อกับ Cloud ขณะพัฒนา ซึ่งทำให้ Development Loop เร็วขึ้นมากและไม่เสีย Quota
# ติดตั้ง Supabase CLI
npm install -g supabase
# เริ่มต้นโปรเจกต์
supabase init
# รัน Supabase Local (ต้องมี Docker)
supabase start
# จะได้ URL และ Keys สำหรับ Local:
# API URL: http://localhost:54321
# Studio URL: http://localhost:54323
# DB URL: postgresql://postgres:postgres@localhost:54322/postgres
# Anon Key: eyJ...
# Service Role Key: eyJ...
# หยุด
supabase stop
# ดู Status
supabase status
Database Migrations
# สร้าง Migration ใหม่
supabase migration new create_products_table
# ไฟล์จะถูกสร้างที่ supabase/migrations/20260410000000_create_products_table.sql
# เขียน SQL ลงไป
# Apply Migration (Local)
supabase db reset
# Push Migration ไป Cloud
supabase db push
# ดึง Schema จาก Cloud มา Local
supabase db pull
# ดู Diff ระหว่าง Local กับ Cloud
supabase db diff
Type Generation
# สร้าง TypeScript Types จาก Database Schema
supabase gen types typescript --local > src/types/database.ts
# หรือจาก Cloud
supabase gen types typescript --project-id your-project-id > src/types/database.ts
# ใช้ Types ใน Code
import type { Database } from './types/database'
const supabase = createClient<Database>(url, key)
// ตอนนี้ supabase.from('products').select('*') จะมี Type Safety เต็มรูปแบบ
// IDE จะ Auto-complete ชื่อตาราง ชื่อ Column และ Type ของแต่ละ Column ให้
Self-hosting Supabase
ข้อดีที่ยิ่งใหญ่ที่สุดของ Supabase คือคุณสามารถ Self-host ได้ทั้งหมด เพราะทุกส่วนประกอบเป็น Open Source คุณสามารถรัน Supabase บน Server ของคุณเองด้วย Docker Compose ซึ่งเหมาะสำหรับองค์กรที่มีข้อกำหนดด้าน Data Sovereignty หรือต้องการควบคุม Infrastructure ทั้งหมดเอง
# Clone Supabase Docker
git clone --depth 1 https://github.com/supabase/supabase
cd supabase/docker
# ตั้งค่า Environment Variables
cp .env.example .env
# แก้ไข .env: ตั้ง POSTGRES_PASSWORD, JWT_SECRET, ANON_KEY, SERVICE_ROLE_KEY
# รัน Supabase ทั้ง Stack
docker compose up -d
# Services ที่รันได้แก่:
# - PostgreSQL (port 5432)
# - PostgREST (port 3000)
# - GoTrue / Auth (port 9999)
# - Realtime (port 4000)
# - Storage API (port 5000)
# - Studio UI (port 3000)
# - Kong API Gateway (port 8000)
# - Meta (port 8080)
Pricing — ค่าใช้จ่ายของ Supabase
Supabase มีโมเดลราคาที่เข้าใจง่ายและเป็นมิตรกับนักพัฒนา โดยเฉพาะ Free Plan ที่ให้มาเยอะพอสำหรับโปรเจกต์ขนาดเล็กถึงกลาง
| Plan | ราคา/เดือน | Database | Storage | Bandwidth | Edge Functions |
|---|---|---|---|---|---|
| Free | $0 | 500 MB | 1 GB | 5 GB | 500K invocations |
| Pro | $25 | 8 GB | 100 GB | 250 GB | 2M invocations |
| Team | $599 | ไม่จำกัด | ไม่จำกัด | ไม่จำกัด | ไม่จำกัด |
| Enterprise | Custom | Custom | Custom | Custom | Custom |
Free Plan รองรับ 2 โปรเจกต์ ไม่มี Pause Policy (ก่อนหน้านี้โปรเจกต์ที่ไม่ใช้งานจะถูก Pause แต่ปี 2026 ยกเลิกนโยบายนี้แล้ว) Pro Plan เหมาะสำหรับ Production App ขนาดกลาง ส่วน Team Plan เหมาะสำหรับทีมที่ต้องการ SOC2 Compliance และ Priority Support
เมื่อไหร่ควรใช้ Supabase เมื่อไหร่ควรใช้ Firebase หรือ Custom Backend?
เลือก Supabase เมื่อ
- ต้องการ Relational Database ที่รองรับ Complex Queries, Joins และ Transactions
- ต้องการหลีกเลี่ยง Vendor Lock-in และมีทางเลือก Self-host
- ทีมมีความรู้ SQL พื้นฐาน และต้องการ Full Control เหนือ Database
- ต้องใช้ PostgreSQL Extensions เช่น pgvector (AI), PostGIS (Map) หรือ pg_cron (Scheduling)
- สร้าง SaaS, B2B App หรือแอปที่มี Data Model ซับซ้อน
เลือก Firebase เมื่อ
- ต้องการเริ่มต้นเร็วที่สุด ไม่อยากยุ่งกับ SQL
- สร้าง Mobile App ที่ต้องการ Offline Sync (Firestore มี Offline Mode ในตัว)
- ใช้ Google Cloud อยู่แล้ว และต้องการ Integration กับ GCP Services
- ต้องการ Analytics, Crashlytics, Remote Config ที่ Firebase มีครบ
เลือก Custom Backend เมื่อ
- ต้องการ Control ทุกอย่าง 100% ทั้ง Architecture และ Performance
- มี Business Logic ที่ซับซ้อนเกินกว่าจะใส่ใน Edge Functions
- ต้องการใช้ Database อื่นที่ไม่ใช่ PostgreSQL เช่น MongoDB, DynamoDB หรือ CockroachDB
- ทีมมีประสบการณ์ Backend Development และมี Infrastructure Engineer
สรุป
Supabase เป็นทางเลือกที่ทรงพลังและครบวงจรสำหรับ Full-Stack Developer ในปี 2026 ด้วยพลังของ PostgreSQL ที่อยู่เบื้องหลัง คุณได้ทั้ง Relational Database ระดับ Enterprise พร้อม Authentication Storage Edge Functions และ Realtime ในแพ็กเกจเดียว ที่สำคัญคือทุกอย่างเป็น Open Source ทำให้คุณไม่ต้องกลัว Vendor Lock-in และสามารถ Migrate หรือ Self-host ได้ทุกเมื่อ
สำหรับนักพัฒนาที่มีพื้นฐาน SQL การเปลี่ยนจาก Firebase มา Supabase แทบไม่มีอุปสรรค และจะได้ความยืดหยุ่นเพิ่มขึ้นอย่างมาก ลองเริ่มต้นที่ supabase.com สร้างโปรเจกต์ฟรี แล้วคุณจะเห็นว่าทำไม Supabase ถึงเป็นหนึ่งในโปรเจกต์ Open Source ที่เติบโตเร็วที่สุดในโลก Dev ปี 2026 อ่านบทความเพิ่มเติมได้ที่ SiamCafe Blog ครับ
