R2 SQL: a deep dive into our new distributed query engine
Sep 25, 2025Yevgen Safronov, Nikita Lapkov, Jérôme Schneider

Summary
This post details the architecture and techniques behind R2 SQL, a serverless query engine for R2 object storage. It introduces the Query Planner, which uses Iceberg metadata (partition-level and column-level stats) to prune irrelevant data, and the Query Execution system, which distributes work across Cloudflare's network. Key innovations include a streaming planning pipeline that emits work units as they become available and a 'finish early' strategy enabled by ordering work units based on the query's ORDER BY clause and metadata statistics, allowing queries to complete after processing only a fraction of the data.
More from the Data Infrastructure & Analytics trail
- Introducing Cloudflare Basin: an open, serverless data platform, now generally available
- Introducing the Billable Usage API: programmatic cost visibility for Cloudflare
- Announcing the Monetization Gateway: charge for any resource behind Cloudflare via x402
- How we built Cloudflare's data platform and an AI agent on top of it
- Iran's Internet is partially restored, Cloudflare Radar data shows