Cloudflare has taken a significant step forward in enhancing the developer experience by deepening its partnership with PlanetScale, a move first announced last September. This collaboration aims to provide Cloudflare Workers with seamless access to both Postgres and MySQL databases, facilitating the development of fast, full-stack applications. The integration is set to become even more streamlined, allowing users to create PlanetScale Postgres and MySQL databases directly from the Cloudflare dashboard and API, with billing conveniently handled through their Cloudflare accounts.
This integration empowers developers to select the data storage solutions that best align with their Worker application requirements while maintaining a unified billing system, whether they are self-serve or enterprise customers. Notably, Cloudflare credits, similar to those provided in the startup program or through committed spending, can be applied towards PlanetScale databases.
Postgres & MySQL for Workers
SQL relational databases such as Postgres and MySQL serve as the backbone of contemporary applications. Postgres, in particular, has gained traction among developers due to its robust tooling ecosystem, which includes ORMs, GUIs, and extensions like pgvector for AI-driven vector search applications. As a result, Postgres has become the preferred choice for developers seeking a powerful, flexible, and scalable database solution.
Developers can already link their PlanetScale accounts and create Postgres databases directly from the Cloudflare dashboard for their Workers. Starting next month, new PlanetScale databases will be billed directly to Cloudflare accounts for both self-serve and enterprise users.
With this built-in integration, PlanetScale databases will work seamlessly with Workers through Hyperdrive, Cloudflare’s database connectivity service. Hyperdrive efficiently manages database connection pools and query caching, ensuring that database queries are both rapid and reliable. Developers can simply add a binding to their Worker’s config file to initiate SQL queries:
// wrangler.jsonc file
{
"hyperdrive": [
{
"binding": "DATABASE",
"id":
}
]
}
Subsequently, developers can execute SQL queries via their 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");
...
}
PlanetScale developer experience
PlanetScale emerges as the ideal partner for the Workers community, offering unmatched performance and reliability. Developers can select from two widely used relational databases: Postgres or Vitess MySQL. This alignment reflects Cloudflare’s commitment to prioritizing performance and reliability as core attributes of its developer platform. With features such as query insights, agent-driven workflows for optimizing SQL query performance, and branching for safe code deployments—including database changes—the PlanetScale developer experience is truly exceptional.
Cloudflare users will enjoy the same high-quality PlanetScale database experience. Their PlanetScale databases can be deployed directly from Cloudflare, with connections managed through Hyperdrive, which enhances the speed of existing regional databases when paired with global Workers. This integration allows access to the same PlanetScale database clusters at standard PlanetScale pricing, inclusive of all features such as query insights and detailed usage and cost breakdowns.
A single node on PlanetScale Postgres starts at /month.
Workers placement
By utilizing centralized databases, Workers can be positioned in close proximity to the primary database, thereby minimizing latency through an explicit placement hint. Typically, Workers execute closest to user requests, which can introduce network latency when querying a central database, especially for multiple queries. However, developers can configure their Workers to operate in the nearest Cloudflare data center to their PlanetScale database. In the future, Cloudflare plans to automate the placement hint based on the location of the PlanetScale database, potentially reducing network latency to single-digit milliseconds.
{
"placement": {
"region": "aws:us-east-1"
}
}
Coming soon
Developers can currently deploy a PlanetScale Postgres database or connect an existing one to Workers via the Cloudflare dashboard, with all billing still processed through PlanetScale. However, starting next month, new PlanetScale databases will be billed directly to Cloudflare accounts. Further enhancements are on the horizon, including Cloudflare API integration, and feedback from the community is encouraged to shape future developments.