From 960 MiB to 9 MiB: Rewriting Three Quiet Lab Services in Rust
Nothing Was Broken — That Was the Problem
It was past two in the morning. Every practicum session for the day had wrapped up hours earlier. Zero students were taking a pre-test. Zero assistants were grading journals. The LMS was completely asleep.
Out of curiosity, we opened our Kubernetes metrics dashboard and sorted every running container by memory usage.
We expected the heavy hitters at the top: PostgreSQL, the main API, maybe the Next.js frontend. What we did not expect was an outbound proxy container sitting quietly at 833 MiB of working-set memory — occasionally spiking past 1,057 MiB — just to forward a handful of HTTP requests. Right below it sat our documentation site burning 96.5 MiB on a live Node.js server nobody was reading at 2 a.m., and our code-execution sandbox supervisor chewing through 30.5 MiB and 23.5 mCPU while running zero student notebooks.
Nothing was throwing 500 errors. No student had opened a support ticket. No page felt slow.
So why touch it at all?
Because university lab infrastructure does not run on an infinite cloud credit card. Our Seelabs platform — the LMS that runs practicum sessions, live proctoring, automated scoring, documentation, and in-browser Python sandboxes for the i-SMILE Laboratory at Telkom University — runs on a compact, shared Kubernetes cluster. Every gigabyte quietly eaten by an idle background service is a gigabyte unavailable when an entire cohort of students hits Start Pre-Test at the exact same second, or when a nightly batch job spikes memory while nobody is watching.
Silent idle waste is the most dangerous kind of technical debt: it never triggers an alert on a calm night, right up until the busiest exam morning of the semester.
That single 2 a.m. glance at kubectl top sparked a question that turned into one of the most satisfying engineering sprints we have done at the lab: what happens if we rewrite only the exact pieces that shouldn't be paying a heavy runtime tax — in Rust?
The Rule Before Writing a Single Line of Rust
Rewriting software in Rust is famously tempting and notoriously easy to get wrong. Do it for the hype, and you end up spending three months porting business logic that a team of rotating student lab assistants still has to maintain next semester.
Before we created a single Cargo.toml, we drew a strict three-part boundary. A service only qualified for a Rust rewrite if all three were true:
We own it end-to-end. No fighting upstream third-party internals we can't control or test.
Its runtime overhead outweighs its domain logic. If a service spends 95% of its memory hosting a VM, garbage collector, or general-purpose desktop daemon just to shuffle bytes or serve static files, it is a textbook systems-programming workload.
We can verify parity before cutting over. Every endpoint, wire protocol, and failure mode had to be testable in isolation and roll out with zero downtime.
Three services cleared that bar immediately: warp-proxy, seelabs-docs, and python-runner.
One major service — our core FastAPI backend, seelabs-api — deliberately did not. (More on why that decision mattered just as much as the rewrites.)
An 833 MiB Proxy That Only Needed 2 MiB
Our first target was the elephant on the metrics dashboard: warp-proxy.
Seelabs integrates with external campus services that require stable, clean outbound routing. Previously, that pod bundled two separate worlds inside a single container: Cloudflare's full official Linux client daemon (warp-svc) paired with a gost proxy sidecar to expose HTTP and SOCKS5 to the cluster.
It worked reliably — at a staggering cost. Even when forwarding zero bytes, the container averaged 833 MiB of working-set memory (822 MiB RSS, peaking over 1 GiB) and 25.0 mCPU of constant background churn. We were essentially running a full consumer VPN desktop stack inside Kubernetes just to forward outbound TCP sockets.
The replacement took a radically simpler route: let Linux do the cryptography, and let Rust do the plumbing.
Instead of emulating a full client daemon in userspace, we built a single, purpose-built Rust binary backed by tokio and rustls:
The WireGuard tunnel (
wg0) runs natively inside the Linux kernel via standard netlink configuration — zero userspace packet-copy overhead.Outbound sockets from our proxy are tagged with Linux
SO_MARKpolicy routing so proxied traffic flows cleanly throughwg0while Kubernetes cluster traffic stays untouched.One lightweight async Rust listener serves both HTTP
CONNECTand SOCKS5 on a single port, sniffing the first byte of each connection to route the protocol transparently.
We deployed the new Rust pod alongside the legacy proxy as a canary, ran live end-to-end integration traffic through it, flipped the upstream proxy URL, verified zero dropped requests, and removed the old deployment. Zero downtime.
The moment the metrics refreshed, we double-checked the units to make sure we weren't misreading kilobytes for megabytes:
Working-set memory:
833 MiB(peak1,057 MiB) →2.1 MiB(−99.7%, a397×reduction)Resident memory (RSS):
822 MiB→0.5 MiBIdle CPU:
25.0 mCPU→0.6 mCPU(−97.6%,42×lower)
Nearly 831 MiB vanished from the cluster in a single rollout.
Docs Shouldn't Need a Node.js Server at 3 a.m.
Target number two was seelabs-docs — our Fumadocs documentation portal covering practicum workflows, architecture guides, and assistant handbooks.
Out of the box, modern documentation frameworks ship as full Next.js server-rendered apps. That meant keeping a warm Node.js runtime alive 24 hours a day — holding 96.5 MiB of working-set memory (peaking at 120.6 MiB) inside a 131.9 MB container image — even though 99% of our docs don't change between deploys.
Wait: why did we have a server at all? Only two features on the entire site were genuinely dynamic:
Instant
Cmd+Ksearch across all documentation pages.Ask AI, our interactive documentation assistant that streams answers over the Vercel AI SDK v6 wire format.
Everything else — all 390 rendered HTML pages, stylesheets, scripts, and assets — was completely static.
So we split build time from run time. At build time, Next.js compiles the entire documentation site into a pure static export plus a compact JSON search corpus. At run time, Node.js is completely gone. A single compiled Rust binary built on axum handles everything:
Serves pre-compressed static pages and assets directly from disk with strict caching headers.
Loads the search corpus once at startup into an in-memory BM25 full-text index, answering
Cmd+Kqueries in sub-millisecond time with zero external search engine.Handles the Ask AI streaming endpoint natively in Rust, speaking the exact same Vercel AI SDK v6 streaming protocol so the frontend didn't even know the backend changed languages.
The live production drop was immediate:
Working-set memory:
96.5 MiB(peak120.6 MiB) →6.1 MiB(−93.7%,16×lower)Resident memory (RSS):
91.8 MiB→5.3 MiBContainer image size:
131.9 MB→45.0 MB(−66%)Kubernetes sizing: comfortably runs with
16 MiBmemory request and a64 MiBceiling.
The Hidden Idle Tax Inside a Python Supervisor
Our third target, python-runner, turned into the best detective story of the entire project.
Inside Seelabs, students open an in-browser Python window during practicum journals and coding assessments, complete with scientific libraries like numpy, matplotlib, and scikit-learn. A dedicated python-runner service manages those isolated execution sessions.
At idle — zero students coding, zero notebooks running — python-runner sat at 30.5 MiB of working-set memory (peaking at 41.0 MiB) and burned 23.5 mCPU continuously. For a tiny FastAPI + Uvicorn wrapper, 23.5 millicores of constant idle CPU made no sense.
When we profiled where those CPU cycles were actually going, we caught two invisible culprits hiding in plain sight:
An anxious watchdog. A background loop was walking Linux's
/procfilesystem four times every second to enforce memory limits — even when the active session table was completely empty.The Kubernetes health-probe tax. Every 10 to 20 seconds, Kubernetes ran an
execprobe that forked a brand-newpython -cinterpreter from scratch just to open a localhost socket, hit/health, and immediately exit. Across a day, the cluster was booting and tearing down thousands of Python interpreters purely to ask "are you still awake?"
Here was the key insight: students still need Python 3.13. Nobody wants to rewrite numpy or matplotlib in Rust. What didn't need to be Python was the long-lived HTTP/WebSocket control plane sitting on top of those sandboxes.
So we built a hybrid architecture:
The control plane became Rust: a
1.1 MBstatically linkedmuslbinary (tokio+axum) that manages session lifecycles, streams stdout/stderr over WebSockets, enforces timeouts and cgroup/memory guardrails, and launches isolated Python 3.13 worker kernels on demand.Zero-syscall idle fast-path: when zero student sessions exist, the resource watchdog sleeps completely — zero
/procscans, zero wasted wakeups.Native
--healthcheckmode: Kubernetes probes execute the same tiny static Rust binary with--healthcheck. No Python startup, no dynamic linker overhead — it connects, verifies/health, and exits in roughly a millisecond.
The result gave us the best of both worlds — full Python 3.13 scientific compatibility for students, with a near-zero footprint for the cluster:
Working-set memory:
30.5 MiB(peak41.0 MiB) →1.0 MiB(−96.7%,30×lower)Resident memory (RSS):
12.6 MiB→0.4 MiBIdle CPU:
23.5 mCPU→6.5 mCPU(−72.3%,3.6×lower)
The Production Benchmarks
Every figure below comes directly from live Kubernetes telemetry in production — measured over steady-state windows before and after each rollout, not synthetic laptop microbenchmarks.

