This is Part 1 of a 3-part engineering series unpacking Star Hunters, originally built during the NASA Space Apps Challenge 2026 in Kisumu (November 14-15, 2026) and heavily re-engineered over the two weeks that followed.

  • Part 1 (this article): The hackathon problem, our last-minute UI pivot, why naive scientific image serving collapses on the web, and the two-week journey into performance engineering.
  • Part 2: Multi-tier caching from browser to SQLite: coordinate grid snapping, popularity-aware cache eviction, on-the-fly half-precision compression, and the UX optimizations users feel without ever seeing.
  • Part 3: Fairness under load: splitting CPU and I/O thread pools in asyncio, building an aging priority semaphore to prevent starvation, and decoupling parallel network timeouts from CPU work.

The Problem: Spotting Moving Objects in the Dark

"Make it work, make it right, make it fast." (Kent Beck)

At the Kisumu hackathon, our team picked NASA's Planet X & SPHEREx track.

You don't need an astrophysics degree to appreciate the core computer-vision trick behind modern sky discovery. Wide-field space telescopes photograph the exact same patches of sky repeatedly over months or years (astronomers call each timestamped pass an epoch). If you align two snapshots taken months apart and subtract one image from the other, millions of distant, stationary stars cancel out to zero. What pops out of the dark are things that moved or changed brightness: nearby fast-moving stars, ultra-cold failed stars (brown dwarfs), comets, asteroids, or undiscovered outer-Solar-System worlds.

NASA's SPHEREx space telescope adds a second dimension to this diffing trick. Instead of taking a single RGB photo, it captures near-infrared light (0.75-5.0 µm, wavelengths just beyond human vision where cold, dusty objects glow) across 6 detector arrays and 102 narrow color channels.

Our goal was to turn a workflow that normally requires Python notebooks and multi-gigabyte desktop tools into an instant, approachable web app.

Our First Mistake, and the Last-Minute Redesign

Truthfully, when the 48-hour clock started, we didn't have a clear product vision for the UI.

Naturally, we looked at existing research portals, specifically Caltech's SPHEREx Mosaic Tool, and built our first prototype in that same mold:

Early Sky Flipbook prototype requiring raw decimal coordinates and specialist sliders

