Turns out Rust really might take over everything.
I never really planned on becoming a Rust evangelist, yet here we are.
Some names first. When you upload imagery to Sarkoa, a processor converts it into a Cloud Optimized GeoTIFF (a COG: a big image file laid out so small pieces can be read on their own). Later, when someone opens the map, a tiler reads pieces of that COG and draws the small square images (tiles) the browser shows. The pieces inside a COG are compressed, and the code that squeezes and un-squeezes an image is called a codec.
A little while back I ran into an embarrassing bug: the default raster format coming out of my own upload processor was the exact format my tile server couldn’t decode. Within a week I’d replaced the entire TypeScript raster tiler with Rust compiled to WebAssembly (WASM), which is a way to run code written in a language like Rust in places that normally only run JavaScript. Day one wrapped libwebp; day two I ripped that out for a pure-Rust WebP decoder; day three the rest of the codecs went in; by the end of the week the old TypeScript tiler was dead.
How my own defaults broke my tiler
The old TypeScript tiler used a library called geotiff.js to read COGs. WebP is an image compression format, like JPEG but smaller. Whenever geotiff.js hits a WebP-compressed piece (GDAL compression code 50001), it doesn’t decode it itself. It asks the web browser to do it, through a browser feature called createImageBitmap. Problem is, my tiler doesn’t run in a browser. It runs on Cloudflare Workers, whose engine (workerd) is not Chrome - createImageBitmap doesn’t exist there, so decoding crashes immediately with Cannot decode WebImage as createImageBitmap is not available.
You can trigger the exact crash with this tiny 1.7 KB test COG: geotiff.js 2.1.3 dies before producing a single pixel, while the Rust tiler decodes it cleanly (pixel (40, 3) comes back as RGBA (80, 6, 43, 255) with zero-alpha masking intact) and handles the full aerial survey above without blinking.
This wasn’t some rare edge case either. My processor writes WebP COGs by default for normal 3- and 4-band imagery because lossy WebP is 25–34% smaller than comparable JPEG. In other words, almost every standard raster uploaded to Sarkoa was broken out of the box.
That left three choices:
- Stop writing WebP COGs. Easy fix, except now I’m paying to store 30% bigger files forever just to babysit a JS library.
- Polyfill
createImageBitmapinside the Worker. Putting a hacked-up fake browser API right on my hottest code path sounded like a future nightmare. - Write a reader that doesn’t depend on browser APIs at all.
Option 3 was the only one that didn’t feel like sweeping the problem under the rug.
Why Rust (and why pure Rust)
Cloudflare Workers run WebAssembly nicely, and Rust already has solid, pure-Rust image codecs. “Pure Rust” ended up being the key part. A crate is a Rust library. Some crates are thin wrappers around older libraries written in C (like libwebp-sys), and those drag in a C-to-WASM cross-compiler setup I really didn’t want to maintain. Pure-Rust crates just compile to WASM like normal code.
The whole tiler comes down to four steps:
- Parse the TIFF’s table of contents directly (its IFDs, or image file directories - no
geotiff.jsat all). - Fetch only the blocks we need from R2 storage, with range requests (“send me bytes X to Y”).
- Decode them with pure-Rust crates:
image-webp,flate2(Rust backend),weezl(LZW), andjpeg-decoder. - Encode the output tile as lossless WebP (VP8L).
Why lossless output? Lossy compression throws away detail you probably won’t notice to make a file smaller. Lossless compression gives back exactly the pixels that went in. The old tiler spit out lossy WebP at quality 70. On aerial photography you barely notice, but on a classified raster where exact RGB values map to legend categories, lossy compression subtly nudges pixel colours until they don’t match the legend anymore. Lossless tiles cost a bit more bandwidth, but every pixel that reaches the browser is bit-for-bit what the tiler rendered - alpha channel included.
Pan around the Clearview survey above - every tile you see is coming straight out of that Rust Worker. Open the full map.

