Wouldn't it be cool to query any file you want?

Project date Geospatial engineering · Feature queries

Yes, it would be cool to run bounding-box and attribute queries against any uploaded file directly from the edge. Right up until Cloudflare Workers’ 128 MB memory limit taps you on the shoulder. (A Worker is the small program that answers each request. It gets 128 MB of working memory and not a byte more.)

When Sarkoa renders a map, vector tiles can simplify lines and strip unused columns. When someone asks “give me every feature inside this box with all its original attributes,” you have to go back to the source file - tiles might even split a single polygon in half across a tile border.

So I built a feature query endpoint that reads original GeoJSON uploads and slapped a 32 MB file-size cap on it. To make sure I hadn’t pulled that number completely out of thin air, I measured how much memory reading the file actually eats. GeoJSON is text. To filter it, the Worker first has to turn that text into objects it can work with (JSON.parse), and those objects live in the JavaScript engine’s working memory (V8 is the engine, the heap is its memory). Objects take more room than the text they came from. A 24.7 MB synthetic polygon file (40,000 parcels, 21 vertices and 4 properties each) ballooned to 72 MB in memory - 2.92× its size on disk.

Bar chart. The 24.7 MB test file takes 72.0 MB of heap once parsed. At the same ratio a file at the 32 MB limit takes about 93 MB, under the Worker’s 128 MB memory limit.

Synthetic test file (40,000 parcels, fixed seed, run in Node 24). Measurement script · Result.

Checking the headroom

In the polygon-file test Memory or size
Source file 24.7 MB
Heap used by the parsed data, median of five runs 72.0 MB
Ratio 2.92
Estimated heap for a 32 MB file at the same ratio about 93 MB
Worker memory limit 128 MB

At roughly 3× expansion, a 32 MB GeoJSON takes about 93 MB of RAM just to parse, leaving ~35 MB inside a Cloudflare Worker’s 128 MB cap for actually running the filter and building the response. (This was a local Node 24 check rather than a live Worker, and different vertex/property mixes will scale differently, so call 2.9× a sanity check rather than a hard law.) Anything bigger than 32 MB gets a clear error on queries, while the map viewer still renders it fine from prepared tiles.

Why paging alone doesn’t save you

The endpoint supports bounding boxes, attribute filters, choosing which fields to return, and paging. Even if you only ask for two rows with geometry stripped out (like a quick test against our synthetic Saskatchewan farm layer: 18 matched, 2 returned, Spring Wheat and Canola at 126.7 ha each - selected fields from the response), the Worker still has to open and parse the entire GeoJSON before it can hand back row one.

That’s why we enforce both limits: the 32 MB cap keeps the Worker from crashing on parse, and paging keeps the response payload small.

All posts