Boost Microservice Performance: Replacing Spring Cloud Gateways with Higress
This guide explains how to adopt Higress, a high‑performance C++‑based cloud‑native gateway, to replace traditional Java gateways in Spring Cloud ecosystems and demonstrates blue‑green, canary, and A/B testing deployments on Kubernetes using Nacos for service discovery.
Motivation for Replacing Java‑Based Gateways
Traditional Java gateways such as Spring Cloud Gateway and Zuul rely on blocking I/O and suffer from Full GC pauses under high request volume. These characteristics increase response latency and can destabilise services, prompting the need for a cloud‑native, high‑performance alternative.
Higress Overview
Higress is an open‑source, cloud‑native API gateway from Alibaba that uses a C++ kernel. Benchmarks show 2–4× higher throughput compared with Java gateways. It integrates with multiple service registries (Nacos, Zookeeper, Eureka) and ecosystems (Spring Cloud, Dubbo, Sentinel, OpenSergo) and conforms to the Kubernetes Ingress/Gateway API.
Prerequisites
Deploy Higress and the Istio CRDs in a Kubernetes cluster (see the Higress deployment guide).
Deploy Nacos (see the Nacos quick‑start guide).
All components are assumed to run in a local Kubernetes cluster for the demonstration.
1. Service Discovery and Routing
1.1 Deploy a Spring Cloud Alibaba Sample
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-cloud-demo-v1
spec:
replicas: 1
selector:
matchLabels:
app: spring-cloud-demo
template:
metadata:
labels:
app: spring-cloud-demo
spec:
containers:
- name: server
image: higress-registry.cn-hangzhou.cr.aliyuncs.com/samples/spring-cloud-demo:v1
imagePullPolicy: IfNotPresent
env:
- name: NACOS_REGISTRY_ADDRESS
value: nacos-server.default.svc.cluster.local
- name: SPRING_CLOUD_NACOS_DEMO_VERSION
value: v1The deployment registers itself to Nacos using the environment variables NACOS_REGISTRY_ADDRESS (the Nacos service address) and SPRING_CLOUD_NACOS_DEMO_VERSION (the version label). The Spring Cloud application reads these variables via:
spring.cloud.nacos.discovery.server-addr=${NACOS_REGISTRY_ADDRESS}:8848
spring.cloud.nacos.discovery.metadata.version=${SPRING_CLOUD_NACOS_DEMO_VERSION}1.2 Configure a Nacos Service Source in Higress
In the Higress console, create a service source of type Nacos 2.x and provide the Nacos address, port, namespace and group. This enables Higress to discover services registered in Nacos.
Higress console URL: http://console.higress.io/
1.3 Create a Domain and Route
Define a domain demo.springcloud.com and a route named demo that forwards the path /version to the Spring Cloud service discovered in step 1.2.
1.4 Verify Routing
Map demo.springcloud.com to the cluster’s LoadBalancer IP (or local IP) and send an HTTP request to http://demo.springcloud.com/version. The service should return the version string (e.g., v1).
2. Blue‑Green Deployment
2.1 Deploy a New Version (v2)
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-cloud-demo-v2
spec:
replicas: 1
selector:
matchLabels:
app: spring-cloud-demo
template:
metadata:
labels:
app: spring-cloud-demo
spec:
containers:
- name: server
image: higress-registry.cn-hangzhou.cr.aliyuncs.com/samples/spring-cloud-demo:v2
imagePullPolicy: IfNotPresent
env:
- name: NACOS_REGISTRY_ADDRESS
value: nacos-server.default.svc.cluster.local
- name: SPRING_CLOUD_NACOS_DEMO_VERSION
value: v2After applying this manifest, Nacos will list two endpoints for the same service, each carrying a different version metadata (v1 and v2).
2.2 Define Subsets Based on Version
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: demo
namespace: higress-system
spec:
host: service-provider.DEFAULT-GROUP.public.nacos
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2This DestinationRule creates two subsets ( v1 and v2) that Higress can address via the version label.
2.3 Switch All Traffic to v2
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
higress.io/destination: service-provider.DEFAULT-GROUP.public.nacos v2
higress.io/ignore-path-case: "false"
labels:
higress.io/domain_demo.springcloud.com: "true"
higress.io/resource-definer: higress
name: demo
namespace: higress-system
spec:
ingressClassName: higress
rules:
- host: demo.springcloud.com
http:
paths:
- backend:
resource:
apiGroup: networking.higress.io
kind: McpBridge
name: default
path: /version
pathType: PrefixUpdating the higress.io/destination annotation routes 100 % of traffic to the v2 subset.
2.4 Verify and Roll Back
Send a request to confirm the response is from v2. To roll back, change the annotation back to ... v1.
3. Canary Release
3.1 Configure Weighted Traffic
metadata:
annotations:
higress.io/destination: |
80% service-provider.DEFAULT-GROUP.public.nacos v1
20% service-provider.DEFAULT-GROUP.public.nacos v2This splits inbound traffic: 80 % to v1, 20 % to v2. Adjust the percentages gradually to increase the share of v2 until it reaches 100 %.
3.2 Verify Canary Distribution
Issue multiple requests (e.g., 20) and observe that roughly 4 of them are served by v2, matching the configured weight.
4. A/B Testing (Header‑Based Routing)
4.1 Define an A/B Ingress
kind: Ingress
metadata:
annotations:
higress.io/destination: service-provider.DEFAULT-GROUP.public.nacos v2
higress.io/canary: "true"
higress.io/canary-by-header: "User-Agent"
higress.io/canary-by-header-pattern: ".*Android.*"
higress.io/ignore-path-case: "false"
labels:
higress.io/domain_demo.springcloud.com: "true"
higress.io/resource-definer: higress
name: demo-ab
namespace: higress-system
spec:
ingressClassName: higress
rules:
- host: demo.springcloud.com
http:
paths:
- backend:
resource:
apiGroup: networking.higress.io
kind: McpBridge
name: default
path: /version
pathType: PrefixThis route directs requests whose User-Agent header matches the regex .*Android.* to the v2 subset, while all other requests continue to hit v1.
4.2 Verify A/B Routing
Send a request with an Android User‑Agent and confirm the response comes from v2. Requests with other User‑Agents should still receive v1. After validation, replace the original demo route’s destination with v2 and delete the demo-ab Ingress to complete the rollout.
References
Higress installation guide (Helm): https://higress.io/zh-cn/docs/ops/deploy-by-helm/#%E6%94%AF%E6%8C%81-istio-crd%E5%8F%AF%E9%80%89
Nacos quick‑start (v2): https://nacos.io/zh-cn/docs/v2/quickstart/quick-start.html
Higress user quick‑start: https://higress.io/zh-cn/docs/user/quickstart
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Alibaba Cloud Native
We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
