Side project
Local Inference Gateway
A path from a browser to a local model on a Mac. The full-size model ran out of memory, so a quantized build took its place. Public traffic hits hosted functions and a tunnel, then a gateway on the Mac.
Process
- Plan
Use a local model from a browser without opening a port on the Mac.
- Design
Hosted function → tunnel → gateway path, with a bounded pool.
- Build
Node gateway, index batch separated from question answering.
- Ship
Pinned the model build and context in configuration so the stack comes back identically after a restart.
- Improve
Swapped to a quantized build and ordered the bottlenecks.
Overview
A path from a browser to a local model on a Mac. Public traffic sees hosted functions and a tunnel. Inference stays on a gateway and Ollama on the machine.
Why I built it
A large full model ran out of memory, so a Q4 quantized build replaced it. Several automation jobs called that model over HTTP, and long replies were cut off by timeouts.
When the model process stopped, every job that called it failed together. The browser should not open a port on the Mac. A gateway sits behind hosted functions and a tunnel.
System
Browser → hosted function → tunnel → Mac gateway → Ollama.
The gateway pool is eight. Bottlenecks hit the GPU first, then the pool, then the proxy.
The model is a Gemma Q4 build in Ollama. Context is 8192. Calls that wait for long replies got double the timeout.
See this in the system diagram
Architecture and data
The gateway forwards prompts. A batch that builds an index is separate from question answering. Large tables are scraped into the local model on a schedule. The web chat only asks that index.
Long replies lose a format marker that belongs at the end. If a title can still be read from the start, the marker is restored.
Stack
Ollama, Gemma Q4, a Node gateway, a tunnel, hosted functions.
Local run: ollama serve and the Node gateway.
Notes
Hard parts: the full model overflowed VRAM. If an environment variable pointed at the heavy build, it came back. There was a stretch where callers were restarted while the model was simply off.
What held: the public path does not expose a Mac port, and the GPU is the first thing that saturates. The same prompt can be typed in a browser while the model stays local.