Skip to main content

02 / projects / hf-backend

HF Pluggable Gateway

Sub-100ms Pluggable Microservice Gateway. An aggregation API gateway designed to host and isolate independent Python micro-services inside a single container environment on Hugging Face Spaces, featuring pre-warmed models and dynamic request routing.

FastAPIDockerPython 3.11UvicornuvPyTorch
01Context

Problem & hardware constraints

An aggregation API gateway designed to host and isolate independent Python micro-services inside a single container environment on Hugging Face Spaces, featuring pre-warmed models and dynamic request routing.

02Layers

System architecture & pipeline

The runtime is structured into decoupled execution layers to avoid latency jitter and unpredictable heap fragmentation:

01/Edge Router & Health Probe

Intercepts incoming requests, routes them to specific sub-modules, and handles graceful wake-up signals.

02/Dependency Isolation

Uses uv for sub-second virtualenv resolution and module sandboxing inside the container.

03/Model Memory Pool

Pre-warms PyTorch weights into shared memory during container startup, preventing cold-hit spikes on first user queries.

03Decisions

Engineering trade-offs & alternatives rejected

Single container orchestration over multi-container cluster

Given free-tier host limits, running multiple Docker containers was impossible. Building an internal in-process router saved 400MB of overhead.

04Field Notes

Field notes & edge cases

  • 01The hardest part was not the routing logic. It was stopping two sub-packages from importing conflicting versions of transformers in the same Python process.

— / deploy

Explore source & live runtime

Source code, static headers, and benchmarks are open for review on GitHub.

Other systems

Keep exploring