Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Neon · Const

Cloudflare Hyperdrive

Cloudflare Hyperdrive connects Cloudflare Workers to Neon Postgres through a globally distributed connection pool. It lets Workers use standard PostgreSQL drivers while reducing connection setup latency.

How it works

Cloudflare Hyperdrive sits between a Cloudflare Worker and Neon Postgres. It maintains connection pools distributed across Cloudflare locations and routes Worker queries to a nearby pool, while standard PostgreSQL drivers such as node-postgres or postgres.js issue the queries.

Syntax

npx wrangler hyperdrive create <name> --connection-string=<NEON_DATABASE_CONNECTION_STRING>

Parameters

NameTypeDescription
connection-stringstringNeon Postgres connection string passed to Wrangler when creating the Hyperdrive configuration.
namestringName assigned to the Hyperdrive service created with Wrangler.

Returns

A Hyperdrive configuration and Worker binding that provide connection details for querying the selected Neon Postgres database.

Key points

  • Hyperdrive proxies database queries and is designed to improve access speed for serverless applications running on Cloudflare Workers.
  • It keeps reusable database connections distributed across Cloudflare’s network instead of creating a fresh database connection for every request.
  • Requests are directed to a nearby available pooled connection, which helps reduce connection-establishment latency for globally distributed Workers.
  • Neon recommends Hyperdrive for Workers when using a native PostgreSQL driver and needing optimized connection pooling.
  • The integration works with standard native PostgreSQL drivers, including node-postgres.

Common mistakes

  • Use Neon’s direct connection string rather than a pooled one, because Hyperdrive provides the pooling layer.
  • Do not assume a separate Workers plan is required for Hyperdrive.

Example: Query Neon through Hyperdrive

import { Client } from "pg";

export default {
  async fetch(request, env) {
    const client = new Client({ connectionString: env.HYPERDRIVE.connectionString });
    await client.connect();
    try {
      const result = await client.query("select now() as current_time");
      return Response.json(result.rows[0]);
    } finally {
      await client.end();
    }
  }
};

Uses node-postgres with the connection string supplied by a Cloudflare Hyperdrive binding.

When to use it

Global serverless applications

A globally distributed Cloudflare Worker needs low-latency access to Neon Postgres.

Native PostgreSQL drivers

A Worker uses node-postgres or postgres.js and needs connection pooling without implementing it itself.

Connection-heavy workloads

Many short-lived Worker requests would otherwise repeatedly establish database connections.

Interview questions

QWhat problem does Hyperdrive solve when a Worker connects to Neon?

Hyperdrive is Cloudflare’s connection-pooling service for Workers. It keeps database connections in globally distributed pools and routes requests to the closest available connection, reducing connection-setup latency.

Follow-up: Why should the Neon connection string have pooling disabled? Because Hyperdrive itself manages pooling, so adding Neon’s pooled endpoint would introduce an unnecessary second pooling layer.

QWhich database drivers can be used with Neon through Hyperdrive?

A Worker can use a regular PostgreSQL driver, including node-postgres or postgres.js, with Hyperdrive. The Worker reads the connection string from its Hyperdrive binding and passes it to the driver.

Follow-up: How does this differ from Neon’s serverless driver? The serverless driver connects over HTTP or WebSockets, whereas Hyperdrive is intended for native PostgreSQL drivers and handles pooling at Cloudflare’s network edge.

QWhat is the basic setup flow?

Create a Hyperdrive configuration with Wrangler using Neon’s direct connection string, add the resulting Hyperdrive binding to the Worker, and use that binding’s connection details in the Worker code. The Neon role and database selected for the connection determine the target database.

Follow-up: What should be checked if deployment fails? Verify that the binding name in the Worker matches the Wrangler configuration and that the source connection string is direct rather than pooled.

  • Cloudflare Workers
  • Hyperdrive binding
  • Wrangler CLI
  • node-postgres
  • postgres.js
  • Neon serverless driver
  • connection pooling

Source: Use Neon with Cloudflare Hyperdrive. Checked 2026-10-16.