Here is the exact side-by-side scorecard across all three services:
Service Working Set (Avg -> After) RSS (Avg -> After) Idle CPU (Avg -> After)
-----------------------------------------------------------------------------------------------
warp-proxy 833.0 MiB -> 2.1 MiB (-99.7%) 822.0 -> 0.5 MiB 25.0 -> 0.6 mCPU (-97.6%)
seelabs-docs 96.5 MiB -> 6.1 MiB (-93.7%) 91.8 -> 5.3 MiB Image: 131.9 -> 45.0 MB
python-runner 30.5 MiB -> 1.0 MiB (-96.7%) 12.6 -> 0.4 MiB 23.5 -> 6.5 mCPU (-72.3%)
-----------------------------------------------------------------------------------------------
TOTAL (3) 960.0 MiB -> 9.2 MiB (-99.0%) 926.4 -> 6.2 MiB 48.5 -> 7.2 mCPU (-85.2%)
Peak RAM: 1,219.0 MiB -> 9.2 MiB (104x lower avg working set | ~951 MiB reclaimed)Together, all three rewritten production services now consume 9.2 MiB of working-set memory — less than a single open browser tab — and sit at the very bottom of our entire cluster's memory list.
Reclaiming nearly a full gigabyte of steady-state RAM and cutting idle CPU by 85.2% wasn't just a pretty graph. It changed the headroom of the entire cluster. Scheduling new rollouts stopped feeling tight, memory pressure dropped across worker nodes, and peak exam traffic gained nearly a gigabyte of breathing room without buying a single new server.
Knowing When Not to Use Rust
After watching three services shrink by 16×, 30×, and 397×, the obvious next question was impossible to ignore:
"Should we rewrite seelabs-api in Rust too?"
We looked closely at the numbers — and said no.