It worked as a technical demo, but stepping back, we realized we had built an instrument panel for specialists. The very first thing it asked a visitor for was six-decimal-place Right Ascension and Declination (astronomy's equivalent of longitude and latitude on the sky sphere) alongside raw contrast-stretch sliders and Julian timestamps. A curious student or developer opening the app wouldn't know what to type.

So late in the hackathon, we threw out the form-heavy dashboard and redesigned around an interactive 3D night-sky globe (powered by Aladin Lite v3):

Redesigned Star Hunters 3D sky globe with plain-text search, curated targets, and one-click detailed inspection

Instead of memorizing coordinates, users spin the sky, type "Saturn" or click "Zenith" (What's Above Me?), and jump straight into a visual frame comparator.

Why a Naive Proxy Backend Breaks Immediately

With the UI simplified, the backend suddenly had to hide a mountain of complexity.

Space archives don't serve web-ready PNGs. They serve FITS (Flexible Image Transport System) files, astronomy's decades-old raw scientific image format, similar to a multi-layer TIFF bundled with camera calibration matrices. If our FastAPI server simply proxied NASA's archive on every click, three things would break immediately:

  1. Multi-Second Upstream Stalls: Discovering exposures, downloading 18 multi-extension FITS files, subtracting background interplanetary dust glow (IMAGE - ZODI, known as zodiacal light), and warping rotated telescope exposures onto a shared pixel grid takes seconds per cold request. Public research archives also occasionally stall or return 503 errors.
  2. Bandwidth Blowup: Each aligned epoch in our binary wire contract is a (6, 256, 256) cube of 32-bit floats (1,572,864 bytes, ~1.5 MiB uncompressed) plus a (256, 256) uint8 pixel-hygiene mask (65,536 bytes) flagging cosmic-ray hits or dead pixels. Re-downloading megabytes every time a user drags a wavelength slider would make mobile connections unusable.
  3. Tiny Hosting Hardware: We deployed on a scale-to-zero Fly.io virtual machine (fly.toml): shared-cpu-2x (2 shared vCPUs), 2048 MB RAM, and a 2 GB persistent disk volume. On 2 vCPUs, a handful of simultaneous image-alignment jobs can easily starve interactive API calls or trigger an Out-Of-Memory (OOM) crash.

The 3-Layer Architecture

To keep the interface feeling instant on tiny hardware, we separated responsibilities across three layers:

Star Hunters 3-Layer System Architecture

1. Browser: Ship Raw Arrays Once, Compute Locally

Instead of asking the server to re-render JPEGs whenever the user adjusts a filter, FastAPI sends pre-gzipped binary float arrays once. Manifest endpoints carry a passive 7-day freshness header (X-Patch-TTL-Seconds), while content-addressed /frames/{grid_key}/{filename} responses ship straight from RAM or SQLite with 1-year immutable cache headers and zero recompression on the hot path.

Inside React, decoded Float32Array buffers live in a two-tier ClientPatchCache (RAM Map + browser IndexedDB) so frame blinking, image subtraction, and wavelength filtering run locally at 60 fps with zero network round-trips:

# Simplified from spatial_cache.py + backend_service.py # Full source: https://github.com/Eddy-Odero/star-hunters/blob/0ee8b82/backend/app/services/spatial_cache.py#L780-L868 IMMUTABLE_FRAME_HEADERS = { "Cache-Control": "public, max-age=31536000, immutable", "Content-Type": "application/octet-stream", "Content-Encoding": "gzip", "Vary": "Accept-Encoding", } def serve_gzipped_frame( grid_key: str, filename: str, precision: str = "float32", # "float32" or "float16" ) -> tuple[bytes, dict[str, str]]: dtype = "uint8" if filename.endswith("_flags.bin") else precision ram_key = f"frame_gz:{grid_key}:{filename}:{dtype}" # 1. Fast path: return wire-ready gzipped bytes directly from RAM LRU if cached_gz := mem_cache.get(ram_key): return cached_gz, {**IMMUTABLE_FRAME_HEADERS, "X-Binary-Dtype": dtype} # 2. SQLite stores only canonical gzip_float32 cubes (and gzip_uint8 masks). # Manifest routes enforce the 7-day patch TTL via X-Patch-TTL-Seconds; # frame blobs are read pre-compressed without decompressing on float32 hits. row = db.execute( """ SELECT bf.compressed_blob, sp.last_accessed FROM binary_frames bf JOIN sky_patches sp ON sp.grid_key = bf.grid_key WHERE bf.grid_key = ? AND bf.filename = ? """, (grid_key, filename), ).fetchone() gz_blob = bytes(row["compressed_blob"]) # 3. Slow-network fallback: downsample float32 -> float16 on the fly in RAM if dtype == "float16": raw_f32 = gzip.decompress(gz_blob) gz_blob = gzip.compress(float32_to_float16_bytes(raw_f32), compresslevel=1) mem_cache.put(ram_key, gz_blob) return gz_blob, {**IMMUTABLE_FRAME_HEADERS, "X-Binary-Dtype": dtype} 

2. FastAPI Backend: Resource Gates & Spatial Cache

Incoming coordinates snap to a 0.05° grid (3 arcminutes, about one-tenth the width of the full Moon) in spatial_cache.py so nearby clicks share cached work. Requests pass through a cold-miss rate limiter (12 misses/min/IP, 50/min globally), single-flight deduplication, a priority semaphore separating fast clicks from heavy CPU alignment, and a 1024 MB RAM + 1536 MB SQLite cache.

3. Parallel Archival Cascade (~10s Per-Provider I/O)

When a sky tile isn't cached, ArchivalResolver gives each upstream archive (NASA SPHEREx, WISE / NEOWISE, and NASA SkyView) its own independent 10.0s network I/O timeout while keeping local CPU work outside those network timers. If SPHEREx takes longer than 3.0s, WISE and SkyView downloads hedge in parallel on the I/O pool so combined wait time stays under 15 seconds, falling back to a Labeled Simulated Baseline only if every archive is unreachable.

Post-Hackathon: Looking Under the Hood of AI-Generated Code

During a 48-hour hackathon, speed of iteration wins, which meant a large chunk of our initial codebase was AI-generated under intense time pressure. It passed tests and got us across the finish line.

After the hackathon wrapped on November 15, I decided to open up that mostly AI-generated backend and profile what it was actually doing under load. That curiosity turned into a two-week deep dive into systems concepts I hadn't previously built from scratch in Python:

  • Designing an airgapped loopback stress-testing and memory-profiling suite (benchmarks/) to measure kernel Resident Set Size (RSS) and tail latencies reproducibly without hammering Caltech's servers.
  • Replacing a naive cache with Segmented LRU (SLRU) and time-invariant logarithmic decay so one user clicking random empty sky couldn't evict shared popular targets.
  • Vectorizing coordinate reprojection, dropping 3-pass image stacking from 4,865 ms down to 312 ms (15.6x faster) and cutting end-to-end cold-miss latency from 6.35s to 1.57s (4x faster) while halving peak memory per miss (+139.2 MB down to +69.7 MB between our November 16 baseline and current codebase).
  • Studying asyncio scheduling, thread-pool isolation, and counting/priority semaphores so interactive user clicks never queue behind heavy background jobs.

In Part 2, I'll walk through the first half of that post-hackathon journey: how spatial_cache.py and clientPatchCache.ts work together to build the kind of fast, resilient UX users appreciate precisely because they never have to notice it.