Skip to main content

Serverless API


This feature is being actively developed as a technology preview under beta and is subject to change.


For serverless environments such as Cloudflare Workers or Vercel Edge Functions, TCP support is not readily available, being based on V8 isolates. These environments strive for lightweight, ephemeral compute where long lived database connectivity and connection pooling is somewhat of an anti-pattern. Serverless environments promise low latency by serving closer to users, but database connectivity problems stand in the way of this.

To enable such environments, PolyScale supports a lightweight API that processes SQL queries via HTTP. PolyScale initiates and maintains TCP connectivity to the origin database.


HTTP requests are accepted by PolyScale and the SQL extracted. A native TCP connection is then initiated to the database (if not already established) and pooled for later reuse.

This provides the benefit that PolyScale is closer to the serverless environment (edge function) and cache hits are served at very low latency at scale.


The design goal for the first iteration of the API is simplicity.

We plan to add additional features and compatibility with other platforms over time.

API Rate limit

The Serverless API is limited to 60,000 requests per minute. Need higher limits? Please contact us.

Client Library


import Client from "@polyscale/serverless";

const polyscale = new Client("", {
cacheId: "polyscale-cache-id",
username: "target-db-username",
password: "target-db-password",
database: "target-db-database",
provider: "mysql", // "postgres" | "mariadb" | "mssql"

polyscale.query("SELECT 1;").then((result) => console.log(result));

Connection Pooling

The Serverless API supports connection Pooling for all databases: Postgres, MySQL, MariaDB and MS SQL Server.

As part of the beta release, the pool size is limited to 2 connections per PolyScale Point of Presence (PoP). This value will be configurable in the future.

The timeout until stale connections are closed is 60 seconds, and like the pool size, will be configurable in the future.


Join the Discord here to keep up to date with the latest on the HTTP API and provide thoughts and feedback.