Our core API is not a thin network plumber. It is over a hundred FastAPI endpoints, thousands of lines of SQLAlchemy 2 ORM models, Alembic schema migrations, background scheduling, Excel/PDF generation, recruitment pipelines, and rapid semester-by-semester feature work maintained by student lab assistants. Rewriting that codebase in Rust would freeze product development for months, multiply onboarding friction for every new cohort of assistants, and buy very little compared to fixing the actual Python and Kubernetes bottlenecks right in front of us.
Instead, we spent one focused engineering pass tuning seelabs-api inside Python — and verified every metric honestly:
Lazy-loading heavy startup modules: Deferring
openpyxl,pypdfium2,alembic, and 27 historical seed modules out of the eager import path trimmed 20–35 MiB per pod of real, unswapped baseline RSS.A crucial benchmarking sanity check: Our very first post-deploy reading looked almost too good to be true (
83–149 MiBworking set). Checking Prometheuscontainer_memory_swapimmediately caught why: the kernel had pushed122–127 MiBof cold pages into swap on a busy node. Once we accounted for swap and measured after full warm-up, the true unswapped gain was20–35 MiB/pod— smaller than a headline stunt, completely honest, and rock-solid.Fixing silent database & scheduler churn: Moving missing-scan hydration filters into SQL
WHEREclauses with narrow column projections and guarding background jobs with PostgreSQL advisory locks cut steady-state API CPU by ~25% (29.3 → 21.9 mCPU).Right-sizing Kubernetes scheduling: Lowering CPU requests from
250mto100mper replica freed300m(−60%) of reserved cluster CPU across our two API pods, while addingmatchLabelKeys: [pod-template-hash]totopologySpreadConstraintsguaranteed rolling updates spread cleanly across worker nodes.
Best of all, paying close attention to live telemetry uncovered a silent failure waiting to happen.
At 03:30 WIB, our nightly scheduler runs ffmpeg to compress old proctoring violation recordings before storage cleanup. Watching the memory curve during that exact window revealed a sudden spike to 473 MiB — 92% of the pod's 512 MiB memory limit — while compressing 43 recordings. On a heavier exam week, that pod would have silently OOMKilled in the middle of the night. Raising the burst limit to 768 MiB — funded directly by the ~951 MiB we had just reclaimed from our three Rust migrations — eliminated the cliff before a single user ever felt it.
What This Taught Us
Looking back at the sprint, the real win wasn't just the 104× headline number. It was four engineering habits that stuck with our team long after the PRs were merged:
Measure what your system costs when nobody is using it. Idle overhead compounds across every replica, every node, and every quiet night — and quietly steals the safety margin you need during peak traffic.
Rust shines brightest on thin, long-lived infrastructure. Proxies, static/search servers, protocol bridges, and sandbox supervisors are where eliminating a heavyweight runtime pays back
15×to400×almost immediately.Hybrid beats ideological purity. Putting a
1.1 MBRust supervisor in front of Python 3.13 scientific kernels gave students zero disruption while stripping96.7%of idle RAM and72.3%of idle CPU.Verify your own good news — and know when to stop. Checking swap kept our API benchmark honest, inspecting the
03:30 WIBspike prevented a futureOOMKill, and resisting the urge to rewrite our core business API kept the lab moving fast.
Sometimes the best optimization isn't waiting for an outage to force your hand. It's opening the metrics dashboard at 2 a.m., asking why a quiet box needs a gigabyte of RAM to do nothing, and choosing the right tool for each layer of the stack.
Share


