Respan re-architected their AI gateway in Rust, adopting a small core and plugin-based approach after facing maintenance challenges with a large wrapper around LiteLLM. This new design emphasizes modularity, allowing developers to extend functionality for model providers, routing, and security through compile-time plugins, enhancing resilience and simplifying updates.
Read original on The New StackRespan initially built its AI gateway with extensive wrapper code around LiteLLM. This approach led to significant technical debt, particularly when a routine LiteLLM upgrade caused critical failures, highlighting the fragility of tightly coupled systems and the difficulty in debugging issues within large, complex codebases. This experience motivated a fundamental re-evaluation of their architectural strategy, pushing towards a more resilient and maintainable design.
Inspired by Nginx's architecture, Respan adopted a design centered around a minimal core gateway and a powerful plugin system. This decouples core gateway logic from specific functionalities like model providers, routing, and security controls. The plugins are compiled into the gateway binary, offering performance benefits but introducing considerations for build pipelines and supply-chain security.
System Design Insight
When designing systems with external dependencies, consider strategies like abstraction layers, version pinning, or a plugin architecture to isolate your core application from frequent or breaking upstream changes. This reduces the blast radius of external library updates.
Plugins in Respan's gateway are compiled directly into the executable, meaning adding new functionality requires rebuilding the binary. This choice offers runtime efficiency but necessitates a robust build and deployment pipeline. Furthermore, plugin order is crucial as early plugins can intercept or modify requests before others, impacting security and processing logic. Security is a key concern, as plugins run within the same process and can access sensitive data, emphasizing the need for diligent code review and dependency management, even in memory-safe languages like Rust.