From gRPC to LLMs: How to Choose an API Gateway
Table of Contents
When your system needs to handle inter-microservice communication, cross-language calls, and large model requests at the same time, the API gateway is no longer a simple routing tool, but a traffic hub for the entire infrastructure. This article records my step-by-step in-depth comparison of APISIX, Kong and Envoy when selecting a gRPC consistent hash load balancing solution. I hope it can provide a reference for you who are also faced with complex gateway selection.
1. Scenarios and requirements #
Our business involves three areas at the same time:
- Communication between microservices: Based on gRPC, multi-language heterogeneous (Go/Java/Python)
- High availability and elasticity: Consistent hashing is required to achieve session persistence/cache affinity
- New business exploration: Need to connect with multiple LLM vendors (OpenAI, Anthropic, Google Vertex AI, etc.)
Therefore, our gateway needs to have the following capabilities at the same time:
- gRPC proxy: supports HTTP/2, TLS, retry, timeout
- Consistent Hash: Stable key based on header/cookie/caller
- Multi-language friendly: Avoid implementing complex logic on the client side
- LLM extension: Token current limiting, multi-vendor routing, content security
2. Overview of gRPC consistent hashing scheme #
Before entering into specific product comparisons, let us first clarify the three mainstream paths in the industry.
Solution 1: gRPC client Balancer plug-in #
- scheme:
grpc-javabuilt-inring_hash,grpc-gois implemented using the community (such asauthzed/consistent) - Advantages: Lightweight, no independent agent required
- Disadvantages: Client heterogeneous maintenance costs are high, and cross-language consistency is difficult to ensure
Solution 2: Independent proxy (Envoy/HAProxy/Nginx) #
- Solution: Envoy provides Maglev / Ring Hash load balancing strategy
- Advantages: Stable, mature, and highly observable
- Disadvantages: Requires independent deployment and maintenance
Solution three: API gateway (APISIX/Kong) #
- solution: APISIX native support
scheme: grpc+type: chash - Advantages: It has both gateway management capabilities and load balancing
- Disadvantages: The gateway itself requires operation and maintenance
Our conclusion: In the K8s environment, the API gateway mode is the optimal solution - it not only unifies the entrance, but also provides a foundation for subsequent expansion.
3. APISIX vs Kong: First round comparison #
| Dimensions | APISIX | Kong (open source) |
|---|---|---|
| configuration storage | etcd (effective in milliseconds) | PostgreSQL (polling, with delay) |
| Cloud native adaptation | native CRD, Ingress Controller | supports K8s, but is not native |
| performance (P99) | ~1-3ms overhead | ~2-5ms overhead |
| plug-in quantity | 100+ built-in | ~40 built-in |
| plug-in development language | Lua / Java / Go / Python / Wasm | Lua (open source version) |
| Business version | API7 | Kong Enterprise (feature-rich) |
Conclusion: APISIX is more suitable for cloud-native and dynamic environments; Kong is more suitable for traditional enterprises, teams that rely heavily on PostgreSQL and mature ecosystems.
4. Join Envoy: Three pillars #
| Dimensions | APISIX | Kong | Envoy |
|---|---|---|---|
| product positioning | high performance gateway | Enterprise-level API management platform | L4/L7 agent (data plane) |
| works right out of the box | ✅ With control surface and UI | ✅ With control surface and UI | ❌ Need to cooperate with Istio / Envoy Gateway |
| Configuration dynamics | millisecond level | Second level / heavy load | xDS protocol, millisecond level |
| Performance | high | Medium | Ultimate (C++) |
| Learning Curve | Medium | Medium | high |
| applicable scenarios | Gateway + Grid Edge | API Management + Developer Portal | Service Grid + High-Performance Agent |
Conclusion: Envoy is a “limb” that requires a “brain” (control plane) and is suitable for Service Mesh scenarios; APISIX and Kong are complete products and suitable for independent deployment.
5. LLM scenario: new variables #
When LLM traffic enters the system, the gateway has another layer of responsibilities:
- Multi-vendor agent: unified access to OpenAI / Anthropic / Google / domestic models
- Token perception: token-based current limiting and cost control
- Intelligent routing: Dynamically select backends based on model performance/cost/content
- Content security: Prompt words/security audit of output
- Cache affinity (the importance of consistent hashing): Maximize the use of KV cache and reduce latency and cost
Consistent hashing has a new meaning in the LLM scenario - routing requests with the same prefix to the same backend can reuse KV Cache, directly reducing latency and inference costs. Product comparison in
LLM scenario #
| product | LLM positioning | Key capabilities |
|---|---|---|
| Envoy AI Gateway | AI native gateway | 16+ LLM provider, MCP protocol, stable version has been released |
| APISIX | A versatile all-rounder | ai-proxy / ai-proxy-multi / prompt word security / token current limit |
| Kong | AI extension of traditional capabilities | ai-proxy plug-in, advanced AI capabilities are only available in the enterprise version |
6. Final selection decision matrix #
flowchart TD
Start[核心需求是什么?] --> Q1{传统微服务<br/>gRPC + 一致性哈希?}
Q1 -->|是| APISIX[推荐:APISIX<br/>开箱即用,云原生友好]
Q1 -->|否| Q2{需要 Service Mesh<br/>统一南北+东西流量?}
Q2 -->|是| Envoy[推荐:Envoy + Istio<br/>或 Envoy Gateway]
Q2 -->|否| Q3{需要开发者门户<br/>+ 企业治理?}
Q3 -->|是| Kong[推荐:Kong 企业版<br/>生态成熟,功能全面]
Q3 -->|否| Q4{LLM 流量是主要场景?}
Q4 -->|是| AIGW[推荐:Envoy AI Gateway<br/>AI 原生设计]
Q4 -->|否| Q5{需要统一管理<br/>传统 API + LLM?}
Q5 -->|是| APISIX2[推荐:APISIX<br/>一个平台覆盖所有]
Q5 -->|否| Envoy2[推荐:Envoy<br/>极致性能 + 高度定制]
Recommended according to demand scenarios #
| demand scenario | recommended solution | Core reasons |
|---|---|---|
| Traditional microservices + gRPC + consistent hashing | APISIX | works out of the box, has excellent performance and is cloud-native friendly. |
| Microservices + Future Service Mesh | Envoy + Istio / Envoy Gateway | Unify north-south + east-west traffic |
| API Management + Developer Portal + Corporate Governance | Kong (Enterprise Edition) | has mature ecology and comprehensive functions |
| LLM gateway independent construction | Envoy AI Gateway | AI native design, active community |
| Unified management Traditional API + LLM traffic | APISIX | One platform covers everything, rich plug-in ecology |
| Extreme performance + high degree of customization | Envoy | C++ core, strong programmability |
Our final choice #
We chose Apache APISIX for the following reasons:
- Production verified gRPC + consistent hashing
- can manage traditional API and LLM traffic simultaneously
- The etcd architecture is naturally compatible with K8s, and the configuration takes effect in milliseconds.
- supports Java/Go development plug-ins, matching the team’s technology stack
- has no enterprise version function lock, and the cost is controllable
At the same time, we use Envoy AI Gateway as an independent evaluation item to reserve evolution space for the explosive growth of LLM traffic in the future.
7. Guide to avoid pits #
- Key selection for consistent hashing : Be sure to use stable identifiers such as
user_id,session_id,consumer, to avoidusingtimestamp,randomEqually volatile values - gRPC routing format:
urimust be/package.Service/Method, such as/helloworld.Greeter/SayHello - TLS configuration: gRPC encryption needs to be configured with
scheme: grpcsand the certificate must be mounted correctly - LLM Token current limit: Note that the current limit dimension is per minute/per token, not simple QPS
8. Write at the end #
There is no “silver bullet” for
gateway selection. The key is to match your scenario:
- gRPC + high performance + cloud native→ APISIX
- Service Mesh + Ultimate Performance→ Envoy
- Enterprise API Management + Mature Ecology→ Kong
- LLM native traffic→ Envoy AI Gateway
If possible, it is recommended to build the core POC verification scenario (gRPC forwarding + consistent hashing + LLM proxy) first, and then make the final decision based on the team’s operation and maintenance capabilities, technology stack, and cost.
The essence of technology selection is to find the optimal solution under constraints, rather than pursuing perfection in a vacuum.
Written by Jermine. View original text.