Making a geospatial Google Drive; problems and solutions.

Project date Geospatial engineering · Data ingestion

Someone sends you a massive shapefile and just wants a link to a map. Simple request, right? Except that one file has to pull double duty: whoever uploaded it needs to be able to download the exact file they sent later, while anyone opening the map just wants to pan around one neighbourhood without waiting for a 500 MB download to finish.

A web map never loads a whole file. It loads tiles: small square pieces, each covering just the patch of map that is on your screen at that zoom. Pan a little and the browser fetches a few more.

The whole architecture of Sarkoa rests on a pretty simple trade-off: a file gets uploaded once, then read in tiny slices thousands of times. A standard 1080p screen only needs 12 to 20 tiles (512 px each) to fill the viewport. So it’s completely worth spending extra compute up front when a file arrives if it makes every map load after that fast and cheap.

How an upload actually moves

There are four players: the browser, the app (the website’s server), storage (Cloudflare R2, which holds files in folders called buckets) and the processor (a separate machine that does the heavy converting).

  1. The browser asks the app for a presigned URL - a one-time, short-lived web address that lets it put one file in one exact spot - and uploads straight to the *-source bucket.
  2. The app writes a row for the file in the database (Supabase) and pokes the processor’s /process endpoint, proving who it is with a shared password (a bearer secret).
  3. The processor pulls the file from R2, runs tippecanoe (for vectors) or GDAL (for rasters) - the two standard tools for cutting geodata into map-ready form - and writes the web-ready copy into a *-viewer bucket.
  4. When it’s done, it calls the app back and flips the file status from “Queued” to ready.

Eight steps between the browser, the app, object storage, the processor and the database, from asking for a signed URL to the file table showing Ready.

The app coordinates everything, but the actual file bytes never pass through it.

Keep big files off the app server

The lazy way is POSTing the upload straight to your app and forwarding it to storage. That doubles your bandwidth for no reason, and Cloudflare’s Workers limits cap request bodies at 100 MB on Free and Pro plans anyway. Presigned URLs solve that cleanly: the app hands the browser a short-lived ticket to PUT one file to one exact key in R2, then gets out of the way.

Callbacks instead of polling

Processing times are all over the map - anywhere from 2 to 30 seconds for a small vector file up to 5 to 90 minutes for a monster raster. Polling across that kind of range is miserable: poll fast and you hammer your server; poll slow and the UI feels broken. (Polling is asking “are you done yet?” over and over. A callback is the processor phoning the app once, when it’s done.) A simple callback when the job finishes is way cleaner, and the processor sends back everything it learned about the file in one shot: where the outputs are, the area the file covers, and the source CRS. The CRS, or coordinate reference system, is the rule that says where on Earth a file’s numbers point. Putting a CRS column right in the file table was a no-brainer - it’s the very first thing any GIS person checks when a layer shows up in the middle of the ocean.

Two buckets, two sets of keys

Original uploads and viewer copies live in completely separate buckets with separate credentials. The original belongs to the user and shouldn’t ever be touched; the viewer copy is disposable and can always be rebuilt. Giving the processor read-only access to *-source and write-only access to *-viewer means a bug in my conversion code can’t corrupt someone’s actual data.

What ends up in the viewer

Vector files (points, lines and shapes) get run through tippecanoe once and packed into a PMTiles archive: one file holding every tile, with an index at the front saying where each one sits. Rasters (grids of pixels, like imagery) go through GDAL and come out as Cloud Optimized GeoTIFFs, or COGs: ordinary GeoTIFFs laid out so a reader can fetch one small piece at a time, with overviews (smaller, pre-shrunk copies for zoomed-out views). Both formats let the browser ask storage for just a byte range - “send me bytes 5,000 to 9,000” instead of the whole file - which is how one neighbourhood loads without the other 500 MB. And because the untouched original is still sitting in the source bucket, if I change my mind about how Sarkoa renders layers six months from now, I can regenerate the viewer copies myself without asking anyone to re-upload a thing.

Getting a giant upload to survive a closed browser tab is its own problem, and its own post.

All posts