Skip to content

Commit a3971ad

Browse files
committed
thomasgauvin: add details to how hyperdrive works with changes
1 parent c54060c commit a3971ad

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

src/content/docs/hyperdrive/configuration/how-hyperdrive-works.mdx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pcx_content_type: concept
33
title: How Hyperdrive works
44
sidebar:
55
order: 2
6-
76
---
87

98
Connecting to traditional centralized databases from Cloudflare's global network which consists of over [300 data center locations](https://www.cloudflare.com/network/) presents a few challenges as queries can originate from any of these locations.
@@ -16,9 +15,17 @@ Hyperdrive solves these challenges by managing the number of global connections
1615

1716
![Hyperdrive connection](~/assets/images/hyperdrive/configuration/hyperdrive-comparison.svg)
1817

18+
## Edge connection setup
19+
20+
When a database driver connects to a database from a Cloudflare Worker, illustrated above on the right half of the diagram in **Direct (without Hyperdrive)**, it will first go through the connection setup. This may require multiple round trips to the database in order to verify and establish a secure connection.
21+
22+
**With Hyperdrive** (on the left half of the above diagram), this connection setup occurs between your Cloudflare Worker and Hyperdrive on the edge, as close to your Worker as possible. This incurs significantly less latency since the roundtrips are done within the same region.
23+
1924
## Connection Pooling
2025

21-
Hyperdrive creates a global pool of connections to your database that can be reused as your application executes queries against your database.
26+
Hyperdrive creates a pool of connections to your database that can be reused as your application executes queries against your database.
27+
28+
The pool of database connections is placed in one or more regions closest to your origin database. This minimizes the latency incurred by roundtrips between your Cloudflare Workers and database to establish new connections. This also ensures that as little network latency is incurred for uncached queries.
2229

2330
When a query hits Hyperdrive, the request is routed to the nearest connection pool.
2431

@@ -28,15 +35,14 @@ If the connection pool does not have pre-existing connections, it will establish
2835

2936
:::note
3037

31-
Hyperdrive automatically manages the connection pool properties for you, including limiting the total number of connections to your origin database. Refer to [Limits](/hyperdrive/platform/limits/) to learn more.
38+
Hyperdrive automatically manages the connection pool properties for you, including limiting the total number of connections to your origin database. Refer to [Limits](/hyperdrive/platform/limits/) to learn more.
3239
:::
3340

3441
## Pooling mode
3542

3643
The Hyperdrive connection pooler operates in transaction mode, where the client that executes the query communicates through a single connection for the duration of a transaction. When that transaction has completed, the connection is returned to the pool.
3744

38-
39-
Hyperdrive supports [`SET` statements](https://www.postgresql.org/docs/current/sql-set.html) for the duration of a transaction or a query. For instance, if you manually create a transaction with `BEGIN`/`COMMIT`, `SET` statements within the transaction will take effect. Moreover, a query that includes a `SET` command (`SET X; SELECT foo FROM bar;`) will also apply the `SET` command. When a connection is returned to the pool, the connection is `RESET` such that the `SET` commands will not take effect on subsequent queries.
45+
Hyperdrive supports [`SET` statements](https://www.postgresql.org/docs/current/sql-set.html) for the duration of a transaction or a query. For instance, if you manually create a transaction with `BEGIN`/`COMMIT`, `SET` statements within the transaction will take effect. Moreover, a query that includes a `SET` command (`SET X; SELECT foo FROM bar;`) will also apply the `SET` command. When a connection is returned to the pool, the connection is `RESET` such that the `SET` commands will not take effect on subsequent queries.
4046

4147
This implies that a single Worker invocation may obtain multiple connections to perform its database operations and may need to `SET` any configurations for every query or transaction. It is not recommended to wrap multiple database operations with a single transaction to maintain the `SET` state. Doing so will affect the performance and scaling of Hyperdrive as the connection cannot be reused by other Worker isolates for the duration of the transaction.
4248

@@ -46,11 +52,11 @@ Hyperdrive supports named prepared statements as implemented in the `postgres.js
4652

4753
Hyperdrive does not support the following PostgreSQL features:
4854

49-
* SQL-level management of prepared statements, such as using `PREPARE`, `DISCARD`, `DEALLOCATE`, or `EXECUTE`.
50-
* Advisory locks ([PostgreSQL documentation](https://www.postgresql.org/docs/current/explicit-locking.html#ADVISORY-LOCKS)).
51-
* `LISTEN` and `NOTIFY`.
52-
* `PREPARE` and `DEALLOCATE`.
53-
* Any modification to per-session state not explicitly documented as supported elsewhere.
55+
- SQL-level management of prepared statements, such as using `PREPARE`, `DISCARD`, `DEALLOCATE`, or `EXECUTE`.
56+
- Advisory locks ([PostgreSQL documentation](https://www.postgresql.org/docs/current/explicit-locking.html#ADVISORY-LOCKS)).
57+
- `LISTEN` and `NOTIFY`.
58+
- `PREPARE` and `DEALLOCATE`.
59+
- Any modification to per-session state not explicitly documented as supported elsewhere.
5460

5561
In cases where you need to issue these unsupported statements from your application, the Hyperdrive team recommends setting up a second, direct client without Hyperdrive.
5662

@@ -66,4 +72,4 @@ Caching reduces the burden on your origin database and accelerates the response
6672

6773
## Related resources
6874

69-
* [Query caching](/hyperdrive/configuration/query-caching/)
75+
- [Query caching](/hyperdrive/configuration/query-caching/)

src/content/docs/hyperdrive/reference/faq.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@ pcx_content_type: concept
33
title: FAQ
44
sidebar:
55
order: 10
6-
76
---
87

98
Below you will find answers to our most commonly asked questions regarding Hyperdrive.
109

10+
## Connectivity
11+
12+
### Does Hyperdrive use specific IP addresses to connect to my database?
13+
14+
Hyperdrive connects to your database using [Cloudflare's IP address ranges](https://www.cloudflare.com/ips/). These are shared by all Hyperdrive configurations and other Cloudflare products.
15+
16+
This can be used to configure restrictions in your database firewall to restrict the IP addresses that can access your database.
17+
1118
## Pricing
1219

1320
### Does Hyperdrive charge for data transfer / egress?
@@ -27,4 +34,3 @@ Hyperdrive itself does not charge for compute (CPU) or processing (wall clock) t
2734
### Are there any limits to Hyperdrive?
2835

2936
Refer to the published [limits](/hyperdrive/platform/limits/) documentation.
30-

0 commit comments

Comments
 (0)