What is Neon?
Neon is a serverless PostgreSQL provider that separates storage from compute. This means your database can scale to zero when not in use, dramatically reducing costs for personal projects and startups.
Key Features
- Branching: Create database branches for dev/staging just like Git branches
- Scale-to-zero: Compute pauses automatically when idle
- Connection pooling: Built-in PgBouncer support
- Point-in-time restore: 24-hour history on the free tier
Connecting Spring Boot to Neon
The connection string uses the standard JDBC PostgreSQL format. Just set your environment variables and Spring Boot handles the rest:
# application.yml
spring:
datasource:
url: ${NEON_JDBC_URL:jdbc:postgresql://localhost:5432/portfolio}
username: ${NEON_USERNAME:postgres}
password: ${NEON_PASSWORD:postgres}
hikari:
maximum-pool-size: 5
minimum-idle: 1
connection-timeout: 30000
idle-timeout: 600000
max-lifetime: 1800000
Schema Management
Instead of relying on Hibernate's DDL generation (which can be dangerous), I use a schema.sql file with IF NOT EXISTS guards for every table. This makes schema changes non-destructive:
CREATE TABLE IF NOT EXISTS blog_posts (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
title VARCHAR(255) NOT NULL,
slug VARCHAR(255) NOT NULL UNIQUE,
content TEXT,
excerpt TEXT,
cover_image VARCHAR(500),
published BOOLEAN NOT NULL DEFAULT false,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
Performance Tips
Since Neon can have cold-start latency, configure your Spring Boot app to keep connections warm with HikariCP's keepaliveTime setting. Also, enable connection pooling via Neon's pooler endpoint for high-concurrency scenarios.