Postgres-Compatible Motherduck Endpoint with Cloudflare Workers Achieves Sub-1 Second Cold Start Latency
Some numbers for those of us who obsess about milliseconds.
Massive kudos to the team that worked on postgres compatible endpoint for motherduck, esp making it work with cloudflare workers + hyperdrive. ๐ ๐ ๐
Being able to have a fully serverless frontend + api + db where end to end cold start latency is <1s end to end is wild! I'm seeing ~400ms end to end cold, and ~150ms warm. (An eye blink is 200ms)
Setup: local chrome browser -> cf edge server -> cf hyperdrive -> MD postgres endpoint
I am hitting cloudflare IAD datacenter, closest to us-east-1.
My machine (FL) to CF IAD roundtrip is 95ms. Measured with a worker that returns new Response("hi!")
worker PG connect warm 4-8ms. const client = new Client({ connectionString: env.HYPERDRIVE.connectionString }); await client.connect(); I couldn't get it to be any lower. In a worker the client must be connected for every request. Cold was 200ms+. Cloudflare hyperdrive does a great job at maintaining a connection pool.
worker -> MD SELECT 1 warm is 20ms. await pgClient.query('SELECT 1 as ping') . Cold was 100-200ms. I imagine that is the pulse wake up.
worker -> MD SELECT .. GROUP BY on 10M rows is ~80ms (cold) is 200-500ms (cold)
Seeing the setup work end to end on the free plan of both cloudflare + motherduck is v cool.
.png)