// Stack

Postgres on Neon

Last updated ·

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, 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.

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 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, postgis for geography and pg_trgm for fuzzy search, all on its supported 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 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 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 page covers its configuration.
  • Neon's serverless driver over HTTP. The neon() function in @neondatabase/serverless 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:

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, 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 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 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). 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 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. 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 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 systems, not the only one.

What does scale to zero cost?

Neon suspends a compute 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 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?

NeonD1Turso
EnginePostgres with extensionsSQLite semantics, run by CloudflareSQLite-compatible, with Turso Cloud
Where data livesOne region per project, fixed at creationA primary, plus read replicas in every supported region through the Sessions APIA cloud database, or an embedded file on the device
Limits that shape the designTransaction-mode pooler; wake-up after idle10 GB per database on Workers Paid; each database runs one query at a timeSync resolves conflicts as "last push wins"
Best fit at EOXLABSRelational products with joins, row security, extensions and branch-per-PR deliveryPer-tenant or per-product data that fits SQLite and belongs beside the Worker; see D1Apps 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.
  • 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.

→

Related

+

More stack

Have a system that can’t go dark?

Start a project →