Neon Functions: backend logic next to your data
Neon Functions are long-running Node.js 24 compute deployed onto a Neon branch, in the same region and on the same infrastructure as its Lakebase Postgres database, with DATABASE_URL and other Neon backend credentials injected automatically. Running next to the data removes the cross-network hop per query and lets a function keep a pg Pool open across requests, so agents can stream for minutes and WebSockets or SSE can fan out via Postgres LISTEN/NOTIFY. Functions branch with the database: each child branch gets its own function copy and URL, and deleting the branch deletes it. They are declared in neon.ts, Hono is the recommended framework, and the pg Pool is recommended over the serverless driver; functions are not for frontend hosting or background jobs, and cron and event triggers are planned.
Related posts
- Simplify Serverless in AWS: How to Use Neon and Ephemeral Environments
Neon mediumAdept
Neon's serverless Postgres pairs well with ephemeral environments on AWS Lambda because each environment can get its own instant copy-on-write database branch without paying for extra RDS uptime. Compared with Aurora Serverless v2, Neon claims ~500ms cold starts versus 15s, built-in PgBouncer supporting 10,000 connections, and an HTTP/WebSocket data API. A TODO API built with the Serverless Framework shows how the serverless driver's sql template tag guards against SQL injection, but only when called directly on a string literal, and how sql.query with $n placeholders handles dynamic updates. Scripts and GitHub Actions create a branch per feature or CI run, run unit and end-to-end tests against it, then tear down both the stack and the branch.
- Understanding Neon’s object hierarchy
Neon easyNovice
Neon organizes serverless Postgres into projects, branches and compute endpoints, built on a separation of storage and compute that avoids sizing a database upfront. A project is a container per application holding a Postgres cluster (default database "neondb"); branches are copy-on-write, isolated copies of data from the current or a past point in time, with the default cluster represented by the "main" branch. Each branch is reached through a compute endpoint that can be fixed-size or autoscale between a minimum and maximum, letting you cap worst-case spend; at time of writing each branch supports only one endpoint, with read replicas planned to allow more.
- SELECT ’Hello, World’
Neon easyNovice
Neon is a serverless Postgres service built on separated storage and compute, launching behind a waitlist. Each user gets a containerized Postgres compute node, while data lives in a multi-tenant Rust storage layer: Safekeepers run a consensus protocol and, together with S3, form the system of record, and Pageservers serve pages with low latency as disposable scratch space. Avoiding EBS in favour of local disk for hot data and S3 for cold data cuts the cost of triple-replicated storage and compute. Stateless compute also enables scale-to-zero, roughly 3-second provisioning, and copy-on-write database branching for CI/CD workflows, all released under Apache 2.0.
- Web-based AI SQL Playground and connecting to Postgres from the browser
Neon mediumAdept
Neon's Postgres AI Playground connects to a Postgres database directly from the browser and uses OpenAI's gpt-3.5-turbo to turn natural-language prompts into SQL. Browsers can't open TCP connections, so the Neon serverless driver tunnels the Postgres wire protocol through a WebSocket-to-TCP proxy. The proxy is open source and can be self-hosted to reach other Postgres providers. A Vercel edge function rate-limits requests with Upstash Redis, injects the user's schema (pulled from information_schema.columns and flattened to a compact text form) into the prompt, and streams the model's response back to the editor.
- How to use Postgres at the Edge
Neon mediumAdept
Standard Postgres can't be reached from V8-isolate edge runtimes like Vercel Edge Functions because they don't support raw TCP. Neon's serverless driver, a drop-in replacement for node-postgres, gets around this by talking HTTP or WebSockets to a Neon proxy, which opens the TCP connection to Postgres. The walkthrough shows Next.js edge API routes using the `neon` SQL-over-HTTP function for single-shot queries and `Pool`/`Client` over WebSockets for multiple queries per connection. It then combines `@vercel/edge` geolocation with an INSERT into a locations table, as in the Ping Thing demo.