Monday, June 16, 2025
HomeJavaEvaluating Apache APISIX vs. Spring Cloud Gateway

Evaluating Apache APISIX vs. Spring Cloud Gateway


Apache APISIX has two deployment modes (truly three, however let’s not get into particulars): conventional and standalone.

In conventional mode, APISIX shops its configuration in etcd. APISIX provides a wealthy API to entry and replace the configuration, the Admin API. In standalone mode, the configuration is simply plain YAML. It’s the strategy for GitOps practitioners: you’d retailer your configuration in a Git repo, watch it by way of your favourite software (e.g., Argo CD or Tekton), and the latter would propagate the adjustments to APISIX nodes upon adjustments. APISIX reloads its configuration each second or so.

upstreams:
  - id: 1
    nodes:
      "catalog:8080": 1
  - id: 2
    nodes:
      "pricing:8080": 1

routes:
  - uri: /v1/merchandise*
    upstream_id: 1
    plugins:
      proxy-rewrite:
        regex_uri: ["/v1(.*)", "$1"]
  - uri: /costs*
    upstream_id: 2
    plugins:
      referer-restriction:
        whitelist:
          - catalog.me

global_rules:
  plugins:
    prometheus:
      prefer_name: true

Spring Cloud Gateway helps all configuration choices of standard Spring tasks, and they’re many. Nevertheless, “flat” configurations, reminiscent of .properties file(s) and setting variables, are error-prone:

spring.cloud.gateway.routes[0].id=merchandise
spring.cloud.gateway.routes[0].uri=http://catalog:8080
spring.cloud.gateway.routes[0].predicates[0]=Path=/v1/merchandise*
spring.cloud.gateway.routes[1].id=pricing
spring.cloud.gateway.routes[1].uri=http://pricing:8080
spring.cloud.gateway.routes[1].predicates[0]=Path=/costs*
spring.cloud.gateway.routes[1].predicates[1]=Header=Referer, http://catalog.me

IMHO, one ought to keep on with a hierarchical configuration, reminiscent of YAML – and keep in mind that I’m not too keen on YAML. Right here’s the identical configuration as above:

spring.cloud.gateway.routes:
  - id: merchandise
    uri: http://catalog:8080
    predicates:
      - Path=/v1/merchandise*
    filters:
      - StripPrefix=1
  - id: pricing
    uri: http://pricing:8080
    predicates:
      - Path=/costs*
      - Header=Referer, http://catalog.me

I imagine the YAML model leaves much less area for errors, particularly relating to indices.

Be warned that Spring purposes don’t reload their configuration by default when the latter adjustments. Whereas it’s attainable – and certainly, a few choices can be found – it requires coding. Right here‘s a superb tutorial on methods to obtain it.

As for Apache APISIX, you too can create replace and delete routes dynamically by way of the /actuator endpoint. Nevertheless, the API doesn’t provide a PATCH methodology: it is advisable replace the entire route in case of updates.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments