Why Serverless Databases?
Serverless databases solve key challenges in modern applications:- No connection limits: HTTP-based connections instead of persistent TCP connections
- Global edge networks: Deploy your database queries close to users worldwide
- Pay-per-use pricing: Only pay for actual query execution time
- Auto-scaling: Handle traffic spikes without manual intervention
- Zero maintenance: No server management or patching required
Supported Platforms
Drizzle supports all major serverless database platforms with dedicated, optimized drivers.Neon
Serverless Postgres with instant branching and autoscaling
PlanetScale
Serverless MySQL with branching workflows
Turso (LibSQL)
Edge SQLite with global replication
Vercel Postgres
Postgres designed for Vercel deployments
Neon Postgres
Neon is a serverless Postgres platform with instant branching, autoscaling, and a generous free tier.Installation
HTTP Connection (Recommended for Edge)
The HTTP driver works everywhere, including edge runtimes, with no WebSocket requirements.The HTTP driver is perfect for Cloudflare Workers, Vercel Edge Functions, and other environments where WebSockets aren’t available.
WebSocket Connection (Better Performance)
For Node.js and environments with WebSocket support, use the WebSocket driver for lower latency.Batch Queries
Both HTTP and WebSocket drivers support efficient batch operations:Row-Level Security with Auth Tokens
Neon supports PostgreSQL Row-Level Security (RLS) with JWT authentication:PlanetScale MySQL
PlanetScale is a serverless MySQL platform with branching, non-blocking schema changes, and automatic backups.Installation
Basic Setup
Edge Runtime Compatible
PlanetScale’s HTTP-based driver works in all JavaScript environments:Schema Design for PlanetScale
Turso (LibSQL)
Turso provides edge-replicated SQLite databases with multi-region support and embedded replicas.Installation
Remote Database
Embedded Replicas (Best Performance)
Embedded replicas sync a local SQLite database with your remote Turso database for ultra-low latency reads:Transactions
Vercel Postgres
Vercel Postgres is a serverless Postgres database integrated with the Vercel platform.Installation
Setup
Vercel automatically injects
POSTGRES_URL and other connection variables when you create a Vercel Postgres database.Edge Function Example
Connection Pooling
Serverless databases handle connection pooling automatically, but you can optimize configuration:Neon Pooling
Connection String Options
Most serverless providers support pooling via query parameters:Best Practices
1
Use connection pooling
Enable connection pooling in your database URL or use a pooling service like PgBouncer to prevent connection exhaustion.
2
Minimize cold starts
Keep your database client initialization outside request handlers when possible:
3
Use prepared statements
For frequently executed queries, use prepared statements to reduce parsing overhead:
4
Batch related queries
Reduce round trips by batching queries when supported:
5
Handle connection errors
Always implement retry logic and graceful degradation:
Migration Strategies
Neon & Vercel Postgres
PlanetScale
Turso
Monitoring and Debugging
Enable Query Logging
Custom Logger
Pricing Considerations
Neon
Neon
- Free tier: 0.5 GB storage, 1 project
- Pay for compute time and storage separately
- Autoscaling to zero when inactive
- Branch databases are free
PlanetScale
PlanetScale
- Free tier: 5 GB storage, 1 billion row reads/month
- Pay for storage and row reads/writes
- Branch databases don’t count toward limits during development
Turso
Turso
- Free tier: 9 GB total storage across all databases
- Pay for storage and rows read
- Edge replicas included in all plans
Vercel Postgres
Vercel Postgres
- Free tier: 256 MB storage, 60 hours compute/month
- Integrated billing with Vercel
- Automatic scaling included
Next Steps
Edge Runtime Guide
Deploy Drizzle to edge networks worldwide
Best Practices
Optimize performance and security
Schema Design
Learn how to design efficient database schemas
Drizzle Kit
Manage migrations and schema changes