Cutting API response time by over a second

When your API handles 19 million requests, every millisecond matters.

Today I reduced my API response time by 1.1 seconds.

As a rough estimate, 1 million requests saved by 1.1 seconds equals nearly 12.7 days of total time recovered.

Here is how I achieved it:

  • Shifted accounting into waitUntil so usage and bandwidth logging no longer delay the response.
  • Merged usage and bandwidth recording into a single Durable Object call and transaction.
  • Eliminated a separate database round trip.
  • Aggregated cells per row in SQL, cutting repeated data transfer; the benchmark dropped from about 399 KB to 176 KB.
  • Combined metadata and page retrieval into one D1 call.
  • Activated Smart Placement in Wrangler so the worker sits near the database.

Cloudflare D1 read timing is in single digits, but the round trip adds triple-digit latency; that is the remaining bottleneck. Next, I would test the D1 read nodes.

Cloudflare Workers Metrics dashboard showing 19.53M invocations over the last 30 days.
Terminal curl timing output with x-tablecells D1 headers and a 363 ms total request time.