PlanetScale — Introducing the PlanetScale serverless driver for JavaScript¶
Summary¶
Taylor Barnett and Matt Robenolt (PlanetScale, 2022-08-18) launch the PlanetScale serverless driver for JavaScript — a Fetch-API-compatible MySQL client that reaches a PlanetScale database over secure HTTP instead of the MySQL binary protocol. This is the first shipping consumer of the PlanetScale HTTP API and the public launch of the infrastructure that backs it: "Backing our new driver is a new HTTP API and global routing infrastructure to support it." The launch solves a structural incompatibility — runtimes like Cloudflare Workers, Vercel Edge Functions, and Netlify Edge Functions "require external connections to be made over HTTP and not other networking protocols," so a MySQL client that speaks the raw TCP binary protocol is simply not usable from those environments. Beyond unblocking serverless, the HTTP interface brings four latency/scale wins called out in the post: TLS 1.3 faster connections, HTTP/2 connection multiplexing, protocol compression (gzip / brotli / snappy), and global routing — the last described explicitly as CDN-like: "A client connects to the closest geographic edge in our network, then backhauls over long-held connection pools over our internal network to reach the actual destination. Within the US, connections from US West to a database in US East reduce latency by 100ms or more in some cases, even more as the distance increases."
Key takeaways¶
-
Serverless / edge runtimes physically cannot speak raw MySQL — the platforms only permit HTTP(S) egress. "Connections with other MySQL drivers speak the MySQL binary protocol over a raw TCP socket. Our new driver uses secure HTTP, which allows you to use PlanetScale in these constrained environments." This is a platform constraint, not a design preference — canonical wiki statement of concepts/serverless-tcp-socket-restriction.
-
The driver is Fetch-API-compatible, not Node-specific. "The driver works in any environment that uses the Fetch API." This is the shipping API boundary that lets the same
@planetscale/databasenpm package run across Cloudflare Workers, Vercel Edge, Netlify Edge, Node.js, and browser contexts — the Fetch API is the portability substrate. -
HTTP gives PlanetScale four structural wins beyond serverless unblocking. Quoted verbatim: "a modern TLS stack for faster connections with TLS 1.3, connection multiplexing with HTTP/2, protocol compression with gzip, brotli, or snappy, all of which lead to a better experience for serverless environments." Each item maps to a wiki concept:
- TLS 1.3 → concepts/tls-1-3-zero-rtt-handshake
- HTTP/2 multiplexing → concepts/connection-multiplexing-over-http
-
Compression is an HTTP API advantage the MySQL wire protocol cannot match (the MySQL protocol has no first-class client-compression negotiation for uploaded query bytes).
-
Global routing infrastructure launched alongside the driver. "Our new infrastructure and APIs also enable global routing. Similar to a CDN, global routing reduces latency drastically in situations where a client is connecting from a geographically distant location… A client connects to the closest geographic edge in our network, then backhauls over long-held connection pools over our internal network to reach the actual destination." This is the first public announcement of the PlanetScale Global Network — later disclosed in full architectural detail by the 2024-04-17 global-replica-credentials launch (sources/2026-04-21-planetscale-introducing-global-replica-credentials).
-
Quantified latency win: "Within the US, connections from US West to a database in US East reduce latency by 100ms or more in some cases, even more as the distance increases." Canonical wiki datum for concepts/edge-to-origin-database-latency — the coast-to-coast database-connection cost that the Global Network's edge-termination + long-held backhaul is built to amortise away.
-
HTTP API status (Aug 2022): intentionally undocumented. "Note: The HTTP API is currently not documented, but we plan on documenting it when we're ready to officially release it." The serverless driver is the only supported way to call the HTTP API at this point; the protocol contract is an implementation detail of the driver package, not a public surface. (Consistent with the stance in the later Faster MySQL with HTTP/3 benchmark post: "This API is not documented for public consumption just yet.")
-
SQL injection prevention is a first-class driver feature. "The driver also handles your SQL sanitization to help prevent security issues like SQL injection." Parameterised queries via positional placeholders:
conn.execute('SELECT * FROM users WHERE email=?', ['foo@example.com']). The driver is the sanitisation boundary — not the HTTP API, not the Vitess origin — so the same safety property that native MySQL drivers provide is preserved in the HTTP transport version. -
Demo application covers all three target edge runtimes. "You can see the Cloudflare Workers, Vercel Edge Functions, and Netlify Edge Functions examples in their own subdirectory." The
f1-championship-statsrepo is structured as one app × three edge-runtime deployments × one database — the canonical cross-serverless-vendor demo for the driver.
Systems introduced / canonicalised¶
- PlanetScale
serverless driver for JavaScript (
@planetscale/database) — shipped npm package, Fetch-API-compatible. - PlanetScale HTTP API — the vendor-side HTTP interface the driver talks to; undocumented at launch, first exposed via this driver.
- PlanetScale Global Network — the CDN-like infrastructure that terminates edge connections and backhauls to the origin database cluster. First public announcement in this post.
- Cloudflare Workers, Vercel Edge Functions, Netlify Edge Functions — the three launch-target serverless/edge runtimes, all HTTP-only by platform policy.
Concepts introduced / canonicalised¶
- concepts/serverless-tcp-socket-restriction — the platform constraint that forces database clients in FaaS / edge runtimes to speak HTTP.
- concepts/connection-multiplexing-over-http — HTTP/2's stream multiplexing as the mechanism by which one HTTP connection carries many logical MySQL sessions.
- concepts/global-routing-for-databases — CDN-analogous routing applied to a stateful database wire protocol: connect-to-nearest-edge, backhaul-over-warm-pool.
- concepts/tls-1-3-zero-rtt-handshake — the handshake-cost reduction that HTTP-based clients benefit from where MySQL-protocol clients generally don't.
- concepts/edge-to-origin-database-latency — the trans-continental tax on cold-start database reads that the Global Network is architected to cut.
Patterns introduced / canonicalised¶
- patterns/http-api-alongside-binary-protocol — ship an HTTP version of your database protocol next to the binary one, so HTTP-only runtimes can connect.
- patterns/multiplex-many-database-connections-over-one-http-connection — fold per-invocation connection cost into shared HTTP/2 streams to make per-request serverless runtimes viable.
- patterns/cdn-like-database-connectivity-layer — structure database connectivity like a CDN: edge POPs terminate client protocol, backhaul runs on warmed long-held connections.
Operational numbers¶
- Latency improvement (US West → US East): "100ms or more in some cases, even more as the distance increases." Stated as a directional ballpark from the launch copy; no p50 / p95 / p99 disclosure.
- npm install:
npm install @planetscale/database. - Configuration:
host/username/passwordfrom the PlanetScale dashboard's Connect dropdown → select planetscale/database → recommended to store in serverless-platform environment variables.
Caveats¶
- HTTP API is undocumented. "The HTTP API is currently not documented, but we plan on documenting it when we're ready to officially release it." The driver is the sole supported consumer at launch; hand-rolled HTTP clients against this API are not supported.
- No
Connectionobject lifecycle in serverless code. Theconnect()returns a driver handle, not a persistent socket — a new transaction is eachexecute(). Long-lived session state (e.g.SETvariables, session transactions, prepared-statement cursors) is not the programming model this driver targets; it's structurally serverless / stateless. - Fetch-API dependency is load-bearing. Runtimes without
fetch()(or with non-standardfetch()implementations) aren't supported; the driver does not ship a polyfill. - "100ms or more" is a qualitative number. No benchmark tables; no reference runtime; no geographic grid. The rigorous numeric disclosure for the HTTP API comes two years later in sources/2026-04-21-planetscale-faster-mysql-with-http3.
- Protocol compression is listed as a capability, not quantified. "gzip, brotli, or snappy" — but no per-codec wire-size reduction numbers, no CPU-cost disclosure on the driver-side serverless-runtime budget.
- Browser targeting unclear. The Fetch-API compatibility claim implies browser usability; the launch post doesn't explicitly recommend or discourage browser-origin use of the driver, and in-browser direct database access is generally a security anti-pattern (client holds DB credentials). The later HTTP/3 post clarifies that the PlanetScale web console is the first-party browser consumer — not customer browser apps.
- Global routing infrastructure described at one paragraph's depth. Architecture details — edge termination tier, warm backhaul pool, per-query routing, etcd-watched Route records, latency-based DNS, TabletType enum — are all withheld until the 2024-04-17 global-replica-credentials launch (sources/2026-04-21-planetscale-introducing-global-replica-credentials). This post is "there is a CDN for MySQL now"; the later post is "here's how it works."
- No HTTP/3 at launch; HTTP/3 via
quic-goshows up in the 2023-01-04 benchmark post (sources/2026-04-21-planetscale-faster-mysql-with-http3).
Why it matters on this wiki¶
- Canonical first-launch evidence that concepts/serverless-tcp-socket-restriction forces a fundamental redesign of database-access protocols for serverless / edge runtimes. It isn't "native MySQL is faster, we added HTTP for convenience" — native MySQL is structurally unavailable, and HTTP is the only egress the platforms permit.
- First wiki source that names the PlanetScale Global Network as a product primitive (even before the 2024 architecture disclosure). The Aug 2022 launch establishes the "CDN for databases" framing; the 2024 post fills in the engineering.
- First wiki source on the HTTP-API-beside-binary-protocol pattern for OLTP MySQL. Contrasts with SQL-over-HTTP shapes for analytics warehouses (BigQuery-class) — same shape, different workload.
- Historical archeology: paired with Faster MySQL with HTTP/3 (2023-01-04, Robenolt solo), these two posts bracket PlanetScale's public story: "we built HTTP-for-MySQL because we had to" (Aug 2022) → "here's the benchmark showing it's also faster" (Jan 2023).
Source¶
- Original: https://planetscale.com/blog/introducing-the-planetscale-serverless-driver-for-javascript
- Raw markdown:
raw/planetscale/2026-04-21-introducing-the-planetscale-serverless-driver-for-javascript-0b90007d.md
Related¶
- systems/planetscale — vendor context
- systems/planetscale-serverless-driver-js — the shipped driver
- systems/planetscale-http-api — the HTTP API it calls
- systems/planetscale-global-network — the CDN-like backhaul
- systems/mysql — binary-protocol baseline
- systems/cloudflare-workers — Tier-1 target runtime
- systems/vercel-edge-functions — target runtime
- systems/netlify-edge-functions — target runtime
- concepts/serverless-tcp-socket-restriction
- concepts/connection-multiplexing-over-http
- concepts/tls-1-3-zero-rtt-handshake
- concepts/edge-to-origin-database-latency
- concepts/global-routing-for-databases
- patterns/http-api-alongside-binary-protocol
- patterns/multiplex-many-database-connections-over-one-http-connection
- patterns/cdn-like-database-connectivity-layer
- companies/planetscale