Tools / Neon
Visit official site north_east

Neon

Serverless PostgreSQL platform with instant branching, autoscaling, and scale-to-zero. Neon modernizes PostgreSQL for the cloud-native era with developer-friendly features.

Features

Serverless Architecture

  • Scale to Zero: Automatically pause when inactive
  • Instant Wake: Sub-second cold starts
  • Autoscaling: Scale compute up and down automatically
  • Pay Per Use: Only pay for what you use
  • No Connection Limits: Pooling built-in

Database Branching

  • Instant Branches: Create database copies in seconds
  • Copy-on-Write: Branches share unchanged data
  • Branch for PRs: Database per pull request
  • Schema Changes: Test migrations safely
  • Point-in-Time Restore: Restore to any moment

Performance

  • Fast Queries: PostgreSQL 15/16 performance
  • Connection Pooling: Built-in pooler (PgBouncer)
  • Read Replicas: Horizontal scaling
  • Local Development: CLI for local workflows
  • Global Distribution: Multi-region support

Developer Experience

  • Web Console: Beautiful UI for management
  • CLI Tools: Command-line control
  • API: Programmatic database management
  • Integrations: Vercel, Netlify, GitHub, etc.
  • SQL Editor: Query databases from browser

Getting Started

Create Database

# Install CLI
npm install -g neonctl

# Create new project
neonctl projects create

# Get connection string
neonctl connection-string

Connection String

postgres://user:[email protected]/neondb

Connect with Node.js

import { Pool } from 'pg';

const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
  ssl: true
});

const result = await pool.query('SELECT NOW()');
console.log(result.rows[0]);

Connect with .NET

using Npgsql;

var connectionString = Environment.GetEnvironmentVariable("DATABASE_URL");

await using var dataSource = NpgsqlDataSource.Create(connectionString);
await using var conn = await dataSource.OpenConnectionAsync();

await using var cmd = new NpgsqlCommand("SELECT NOW()", conn);
var result = await cmd.ExecuteScalarAsync();
Console.WriteLine(result);

Database Branching

Create Branch

# Create branch from main
neonctl branches create --name dev

# Create from specific point in time
neonctl branches create --name restore --timestamp 2024-01-01T12:00:00Z

# Create for pull request
neonctl branches create --name pr-123

Branch Workflow

# GitHub Actions example
name: Preview
on: pull_request

jobs:
  preview:
    runs-on: ubuntu-latest
    steps:
      - uses: neondatabase/create-branch-action@v3
        with:
          project_id: ${{ secrets.NEON_PROJECT_ID }}
          parent: main
          branch_name: pr-${{ github.event.pull_request.number }}
          api_key: ${{ secrets.NEON_API_KEY }}

Use Cases

  • Testing: Isolate test data
  • Migrations: Safe schema testing
  • Development: Per-developer databases
  • Preview Deployments: Database per PR
  • Data Recovery: Point-in-time restore

Autoscaling

Configuration

using System.Net.Http.Json;

using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", 
quot;Bearer {apiKey}"); await client.PatchAsJsonAsync(
quot;https://console.neon.tech/api/v2/projects/{projectId}/endpoints/{endpointId}", new { autoscaling_limit_min_cu = 0.25, // Minimum compute units autoscaling_limit_max_cu = 2 // Maximum compute units } );

Benefits

  • Cost Efficiency: Pay only for active time
  • Performance: Auto-scale during traffic spikes
  • Simplicity: No manual scaling needed
  • Predictable: Set min/max limits

Pricing

Free Tier

  • 0.5 GB storage
  • Shared compute
  • Scale to zero
  • Unlimited projects
  • Community support

Pro ($19/month)

  • 10 GB storage included
  • Autoscaling
  • Unlimited branches
  • Point-in-time restore (7 days)
  • Email support

Scale (Custom)

  • Custom storage
  • Dedicated compute
  • Extended retention
  • Priority support
  • SLA

Additional Costs

  • Storage:
    .15/GB/month
  • Compute:
    .16/hour (1 CU)
  • Data Transfer:
    .09/GB

