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.