Databases 10 min read

Understanding Serverless Databases: PlanetScale, Neon, Supabase, and Turso

This article explains what serverless databases are, compares them with traditional databases, and provides detailed overviews, core concepts, and code examples for four major services—PlanetScale, Neon, Supabase, and Turso—highlighting features such as automatic scaling, pay‑as‑you‑go pricing, and global replication.

Long Ge's Treasure Box
Long Ge's Treasure Box
Long Ge's Treasure Box
Understanding Serverless Databases: PlanetScale, Neon, Supabase, and Turso

1. Serverless Database Overview

1.1 What is a Serverless Database

A serverless database is a cloud‑native service that automatically scales, charges per usage, and requires no server or infrastructure management.

1.2 Core Features

Automatic scaling : Scales up or down based on load.

Pay‑as‑you‑go : You only pay for actual usage.

Zero ops : No server management is needed.

Global replication : Built‑in read/write splitting and multi‑region deployment.

Connection pool : Integrated connection management.

1.3 Serverless vs Traditional

Capacity planning : Automatic vs requires manual estimation.

Cost model : Usage‑based vs monthly/annual subscription.

Cold start : May incur latency vs none.

Suitable workload : Highly variable vs stable.

Control : Less control vs full control.

2. PlanetScale

2.1 Overview

PlanetScale is a MySQL‑compatible serverless database offering branching and immutable architecture.

2.2 Core Concepts

Branch : Database branch similar to Git.

Schema : Table structure definition.

Deploy Request : Branch merge request.

Vitess : Underlying MySQL scaling engine.

2.3 Usage Examples

# Install PlanetScale CLI
brew install planetscale/tap/pscale

# Login
pscale auth login

# Create a database
pscale database create my-app --region us-east

# Create a branch
pscale branch create my-app feature-new-table

# Connect to the branch
pscale connect my-app feature-new-table
import mysql.connector
import os

connection = mysql.connector.connect(
    host=os.environ['DATABASE_HOST'],
    user=os.environ['DATABASE_USER'],
    password=os.environ['DATABASE_PASSWORD'],
    database=os.environ['DATABASE'],
    ssl_ca='/etc/ssl/certs/ca-certificates.crt'
)

cursor = connection.cursor()
cursor.execute("SELECT * FROM users LIMIT 10")
results = cursor.fetchall()
// Prisma + PlanetScale
datasource db {
  provider = "mysql"
  url = env("DATABASE_URL")
  relationMode = "prisma"
}

generator client {
  provider = "prisma-client-js"
}

model User {
  id    Int    @id @default(autoincrement())
  email String @unique
  name  String?
  posts Post[]
}

model Post {
  id       Int    @id @default(autoincrement())
  title    String
  content  String?
  authorId Int
  author   User @relation(fields: [authorId], references: [id])
}

3. Neon

3.1 Overview

Neon is a fully managed PostgreSQL database that supports serverless mode and branching.

3.2 Core Concepts

Project : A collection of databases.

Branch : Database branch.

Database : Individual database instance.

Role : Database user.

Compute : Compute resource that can be paused.

3.3 Usage Examples

import { neon } from '@neondatabase/serverless'

const sql = neon(process.env.DATABASE_URL)

// Simple query
const users = await sql`SELECT * FROM users LIMIT 10`

// Parameterized query
const user = await sql`SELECT * FROM users WHERE id = ${userId}`

// Transaction
async function transfer(from, to, amount) {
  await sql.transaction([
    sql`UPDATE accounts SET balance = balance - ${amount} WHERE id = ${from}`,
    sql`UPDATE accounts SET balance = balance + ${amount} WHERE id = ${to}`
  ])
}
// Node.js / Drizzle ORM
import { drizzle } from 'drizzle-orm/neon-http'
import { neon } from '@neondatabase/serverless'
import { users } from './schema'

const sql = neon(process.env.DATABASE_URL)
const db = drizzle(sql)

// Query
const allUsers = await db.select().from(users)

3.4 Branch Feature

# Create a branch
psql "postgresql://user:[email protected]/neondb"
CREATE BRANCH dev FROM main;

# List branches
SHOW BRANCHES;

4. Supabase

4.1 Overview

Supabase is an open‑source Firebase alternative that provides a PostgreSQL database, real‑time subscriptions, authentication, storage, edge functions, and automatic API generation.

4.2 Core Features

PostgreSQL : Full PostgreSQL compatibility.

Realtime subscriptions : WebSocket‑based live data.

Auth : Built‑in user system.

Storage : File storage.

Edge Functions : Edge runtime.

Auto API : Generates REST API from schema.

4.3 Usage Examples

import { createClient } from '@supabase/supabase-js'

const supabase = createClient('https://xxx.supabase.co', 'public-anon-key')

// Query
const { data, error } = await supabase
  .from('posts')
  .select('*, author:users(name)')
  .eq('published', true)

// Insert
const { data, error } = await supabase
  .from('posts')
  .insert({
    title: 'Hello World',
    content: 'This is a post',
    author_id: userId
  })

// Real‑time subscription
supabase
  .channel('posts')
  .on('postgres_changes', { event: '*', schema: 'public', table: 'posts' }, (payload) => {
    console.log('Change:', payload)
  })
  .subscribe()

5. Turso

5.1 Overview

Turso is an edge database service built on libSQL (a SQLite fork), offering global edge deployment and an embeddable client.

5.2 Core Features

libSQL compatible : SQLite compatibility.

Edge deployment : Globally distributed.

Embedded : Runs inside client applications.

Replication : Primary‑secondary sync.

Pay‑per‑query : Free tier up to 5,000 queries per day.

5.3 Usage Examples

# Install Turso CLI
brew install tursodatabase/tap/turso

# Create a database
turso db create my-db

# Show database info
turso db show my-db

# Open a shell
turso db shell my-db
# Python SDK
import turso

client = turso.Client("your-token")
 database = client.database("my-db")

# Execute a query
result = database.execute("SELECT * FROM users LIMIT 10")
for row in result.rows:
    print(row)

# Prepared statement
result = database.execute("SELECT * FROM users WHERE id = ?", (user_id,))
// Embedded SQLite (Node.js)
import { createClient } from '@libsql/client'

const local = createClient({ url: "file:local.db" })
const remote = createClient({ url: "libsql://my-db-user.turso.io", authToken: "your-token" })

// Local query with lower latency
const result = await local.execute("SELECT * FROM config")
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud-nativeServerlessdatabaseNeonSupabasePlanetScaleTurso
Long Ge's Treasure Box
Written by

Long Ge's Treasure Box

I'm Long Ge, and this is my treasure chest—packed with cutting‑edge tech insights, career‑advancement tips, and a touch of relaxation you crave. Open it daily for a new surprise.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.