Vercel Integration

Setup

# Install Vercel integration
vercel env add DATABASE_URL

# Automatic branch databases
# Each preview deployment gets its own database branch

Configuration

// vercel.json
{
  "env": {
    "DATABASE_URL": "@database_url"
  },
  "build": {
    "env": {
      "DATABASE_URL": "@database_url_preview"
    }
  }
}

Use Cases

Preview Environments

  • Database per pull request
  • Isolated testing
  • Safe schema migrations
  • Realistic data for previews

Development

  • Local-like cloud databases
  • Instant provisioning
  • Cost-effective development
  • Easy cleanup

Production

  • Serverless scalability
  • Automatic optimization
  • Built-in high availability
  • Global performance

Testing

  • Ephemeral test databases
  • Parallel test execution
  • Clean state per test
  • Fast provisioning

API Access

Create Database

curl -X POST https://console.neon.tech/api/v2/projects \
  -H "Authorization: Bearer $NEON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "project": {
      "name": "my-project",
      "region_id": "aws-us-east-2"
    }
  }'

Create Branch

curl -X POST https://console.neon.tech/api/v2/projects/$PROJECT_ID/branches \
  -H "Authorization: Bearer $NEON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "branch": {
      "name": "dev",
      "parent_id": "main"
    }
  }'

Connection Pooling

Built-in Pooler

# Direct connection (for migrations)
postgres://user:[email protected]/db

# Pooled connection (for app)
postgres://user:[email protected]/db

Best Practices

  • Use pooler for applications
  • Use direct for migrations/admin
  • Serverless functions → pooler
  • Long-running apps → direct or pooler

Performance Tips

Connection Management

// Use connection pooler for serverless
const connectionString = process.env.DATABASE_URL + '?sslmode=require';

// Reuse connections
const pool = new Pool({ connectionString });

// Close on shutdown
process.on('SIGTERM', () => pool.end());

Query Optimization

-- Use indexes
CREATE INDEX idx_users_email ON users(email);

-- Analyze queries
EXPLAIN ANALYZE SELECT * FROM users WHERE email = '[email protected]';

Monitoring

Metrics Available

  • Query performance
  • Connection count
  • Compute usage
  • Storage usage
  • Data transfer

Dashboards

  • Web console graphs
  • API for custom dashboards
  • Query statistics
  • Branch activity

Best For

  • Serverless Apps: Perfect match for Vercel, Netlify
  • Preview Environments: Database per PR
  • Startups: Generous free tier, scale later
  • Development: Fast, isolated databases
  • Cost-Conscious: Pay only when active
  • PostgreSQL Users: Full Postgres compatibility

Advantages

vs Traditional PostgreSQL

  • Serverless: Auto-scaling, scale to zero
  • Branching: Instant database copies
  • Cheaper: Pay per use, not reserved capacity
  • Faster Setup: Seconds, not hours

vs Amazon RDS

  • Simpler: No instance management
  • Branching: Not available in RDS
  • Cheaper: For variable workloads
  • Modern: Better developer experience

vs Supabase

  • Branching: Unique to Neon
  • Autoscaling: More aggressive
  • Simpler: Just database, not full backend
  • Cheaper: For serverless workloads

Limitations

  • PostgreSQL only (not MySQL, etc.)
  • Some extensions not supported
  • Higher latency than dedicated servers (minimal)
  • Storage limits on free tier

Integration Examples

Prisma

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

Drizzle

import { drizzle } from 'drizzle-orm/neon-http';
import { neon } from '@neondatabase/serverless';

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

Next.js

import { sql } from '@vercel/postgres';

export async function GET() {
  const { rows } = await sql`SELECT * FROM users`;
  return Response.json(rows);
}

Neon is revolutionizing PostgreSQL for the serverless era, making it as easy and cost-effective as NoSQL databases while retaining all of PostgreSQL's power. The database branching feature alone is worth the switch for most development workflows.

Ready to get started? Visit the official site to learn more.

Visit official site north_east
An unhandled error has occurred. Reload