6 min read
|
Saved February 14, 2026
|
Copied!
Do you care about this?
This article explains how to deploy DuckDB as a WebAssembly module within Cloudflare Workers, enabling SQL queries without a traditional database server. It details the limitations of Cloudflare Workers, the use of Emscripten's Asyncify to handle asynchronous calls, and provides setup and coding instructions for creating a SQL query API.
If you do, here's more
Running SQL queries directly in Cloudflare Workers is now feasible thanks to Ducklings, a lightweight DuckDB WebAssembly (Wasm) build tailored for serverless environments. This setup eliminates the need for a database server and avoids cold-start delays associated with external services. Ducklings leverages Emscripten's Asyncify to convert DuckDB's synchronous HTTP calls into asynchronous ones, making it compatible with the Workers runtime where synchronous I/O is unsupported. With Ducklings, users can execute full SQL queries, including JOINs and aggregations, as well as read remote Parquet files through an optimized package.
The package @ducklings/workers is approximately 9.6 MB gzipped. It comes with essential extensions for Parquet, JSON, and an HTTP file system (httpfs) baked into the binary, avoiding the need for runtime loading. Setting up the project requires a paid Cloudflare Workers plan due to the size of the Wasm binary. The article provides clear instructions for creating a new project, configuring necessary files, and writing the Worker code. Users can expose a SQL query API, allowing them to execute queries and return data in a structured format.
Ducklings also supports querying remote files in various formats, such as Parquet, CSV, and JSON, without additional configuration. For accessing private data, configuration for Cloudflare R2 or S3-compatible storage is straightforward, involving the creation of secrets to facilitate secure access. The article emphasizes the utility of returning results in Apache Arrow IPC format, which enables efficient data transfer for clients familiar with this format. Overall, Ducklings presents a powerful solution for running SQL queries within serverless architectures, making data processing more accessible and efficient.
Questions about this article
No questions yet.