Can I use Cloudflare Hyperdrive with Yugabyte?

Hi. I‘m coding a very simple React app.

Web app → Cloudflare Worker → Yugabyte

now i learned that this doesn’t work because CF Workers can‘t keep the TCP connection open.

Chatgpt told me to use hyperdrive. Is that correct? is this the way to go? I use geo distributed yugabyte. Will it route correctly to the right yugabyte geo instance?

Or is there a copy paste middleware solution i should use and self-host alongside yugabyte?

right now i‘m planning to host yugabyte in USA Germany Singapore (geo distributed rows)

chatgpt told me this:

:brain: 1)

Cloudflare Hyperdrive

(most common “middleware” used today)

Cloudflare Hyperdrive is effectively the de facto way teams connect Workers to an external SQL database (including PostgreSQL or any PostgreSQL-compatible engine like Yugabyte’s YSQL). It solves the hard part of serverless → SQL connectivity:

  • Workers can use familiar Postgres drivers (pg, postgres.js, ORMs like Kysely/Drizzle) but via a Hyperdrive-provided connection string.

  • Hyperdrive maintains globally pooled TCP connections to your database so Workers don’t have to establish a new connection on every request.

  • It also optionally caches query results at the edge for hot reads.

  • You don’t need your own API backend solely for DB access — Workers talk directly via Hyperdrive.

Why people pick it

  • Removes the pain of connection setup on every Worker invocation (TCP ↔ TLS ↔ auth handshake).

  • Works with existing tools / drivers with minimal code change.

  • Makes global scale feel faster without managing connection pools yourself.

  • Now available even on Workers’ free plan.

Typical usage flow

  1. Create a Hyperdrive config pointing at your YSQL database.

  2. Bind it to your Worker (wrangler hyperdrive create …).

  3. Inside the Worker call your database using the Hyperdrive connection string with pg / postgres.js.

  4. Hyperdrive handles pooling, routing, and optional caching.

Tradeoffs

  • You’re adding a platform dependency (Hyperdrive) instead of running your own backend service layer.

  • Some workloads with very complex transactions may still benefit from a full backend layer.

chatgpt told me to do this Option A. I‘m wondering if this will increase latency.

I‘m hosting yugabyte on hetzner. maybe i should co-host a middlewear on hetzner? idk

Option A (usually best):

One Hyperdrive per region + choose at the edge

Create three Hyperdrive configs, each pointing at a regional Yugabyte SQL endpoint:

  • hyperdrive_us → US regional LB / node addresses

  • hyperdrive_de → Germany regional LB / node addresses

  • hyperdrive_sg → Singapore regional LB / node addresses

Then in Workers:

  • choose which Hyperdrive binding to use based on request.cf.country, request.cf.colo, or your own region mapping.

  • (and optionally) use Yugabyte geo-partitioning so the “right” rows are local once you’re connected.

This gives you true edge routing control instead of hoping one origin hostname does the right thing.

Why this matches Yugabyte’s model: Yugabyte expects apps to connect in a region-aware way (smart drivers / load balancing / region preference), especially in multi-region deployments.

option B is shit, right?

Option B:

Single Hyperdrive + GeoDNS/Anycast origin hostname

You can point Hyperdrive at db.yourdomain.com and make that hostname resolve to the nearest regional Yugabyte LB via GeoDNS / latency routing.

This can work, but there are two gotchas:

  1. Hyperdrive’s pooling is described as being placed “closest to your origin database” — if “origin” effectively changes by resolver location, you need to be careful you’re getting the behavior you expect.

  2. Debugging “why did this request hit that region” becomes harder.

If you want predictable behavior, Option A is safer.

Hi @kokoskiwi

Who said this? This works the same as if connecting to Mysql/PostgreSQL.

Since it’s free and included, I believe yes.

You should create a hyperdrive config for every yb-tserver I believe.
And then connect to them as if you were connecting to each yb-tserver.

Does hyperdrive accept multiple ips for a single “config” ?


What is the language you’re coding in?

1 Like

2. The main architectural challenge

:warning: Cloudflare Workers cannot keep long-lived TCP connections.

Yugabyte speaks:

  • YSQL (Postgres protocol) or

  • YCQL (Cassandra-like protocol)

Both require stateful TCP connections.

So you cannot connect directly from Workers to Yugabyte.

Short answer: No — a single Hyperdrive config points to one hostname / origin, not a list of IPs.

Hyperdrive is designed like this:

Worker → Hyperdrive → one configured Postgres-compatible endpoint

That endpoint is:

  • a hostname (recommended), or

  • a single address that resolves via DNS

It does not take:

  • a list of IPs

  • a node list

  • a topology description

Option B is sharp and unpleasant to live with, but it isn’t broken.

Brief points:

It doesn’t matter if workers don’t have TCP in this case; Hyperdrive, not the worker, owns the TCP pool.

Cloudflare Hyperdrive functions properly at the protocol level since Yugabyte YSQL talks Postgres.

GeoDNS + pooling is the issue with option B; once “origin” changes based on resolver location, connection reuse and troubleshooting quickly become problematic.

Hyperdrive is not aware of the Yugabyte topology, but it can accept numerous IPs. It won’t find its way to leaders by magic.

Briefly put, option B is brittle but functional.
Explicit edge selection combined with one Hyperdrive per region is monotonous, predictable, and the appropriate decision for Yugabyte.

1 Like

Please answer. Language and driver you’re using.

1 Like

Hi I‘m using Javascript for everything

inside CF workers they have their V8 environment

CF workers might become expensive so i‘m thinking of a separate node server on hetzner later on (or python or Go) - I don‘t really care about the language i have worked with C Python Java JS in my life - thanks to AI its even easier now anyway to code in anything

But yea for the start i prefer CF Workers i guess,

I want to host yugabyte in hetzner

I use YSQL if thats what you mean with „driver“

BTW thank you everyone already for all your help and support :folded_hands::folded_hands::folded_hands::folded_hands:i dont take it for granted

It’s not that easy to change stacks.

Not to write correct & complex code.

By “driver” I mean the name of the library that you will use to connect to the db. In python there are “psycopg”, “asyncpg”, etc.

Both ways work but you need to decide.


The hyperdrive should still work by creating one hyperdrive for each yb-tserver and connecting to each one. No issue not knowing which is the leader (there are multiple leaders at the same time, leader is per-tablet, not per-cluster)