# Postgres on Neon

URL: https://eoxlabs.dev/stack/neon-postgres
Last updated: 2026-11-26
Publisher: EOXLABS (https://eoxlabs.dev)

Section: [Stack](https://eoxlabs.dev/stack)

Neon is a managed Postgres service that separates compute from storage, so a database can branch instantly, suspend when idle and resume on the next query. EOXLABS uses Neon when a product needs relational Postgres (joins, extensions, row-level security) behind Cloudflare Workers, and connects to it through Hyperdrive or Neon's serverless driver.

Neon's documentation now calls the engine Lakebase Postgres, and Databricks runs the same database inside its own platform. In Neon's [architecture](https://neon.com/docs/introduction/architecture-overview), compute nodes are standard Postgres instances that hold no durable state. Safekeepers replicate the write-ahead log, and a commit counts once a quorum of them acknowledges it. A pageserver rebuilds pages from that log, backed by object storage. Branching, restore and scale to zero all follow from that split. Neon is the Postgres option in the [EOXLABS stack](https://eoxlabs.dev/stack).

## Why does EOXLABS choose Postgres for some products?

Some data models outgrow SQLite: many tables with foreign keys, reporting joins, tenant isolation enforced by the database itself. Postgres [row security policies](https://www.postgresql.org/docs/current/ddl-rowsecurity.html) restrict which rows each role can read or change, so tenant isolation doesn't depend on every query remembering its filter. Neon also offers the extensions EOXLABS reaches for: `vector` (pgvector) for embeddings in [AI systems](https://eoxlabs.dev/capabilities/ai-systems), `postgis` for geography and `pg_trgm` for fuzzy search, all on its [supported extensions](https://neon.com/docs/extensions/pg-extensions) list. One catch from the same list: `pg_cron` only runs while the compute is awake, so it needs scale to zero turned off.

Neon is also a natural landing point when a [legacy-to-edge migration](https://eoxlabs.dev/capabilities/legacy-to-edge-migration) moves an existing Postgres database behind Workers. It is still Postgres, so the schema and SQL carry over, subject to the extension list.

## How does a Worker connect to Neon?

EOXLABS picks one of three paths per workload:

- **Hyperdrive with node-postgres.** Hyperdrive keeps a pool of connections and routes each query over the nearest one. Neon's [Hyperdrive guide](https://neon.com/docs/guides/cloudflare-hyperdrive) says to give Hyperdrive the direct, unpooled connection string, because Hyperdrive does its own pooling. This is the default when a Worker runs several queries per request or uses Drizzle ORM. The [Hyperdrive](https://eoxlabs.dev/stack/hyperdrive) page covers its configuration.
- **Neon's serverless driver over HTTP.** The `neon()` function in [`@neondatabase/serverless`](https://neon.com/docs/serverless/serverless-driver) sends each query as an HTTP request. Neon calls it the fastest option for single queries and non-interactive transactions. Requests and responses are capped at 64 MB.
- **The same driver over WebSockets.** `Pool` and `Client` follow the node-postgres API and support interactive transactions, but in Workers the connection can't outlive the request that opened it.

A read-only transaction over HTTP, using the driver's own options:

```ts
import { neon } from '@neondatabase/serverless';

const sql = neon(env.DATABASE_URL);
const [order, lines] = await sql.transaction(
  [
    sql`SELECT id, status FROM orders WHERE id = ${orderId}`,
    sql`SELECT sku, qty FROM order_lines WHERE order_id = ${orderId}`,
  ],
  { isolationLevel: 'RepeatableRead', readOnly: true },
);
```

Every path still ends in one region. Each Neon project lives in [exactly one region](https://neon.com/docs/introduction/regions), and the region can't be changed later, so EOXLABS chooses it at creation based on where users are and where the data is allowed to live. When a Worker makes several queries per request, an explicit [placement hint](https://developers.cloudflare.com/workers/configuration/placement/) such as `aws:us-east-1` runs that Worker beside the database, while an unplaced Worker in front still handles authentication close to the caller. The note on [sub-50 ms edge latency](https://eoxlabs.dev/engineering/sub-50ms-edge-latency) shows how EOXLABS budgets those round trips against its p50 design target.

## Which connection does each job get?

Neon's built-in pooler is PgBouncer in transaction mode, and it accepts up to 10,000 client connections ([connection pooling](https://neon.com/docs/connect/connection-pooling)). Transaction mode has limits: plain `SET`, temporary tables, SQL-level `PREPARE`, `LISTEN/NOTIFY` and session advisory locks don't work through it. EOXLABS therefore uses:

- the pooled hostname (with `-pooler`) for application traffic that doesn't go through Hyperdrive;
- direct connections for schema migrations, `pg_dump` and `pg_restore`, logical replication, and Hyperdrive itself;
- `SET LOCAL` inside a transaction, never plain `SET`, for per-request values such as the tenant ID a row security policy reads.

## How does branching change delivery?

A Neon [branch](https://neon.com/docs/introduction/branching) is a copy-on-write clone of a database. It shares data with its parent until the two diverge, and creating it adds no load to the parent. EOXLABS uses branches to:

1. give each pull request its own database, with an expiration date so it deletes itself;
2. rehearse a migration on a fresh branch of production before running it for real;
3. roll a branch back to any moment inside its history window, down to the millisecond, with [instant restore](https://neon.com/docs/introduction/branch-restore). Neon keeps the pre-restore state as a backup branch, so a restore can itself be undone.

A branch of production also copies production rows, including any PHI. [Schema-only branches](https://neon.com/docs/guides/branching-schema-only) copy the structure without the data, so test environments get real tables filled with synthetic records. Neon labels the feature beta and caps how many root branches a project can hold, so EOXLABS treats it as one control among several for [healthcare](https://eoxlabs.dev/industries/healthcare) systems, not the only one.

## What does scale to zero cost?

Neon [suspends a compute](https://neon.com/docs/introduction/scale-to-zero) after 5 minutes without activity and reactivates it "within a few hundred milliseconds" on the next query. That saves money on preview branches and quiet internal tools. It is the wrong trade for a production API with a latency target, because the first request after a quiet spell pays a cold start. Paid plans can turn scale to zero off; on the Free plan the setting is fixed, and computes larger than 16 CU never suspend. [Autoscaling](https://neon.com/docs/introduction/autoscaling) is a separate control: it moves compute between a minimum and a maximum without restarts, and the range can't exceed 8 CU.

## Neon, D1 or Turso?

| | Neon | D1 | Turso |
|---|---|---|---|
| Engine | Postgres with extensions | SQLite semantics, run by Cloudflare | SQLite-compatible, with Turso Cloud |
| Where data lives | One region per project, fixed at creation | A primary, plus read replicas in every supported region through the [Sessions API](https://developers.cloudflare.com/d1/best-practices/read-replication/) | A cloud database, or an embedded file on the device |
| Limits that shape the design | Transaction-mode pooler; wake-up after idle | [10 GB per database](https://developers.cloudflare.com/d1/platform/limits/) on Workers Paid; each database runs one query at a time | [Sync](https://docs.turso.tech/sync/usage) resolves conflicts as "last push wins" |
| Best fit at EOXLABS | Relational products with joins, row security, extensions and branch-per-PR delivery | Per-tenant or per-product data that fits SQLite and belongs beside the Worker; see [D1](https://eoxlabs.dev/stack/d1) | Apps that must read and write offline, then sync |

## When not to use Neon

- **The data fits SQLite and lives with one Worker.** D1 removes the connection layer entirely.
- **The app must keep working offline.** An embedded database with sync is closer to the requirement.
- **The data must stay in a jurisdiction where Neon has no region.** Check the region list first; a project can't move later.
- **The design depends on session state through the pooler,** such as `LISTEN/NOTIFY` fan-out. Use a direct connection, or move fan-out to [Durable Objects](https://eoxlabs.dev/stack/durable-objects).
- **Writers on every continent each need fast commits.** A single-region primary makes distant writers pay the full round trip.
- **A production path can't absorb a wake-up after idle** and the plan doesn't allow turning scale to zero off.

For pipelines that land structured records in Postgres, see [data pipelines](https://eoxlabs.dev/capabilities/data-pipelines).

## Related

- [Hyperdrive](https://eoxlabs.dev/stack/hyperdrive): Hyperdrive lets edge code query a central Postgres without a new connection per request, and EOXLABS splits cached and fresh reads and keeps transactions short.
- [D1](https://eoxlabs.dev/stack/d1): D1 is the relational store EOXLABS reaches for first on Cloudflare, and its single-threaded design shapes schemas, replica sessions and the point where Postgres is the better choice.
- [Data Pipelines](https://eoxlabs.dev/capabilities/data-pipelines): EOXLABS designs pipelines in which every record can be traced from source to destination: ingestion at the edge, validation with reasons, idempotent transforms, and lineage stored with the data.
- [Legacy-to-Edge Migration](https://eoxlabs.dev/capabilities/legacy-to-edge-migration): Maintain On Course: EOXLABS migrates live systems to Cloudflare's edge one route at a time, keeps the existing database reachable through Hyperdrive, and keeps every step reversible.
- [Why sub-50 ms is a defensible edge claim and sub-2 ms is not](https://eoxlabs.dev/engineering/sub-50ms-edge-latency): Fiber propagation, handshake round trips and last-mile latency decide which edge latency claims hold up. Server-Timing and real-user data keep the numbers honest.

## More stack

- [SvelteKit](https://eoxlabs.dev/stack/sveltekit)
- [TypeScript](https://eoxlabs.dev/stack/typescript)
- [Rust](https://eoxlabs.dev/stack/rust)
