Skip to main content
Beato
  1. All Articles/

From gRPC to LLMs: How to Choose an API Gateway

·6 mins

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:

  1. gRPC proxy: supports HTTP/2, TLS, retry, timeout
  2. Consistent Hash: Stable key based on header/cookie/caller
  3. Multi-language friendly: Avoid implementing complex logic on the client side
  4. 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-java built-in ring_hash, grpc-go is implemented using the community (such as authzed/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 #

DimensionsAPISIXKong (open source)
configuration storageetcd (effective in milliseconds)PostgreSQL (polling, with delay)
Cloud native adaptationnative CRD, Ingress Controllersupports K8s, but is not native
performance (P99)~1-3ms overhead~2-5ms overhead
plug-in quantity100+ built-in~40 built-in
plug-in development languageLua / Java / Go / Python / WasmLua (open source version)
Business versionAPI7Kong 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 #

DimensionsAPISIXKongEnvoy
product positioninghigh performance gatewayEnterprise-level API management platformL4/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 dynamicsmillisecond levelSecond level / heavy loadxDS protocol, millisecond level
PerformancehighMediumUltimate (C++)
Learning CurveMediumMediumhigh
applicable scenariosGateway + Grid EdgeAPI Management + Developer PortalService 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 #

productLLM positioningKey capabilities
Envoy AI GatewayAI native gateway16+ LLM provider, MCP protocol, stable version has been released
APISIXA versatile all-rounderai-proxy / ai-proxy-multi / prompt word security / token current limit
KongAI extension of traditional capabilitiesai-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/>极致性能 + 高度定制]
demand scenariorecommended solutionCore reasons
Traditional microservices + gRPC + consistent hashingAPISIXworks out of the box, has excellent performance and is cloud-native friendly.
Microservices + Future Service MeshEnvoy + Istio / Envoy GatewayUnify north-south + east-west traffic
API Management + Developer Portal + Corporate GovernanceKong (Enterprise Edition)has mature ecology and comprehensive functions
LLM gateway independent constructionEnvoy AI GatewayAI native design, active community
Unified management Traditional API + LLM trafficAPISIXOne platform covers everything, rich plug-in ecology
Extreme performance + high degree of customizationEnvoyC++ core, strong programmability

Our final choice #

We chose Apache APISIX for the following reasons:

  1. Production verified gRPC + consistent hashing
  2. can manage traditional API and LLM traffic simultaneously
  3. The etcd architecture is naturally compatible with K8s, and the configuration takes effect in milliseconds.
  4. supports Java/Go development plug-ins, matching the team’s technology stack
  5. 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 #

  1. Key selection for consistent hashing : Be sure to use stable identifiers such as user_id, session_id, consumer, to avoidusing timestamp, random Equally volatile values
  2. gRPC routing format: uri must be /package.Service/Method, such as /helloworld.Greeter/SayHello
  3. TLS configuration: gRPC encryption needs to be configured with scheme: grpcs and the certificate must be mounted correctly
  4. 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.