I built K2-Chat because I wanted a private way to run multimodal LLMs: text, audio and images without sending data to third-party APIs. It sounded straightforward. Six months of gRPC, distributed tracing and memory leaks showed me how different production infrastructure is from a research prototype.
Where the Simple Approach Breaks
The tutorials all show the same pattern: frontend talks to API, API talks to model. That works for a text-only chatbot. K2-Chat needed a single request to do all of this, for concurrent users:
- Processing an audio file through Whisper for transcription
- Running vision analysis on uploaded images
- Streaming text tokens from a language model
- Persisting the entire conversation to a database
Doing that synchronously in one monolithic API means timeouts. I split the system into three services that talk over gRPC.
Why gRPC Over REST?
I chose gRPC with Protocol Buffers for service-to-service calls. Coming from REST, the learning curve was steep, but the numbers convinced me:
- Binary serialization: Protobuf messages are roughly 60% smaller than equivalent JSON
- HTTP/2 multiplexing: Multiple requests share a single connection without head-of-line blocking
- Strict contracts: Generated types kept the Python services and the gateway in sync as the API evolved
Multimodal Inference on a Budget
Running SmolLM, Gemma, and Whisper together on a 4GB EC2 node meant lazy-loading models on demand and aggressively caching HuggingFace weights. Cold starts dropped by 98% once models stayed warm between requests instead of reloading from disk on every call.
Observability From Day One
OpenTelemetry and Jaeger traces on every request path found thread-blocking bottlenecks that average latency numbers hid. Flame graphs turned “it feels slow sometimes” into a specific line of code blocking the event loop during streaming responses.
Security and Multi-Tenancy
Row Level Security in Postgres (via Supabase) enforces tenant isolation at the database layer rather than trusting application code to filter every query correctly. Together with SSR cookie-based sessions and OAuth 2.0, this ruled out a whole class of authorization bugs.
What I’d Do Differently
I would introduce the gRPC service boundaries earlier instead of starting monolithic and splitting later. The refactor cost more time than designing for it up front would have.