Next.js ช่วยสร้าง Full Stack App ด้วย SSR ได้ง่าย และ Vercel/Netlify รองรับ Serverless Functions สำหรับ Backend คำถามคือ: ฐานข้อมูลไหนเหมาะที่สุดสำหรับ Next.js?
เกณฑ์สำคัญ 2 ประการ:
- Serverless Pricing: จ่ายตามการใช้งานจริง? ไม่ใช้ไม่ต้องจ่าย?
- Serverless Connections: รองรับ HTTP/REST API? (หลีกเลี่ยงปัญหา Connection Pooling ใน Serverless)
TL;DR - ตารางเปรียบเทียบ
| Feature | PlanetScale | Supabase | Upstash | Fauna | DynamoDB | MongoDB Atlas |
|---|---|---|---|---|---|---|
| API | MySQL | PostgreSQL | Redis | Fauna (FQL/GraphQL) | DynamoDB | MongoDB |
| Type | Relational | Relational | KV Store | Document | Document | Document |
| Free Tier | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Serverless Pricing | ⚠️ (Min $29/mo) | ⚠️ (Min $25/mo) | ✅ True Serverless | ⚠️ (Min $22.5/mo) | ✅ | ✅ (Serverless Plan) |
| REST API | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ (Data API) |
| GraphQL API | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ |
| Global Replication | ❌ | ❌ | ✅ | ✅ | ✅ | ⚠️ (Dedicated Only) |
| Database Branching | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Realtime Updates | ❌ | ✅ | ❌ | ❌ | ✅ | ⚠️ (via Realm) |
| Price Reads | $1.5/10M | $0.09/GB | $0.2/100K | $0.45/1M (4KB) | $0.25/1M (2KB) | $0.3/1M (4KB) |
| Price Writes | $1.5/1M | $0.09/GB | $0.2/100K | $2.25/1M (1KB) | $1.25/1M (1KB) | $1.25/1M (1KB) |
| Price Storage | $1.25/GB | $0.125/GB | $0.25/GB | $0.23/GB | $0.25/GB | $0.25/GB |
PlanetScale (MySQL + Vitess)
- MySQL Compatible ใช้ Vitess (Tech เดียวกับ YouTube)
- Database Branching - Feature เด่น! Branch/Merge Schema เหมือน Git
- Free Tier: 100M reads/เดือน
- Paid เริ่ม $29/เดือน (มี Minimum Cost → ไม่ใช่ True Serverless)
- ❌ ไม่มี HTTP/REST API → ใช้กับ Cloudflare Workers/Vercel Edge ไม่ได้
- ❌ ต้องใช้ TCP Connection (MySQL Protocol) - อาจมีปัญหา Connection Limit
Supabase (PostgreSQL + Auth + Storage)
- PostgreSQL จริง + Real-time Subscriptions + Auth + Storage
- มี REST API (PostgREST) ใช้ใน Serverless/Edge ได้
- Free Tier: 500MB Storage, 2GB Transfer/เดือน
- Paid เริ่ม $25/เดือน (Minimum Cost → ไม่ใช่ True Serverless)
- รองรับ Cloudflare Workers ผ่าน REST API
Upstash Redis (True Serverless Redis)
- Redis แบบ Serverless จริง - จ่ายต่อ Request, Scale to Zero
- มีทั้ง Redis Protocol (TCP) และ REST API (HTTP) - ใช้ได้ทุกที่
- Global Replication มาตรฐาน (5 Regions)
- Free Tier: 10,000 Commands/วัน
- Pricing: $0.20/100K Commands, $0.25/GB Storage
- ⚠️ ไม่เหมาะสำหรับ Complex Queries (No SQL, No Joins)
Fauna (Global Strong Consistency)
- Globally Replicated + Strongly Consistent (ACID)
- GraphQL API + FQL (Native Query Language)
- HTTP-based - ใช้ใน Serverless/Edge ได้
- Paid เริ่ม $22.5/เดือน (Minimum Cost)
- Pricing Complex (TRO, TWO, TCO Units)
- Write Latency สูงกว่า (Trade-off ของ Strong Consistency)
MongoDB Atlas (Serverless Plan)
- MongoDB Managed Service มี Serverless Plan (Preview)
- Data API (REST) เพิ่งเปิดตัว - ใช้ HTTP ได้
- Serverless Pricing: Pay-per-operation, Scale to Zero
- Multi-region เฉพาะ Dedicated Plan
- ยังอยู่ใน Preview - อาจมีข้อจำกัด
DynamoDB (AWS Native)
- Fully Managed NoSQL (Key-Value + Document)
- HTTP-based - เหมาะ Serverless
- Pay-per-request + Storage - Scale to Zero
- Global Tables สำหรับ Multi-region (ค่าใช้จ่ายเพิ่ม)
- ⚠️ Vendor Lock-in (AWS Only)
- ⚠️ API ไม่ Intuitive เท่า Redis/MongoDB
สรุป: เลือกตัวไหนดี?
| ความต้องการ | แนะนำ |
|---|---|
| Relational DB | Supabase หรือ PlanetScale |
| Database Branching (Schema Migration แบบ Git) | PlanetScale |
| Real-time Updates | Supabase หรือ MongoDB Atlas |
| Global Low Latency | Upstash หรือ DynamoDB |
| Global Strong Consistency | Fauna |
| Low Latency Key-Value Store | Upstash |
| ชอบ PostgreSQL | Supabase |
| ชอบ MySQL | PlanetScale |
| ชอบ Redis | Upstash |
| ชอบ MongoDB | MongoDB Atlas |
| ต้องการ GraphQL | Fauna |
พยายามเป็นกลางและถูกต้องที่สุด หากมีข้อผิดพลาดหรือข้อมูลเก่า กรุณาแจ้งมาทาง Twitter ครับ!