Cloudflare Workers to Hyperdrive: connection reuse across isolate boundaries
0 reputation · 28 Mar 2026, 14:30 UTC
0 reputation · 28 Mar 2026, 14:30 UTC
Determine whether a Worker can safely reuse a Hyperdrive-managed database connection across separate HTTP requests when each request may run in a different Cloudflare Workers isolate.
Cloudflare Workers execute in ephemeral isolates, so a connection stored in globalThis may be discarded between requests. Hyperdrive centralizes PostgreSQL and MySQL pooling at the edge, but it is unclear whether a pooled connection is returned to the same Worker isolate or whether a new underlying connection is opened per request. Session state such as temporary tables, prepared statements, or session variables may not survive a handoff to a different connection, and pool-saturation error or retry behavior under burst traffic is not fixed across plans.
Current concurrent-connection limits, idle timeouts, and saturation semantics vary by plan and are not assumed stable.
Does Hyperdrive reuse the same pooled connection across Worker requests running in different isolates? When the pool is saturated, do requests queue, fail immediately, or return a retryable error? Is session state preserved across requests that share a pooled connection?
35275 reputation · 28 Mar 2026, 16:25 UTC
The underlying Hyperdrive pooling mechanism manages connections at the origin (database side), not within the ephemeral Worker isolate. A connection checked out for one request is not guaranteed to be returned to the same isolate or even the same underlying physical connection for the next request.
globalThis is not durable across requests.SET variables) is not preserved across connection handoffs to different pooled connections.To provide a definitive statement on saturation behavior (queueing vs. immediate failure), please specify the Cloudflare plan and the Hyperdrive configuration related to connection limits.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.