Running a Rust backend on Cloudflare Workers: what works and what bites.
A Rust backend on Cloudflare Workers is Rust compiled to WebAssembly and started by a small JavaScript entry script. It has no threads and no Tokio. That sounds restrictive, and in places it is. An axum router, a SQL database and sign-in still fit. Harness, our open-source backend, has run this way since the day it was started. These are the constraints we met, with Cloudflare's numbers and ours.
By Nick van der Meij · Published
Listen to this post
In short
- Workers run Rust as WebAssembly through the workers-rs crate. Every dependency has to compile to wasm32-unknown-unknown, and Tokio's threaded runtime does not run there.
- The Free plan allows 10 ms of CPU per request. One Argon2id password check took about 20 ms in our local test, so password login needs the paid plan.
- The example backend measured 3.50 MB as a WebAssembly file in September 2026. A warm build with one new module took 5.3 seconds.
- The same modules build as a native binary on Tokio with Postgres, so the Workers constraints are a starting point you can leave.
§1 · Shape
What a Rust Worker is.
Cloudflare supports Rust through its own crate, workers-rs. Your code compiles to the wasm32-unknown-unknown target, and in Cloudflare's words a Wasm Worker is “invoked from a JavaScript entrypoint script which is created automatically.” A tool called worker-build does the compile and the packaging, and wrangler deploys the result.
Harness made three choices on its first day and recorded them. The runtime is Workers through workers-rs. The router is axum, which workers-rs can serve directly. And the core depends on no Cloudflare crate at all. This is Shipping: it is how every Harness backend on Workers runs today.
§2 · Rules
The rule that shapes everything: it must compile to wasm32.
The workers-rs README puts it plainly: “you've got to leave your threaded async runtimes at home; meaning no Tokio or async_std support.” Every crate in the dependency tree has to build for wasm32-unknown-unknown. Anything that expects threads, a file system or native TLS is out.
A rule like that is easy to break by accident. One transitive dependency pulls in Tokio's runtime, mio or native TLS and the Worker stops building. So we made it a property of the code. The Harness core and every module may depend on http, axum, serde, tracing and pure-Rust crypto. They may not depend on worker, wasm-bindgen, tokio or std::fs. Only the runtime crates touch those. CI builds the example backend with worker-build on every commit, so a dependency that cannot target WebAssembly fails there.
The rule cost us real work once. The usual Rust library for passkeys, webauthn-rs, did not build for wasm32 when we tried it, because the version we tried (0.5.5) depended on OpenSSL. Version 0.6 has since dropped it. We verified passkeys on pure-Rust crates instead: p256, sha2, ciborium and coset. The spike that proved it was about 340 lines, and its decision record has the details.
§3 · Numbers
Cloudflare's limits, and what we measured against them.
| Limit | Free | Paid |
|---|---|---|
| CPU time per HTTP request | 10 ms | 30 seconds by default, up to 5 minutes |
| Memory per isolate | 128 MB | 128 MB |
| Worker size, uncompressed | 64 MiB | 64 MiB |
| Startup | 1 second | 1 second |
| Requests | 100,000 a day | 10 million a month included |
| Price | $0 | From $5 a month |
Those are Cloudflare's published figures. The one that decides most designs is CPU time on the Free plan. Ten milliseconds is plenty for a query and a JSON response. Hashing a password is another matter.
wrangler dev on an Apple Silicon machine and recorded in ADR 0200. These are local timings on one host.So password login in Harness needs the paid plan, and our capability table says so. Passkeys and sign-in with Google do not hash passwords.
Size turned out to be a smaller worry. Cloudflare's Rust page warns that unoptimised Wasm binaries can be large and slow to start. The example backend in the repository measured 3.50 MB in September 2026, with the page renderer mounted. Building for size with opt-level = "s" cut an earlier 2.66 MB build to 1.86 MB. Build time was not the problem we expected either: 26.7 seconds from cold, and 5.3 seconds warm with one new module crate, on a 14-core Mac. The method is in What a build actually costs.
§4 · Database
The database is SQLite, one thread at a time.
The SQL database on Workers is D1, and D1 is SQLite. Cloudflare caps a database at 10 GB on the paid plan and runs each one single-threaded. Its documentation does the arithmetic: at 1 ms per query, at most 1,000 queries a second.
That suits many small databases better than one large one, which is the subject of Database per tenant or shared schema. For Harness it also meant writing SQL that two engines accept. Migrations stay inside the subset SQLite and Postgres share, and every module's tests run against both in CI.
§5 · Exit
The way out is one line of composition, plus a data copy.
Because modules never touch a Cloudflare type, leaving Workers does not mean rewriting them. The native runtime serves the same axum router on Tokio. The portability guide shows the change in a backend's one composition file. This is its outline; the real constructors take their settings as arguments, and the guide lists the other steps:
// before
.runtime(Cloudflare::new().db("DB").mailer(Resend::from_env()).captcha(Turnstile::from_env()))
// after
.runtime(Native::new().db(Postgres::from_env()).rate_limiter(Redis::from_env()))
The data moves with fz data export and fz data import. The native runtime and the Postgres adapter are published crates. The many-tenant layer for the native runtime is Designed in an accepted decision record and unbuilt, so today one native process serves one backend.
§6 · Limits
What this does not solve.
Realtime does not run at the edge in Harness yet. The Realtime port and its in-process adapter work on the native runtime. The Durable Object adapter that would serve it on Workers is Designed in a public issue (#103) and unbuilt.
We have no performance numbers for Workers to offer. The benchmarks page lists cold start and warm read latency as unmeasured, and we would sooner publish a gap than a guess.
Some libraries will not come with you. If your backend leans on a crate that needs threads or a C library with no WebAssembly build, Workers is the wrong first target. Start on the native runtime.
And you still deploy it yourself. Cratefield, the managed service that would do the builds and deploys, is Planned and not running. What Harness is, and how it compares with the hosted backends, is in An open-source Rust backend, next to Supabase and Firebase.
Questions
Questions people ask about this.
- Can you use Tokio on Cloudflare Workers?
- Not on the standard target. The workers-rs README says you have to leave threaded async runtimes at home, meaning no Tokio or async_std support. Async and await still work through the
workercrate. The README also describes an experimental Emscripten build flag that brings Tokio timers and tasks. - Does axum work on Cloudflare Workers?
- Yes. The
httpfeature of theworkercrate uses the standardhttptypes, which the README says makes crates such as axum and hyper much easier to use. Harness serves an axumRouteron Workers, and the same router runs on Tokio in the native runtime. - How big can a Rust Worker be?
- Cloudflare's limits page gives 64 MiB uncompressed on both the Free and Paid plans, and says no compressed size limit applies. The tighter constraint is startup: a Worker must parse and run its global scope within one second.
- Is Rust on Workers faster than JavaScript?
- We do not know, and we make no claim. Harness publishes one measured figure, a local write benchmark, and lists cold start and request latency on Workers as unmeasured. Pick Rust here for the compiler and for portability.
Sources
Where the numbers come from.
- Workers limits, Cloudflare. Read on 30 November 2026.
- Workers pricing, Cloudflare. Vendor list prices, read on 30 November 2026.
- Rust on Workers, Cloudflare. Read on 30 November 2026.
- workers-rs README, Cloudflare. Read on 30 November 2026.
- D1 limits, Cloudflare. Read on 30 November 2026.
- ADR 0001: workers-rs on Cloudflare, axum as the router, runtime-agnostic core, Cratefield, 5 September 2026.
- ADR 0200: wasm32 crypto and WebAuthn on Workers, Cratefield, 6 September 2026. The Argon2id timings were measured locally in wrangler dev on an Apple Silicon host.
- What a build actually costs, Cratefield, 6 and 7 September 2026. Measured on one 14-core Mac.
- Published numbers, and the rules they follow, Cratefield.
- Portability: the move off Cloudflare, Cratefield.
Keep reading
- 01An open-source Rust backend, next to Supabase and Firebase.Harness is an open-source Rust backend you compile from MIT crates. What ships today, how it compares with Supabase, Firebase and PocketBase, and its limits.
- 02Database per tenant or shared schema: where each one fails.Database per tenant vs shared schema, with the numbers: what row-level security costs when a rule is missing, what many small databases cost, and D1's limits.