PlanetScale databases land in the Cloudflare dashboard

Cloudflare is deepening its partnership with PlanetScale, moving beyond the initial integration announced last September. Soon, Cloudflare users will be able to create PlanetScale Postgres and MySQL databases directly from the Cloudflare dashboard and API, with billing handled through their Cloudflare account.

BLOG-3213 2

This applies to both self-serve and enterprise customers. Cloudflare credits, including those from the startup program or committed spend, can be applied to PlanetScale database usage, consolidating billing under one roof.

Why Postgres and MySQL on Workers

SQL relational databases remain a core component of modern application stacks, and Postgres has become a popular default. Its extensive ecosystem of ORMs, GUIs, and extensions like pgvector for vector search in AI workloads makes it a flexible choice for developers building on Workers. The integration means developers can pick the database engine that fits their application requirements.

Currently, developers can already link a PlanetScale account and create Postgres databases from the Cloudflare dashboard for use with Workers. The update arriving next month adds a new Cloudflare subscription that bills for these databases directly through Cloudflare, removing the need for a separate PlanetScale billing relationship for new database instances.

BLOG-3213 3

The built-in integration works with Hyperdrive, Cloudflare's database connectivity service. Hyperdrive handles connection pooling and query caching to keep database access fast and reliable. To connect, developers add a binding to their Worker's configuration file:

// wrangler.jsonc file
{
  "hyperdrive": [
    {
      "binding": "DATABASE",
      "id": <AUTO_CREATED_ID>
    }
  ]
}

Once wired up, standard SQL queries run through the Worker using any preferred Postgres client:

import { Client } from "pg";

export default {
  async fetch(request, env, ctx) {
   
    const client = new Client({ connectionString: env.DATABASE.connectionString });
    await client.connect();

    const result = await client.query("SELECT * FROM pg_tables");
    ...
}

Developer experience and features

PlanetScale was chosen as a partner because of its performance and reliability track record. It offers Postgres and Vitess MySQL, both popular relational database options. Cloudflare's own emphasis on performance and reliability aligns with PlanetScale's approach to database infrastructure.

PlanetScale brings a set of developer-focused features to the table, including query insights for monitoring and optimizing SQL performance, agent-driven workflows to improve queries, and branching for safely deploying code alongside database schema changes. Cloudflare users get the full PlanetScale experience at standard PlanetScale pricing, with all features included, such as usage breakdowns and cost reporting.

BLOG-3213 4

Placement and latency

When Workers interact with a centralized database, network latency can become a concern, especially for applications that issue multiple queries. By default, Workers run at the data center closest to the user, which can add overhead when talking to a central database instance.

Cloudflare offers explicit placement hints that let Workers run in the data center nearest to the primary database, minimizing round-trip times. Looking ahead, Cloudflare plans to automate this process, setting placement hints based on the PlanetScale database's location without manual configuration, with the goal of reducing network latency to single-digit milliseconds.

{
  "placement": {
    "region": "aws:us-east-1"
  }
}

What's available now and next

Developers can today create a new PlanetScale Postgres database or connect an existing PlanetScale database to Workers through the Cloudflare dashboard. Billing for these databases continues to run through PlanetScale for now.

The shift to Cloudflare account billing for new PlanetScale databases goes live next month. Cloudflare is also working on API integration, and is soliciting feedback from users on what other capabilities they'd like to see in the partnership.