Keeping a giant GeoTIFF from blocking everyone else's uploads.
Every file uploaded to Sarkoa has to be converted before it can be drawn on a map. Uploads wait in a queue (a line), and a worker is a program that takes one job off the line, finishes it, and takes the next.
A small GeoJSON finishes processing in a few seconds. A massive raster warp (re-gridding a huge image into the projection web maps use) can lock up a worker for over an hour. Once that big job grabs a worker, the next upload has to sit in line - so the real lever I have is deciding who goes next when a worker frees up.
Earlier on, I moved upload processing into Redis queues with RQ (Redis holds the line, RQ is the Python library that hands jobs from it to workers) so conversions wouldn’t die if an API request timed out. To stop heavy batch jobs from starving paying accounts, I split that single line into five priority levels - think of five lines at the airport, where the agent always serves the first-class line first mapped to the organization’s plan: free accounts land at p0, stepping up one lane per tier to p4 for enterprise. Workers check p4 down to p0, and then drain the legacy single queue from before the rollout.
Worth calling out one intentional choice: the scheduler prioritizes by plan tier, not by file size. A small file and a huge file on the same plan land in the exact same lane, so a tiny upload on a lower tier (or one submitted later on the same tier) still waits behind an active warp.
Sanity-checking the routing rules
I wired up six unit tests against a simulated queue so I could verify the edge cases without waiting on real GDAL runs (test names, queue order, and plan mapping):
| Scheduler input | Result |
|---|---|
| A GeoJSON job assigned priority 3 | The worker payload and the chosen queue both retain level 3. |
| The same active job ID submitted again at level 4 | The scheduler returns the existing job ID and creates no second conversion. |
| A fresh job when all 100 places in the test’s combined queue are occupied | The scheduler reports that the queue is full; a higher priority doesn’t create more capacity. |
Priority decides who gets the next free worker, not how many workers exist - if the single worker is already busy, even a p4 job waits its turn until that warp wraps up.