Hyperdrive
Keep your current database — Hyperdrive makes it feel global and instant.
What is Hyperdrive?
Hyperdrive is an accelerator that sits in front of a database you already have (like PostgreSQL or MySQL) and makes querying it from Cloudflare Workers fast — no matter where in the world the request comes from.
Normally a regional database (one that lives in a single data center) is slow to reach from far away, and opening a fresh connection for every request adds delay. Hyperdrive fixes both with connection pooling and query caching.
Think of it like…
A VIP fast lane to your database. Instead of dialing the database from scratch every time (slow handshakes), Hyperdrive keeps warm lines open and remembers recent answers — so most requests skip the wait.
Why use Hyperdrive?
Workers run all over the globe, but your database lives in one place. Without help, every query pays a long round-trip and a connection setup cost. Hyperdrive removes that pain so your existing SQL database performs like it was built for the edge.
Connection pooling
Reuses a pool of warm database connections instead of opening one per request.
Query caching
Caches results of popular read queries so repeats return almost instantly.
No migration
Keep your current Postgres/MySQL provider; just point Workers through Hyperdrive.
Feels global
Far-away Workers query a single regional database without the usual lag.
When should you use it?
You already have a SQL DB
An existing Postgres or MySQL on AWS, Neon, PlanetScale, etc. that you want to keep.
Global users, one DB
Visitors worldwide but a single regional database that feels slow far away.
Connection limits hit
Serverless functions exhaust your database's connection limit — pooling fixes that.
Read-heavy queries
The same SELECTs repeat often, so caching delivers a big speed-up.
How do you start?
Give Hyperdrive your database connection string (a connection string = the single URL with host, user, password, and database name). Then bind it and connect using a normal Postgres driver from your Worker.
Create a Hyperdrive config
Point it at your existing database with its connection string. Wrangler prints an id.
npx wrangler hyperdrive create my-db-config \ --connection-string="postgres://user:password@db-host.example.com:5432/mydb"Bind it to your Worker
Add the id to wrangler.jsonc under the HYPERDRIVE binding.
{ "hyperdrive": [ { "binding": "HYPERDRIVE", "id": "<paste-your-id-here>" } ] }Install a Postgres driver
Use the popular pg package (add its TypeScript types too).
npm i pg npm i -D @types/pgQuery through Hyperdrive
Read env.HYPERDRIVE.connectionString and connect as usual — Hyperdrive handles pooling and caching for you.
import { Client } from "pg"; export default { async fetch(request, env, ctx) { const client = new Client({ connectionString: env.HYPERDRIVE.connectionString, }); await client.connect(); const { rows } = await client.query("SELECT * FROM products LIMIT 10"); ctx.waitUntil(client.end()); return Response.json(rows); }, };Deploy
Publish your Worker and queries now flow through the fast lane.
npx wrangler deploy
Key concepts
Connection string
The single URL with host, port, user, password, and database name that locates your DB.
Connection pool
A set of ready-made connections kept warm and shared across requests to avoid setup cost.
Query cache
Recent read-query results are remembered so identical repeats skip the database.
Your DB stays the source
Hyperdrive only accelerates access; your real data still lives in your own database.
Tips & notes
Tune caching for fresh data
Query caching is on by default and is great for data that does not change every second. If a query must always return the very latest value, you can disable caching for it.
- Hyperdrive is available on both Free and Paid plans, so you can try it at no cost.
- It supports PostgreSQL (and compatibles like Neon, CockroachDB, Timescale) and MySQL.
- Use ctx.waitUntil(client.end()) so closing the connection does not delay your response.
- Need a Cloudflare-native SQL database instead? Look at D1.
Related products
menu_bookOfficial docsopen_in_new