Java API Gateways combine high performance with a broad feature set and excellent integration capabilities. They are often faster in real workloads than expected and benefit from the rich Java ecosystem.
This article explains what a Java API Gateway is, why it is special, and what its limitations are.
A Java API Gateway is an API gateway built entirely in Java, leveraging the countless libraries of the Java ecosystem. Unlike gateways based on Nginx that use embedded scripting engines for plugins and API functionality, a Java gateway is homogeneously implemented in Java. All components of a Java gateway from the HTTP protocol to OpenAPI validators are made with Java. This unified approach makes a gateway easy to extend, debug, and integrate with enterprise infrastructure. It also allows developers to configure and adapt core behavior without switching between languages or runtimes.
Well-known Java API gateways include Gravitee, Membrane, Apigee, and Spring Cloud Gateway.
Java provides a mature platform and a vast ecosystem of libraries. Many gateway features can be implemented simply by wrapping battle-tested Java libraries as plugins. This approach is typically faster and less error-prone than writing Lua scripts for a C-based reverse proxy such as Nginx.
Over the last 15+ years, gateways from multiple vendors have proven that Java is both reliable and performant in production.
A key advantage is integration of legacy technologies such as SOAP, WSDL and XML. Large organizations still rely on XML and SOAP-based Web Services, and Java offers a wealth of libraries for handling them. This makes it straightforward for Java API gateways to provide strong support for XML processing and Web Services integration.
A gateway’s CPU time is split between user time and system time. User time is spent running the gateway’s code; system time is spent by the operating system handling tasks such as network input and output. Unlike image editing or video rendering, API gateways do relatively little computation and a lot of input and output.
For a typical API gateway, system time accounts for about 70 to 80% of CPU time, with the rest spent executing Java code. Replacing Java with a faster language cannot eliminate the time the operating system spends handling network traffic. That limits the gains: even if the gateway’s own code took no time to run, the overall speedup would be limited. Gateways written in faster languages may be at most 20 to 40% faster than an optimized Java implementation.
Java gateways remain fast with API features such as OpenAPI validation and JSON transformation enabled. Plugins can reduce throughput severalfold, so realistic setups provide a more useful comparison than forwarding-only benchmarks.
With features enabled, Java-based gateways often outperform solutions that combine native code with interpreted scripts. Plugins written in another language, such as Lua, add cross-runtime overhead. A gateway built on a single platform, such as Java, avoids that overhead and can deliver higher throughput.
A higher memory footprint is the trade-off for Java’s ecosystem and extensibility. Typical Java gateways, e.g., Membrane, need 200–400 MByte for operation. If you deploy hundreds of sidecar micro-gateways, this may be too much overhead, but for a few central gateways it’s negligible.
Native image compilation (e.g., GraalVM) can further reduce startup and memory in specific scenarios.
Java has automatic memory management that makes it very stable and avoids crashes. To free memory, garbage collections must be executed. While unused objects are collected, the Java VM can pause and cause latency.
Garbage collection was a problem decades ago, but modern Java has solved it, so we get the advantages of a GC without paying a significant price.
As measurements show: Garbage collection has practically no effect on a Java API Gateways response times. At 1,000 requests per second, 999 out of 1,000 requests were answered in under one millisecond. Garbage collection briefly delayed about 2 in 3,000 requests, each by around one millisecond.1
Question: Can I run a Java API Gateway in Docker?
Answer: Yes. Java gateways run well in containers. Image size and memory usage are manageable for most deployments.
Question: What is the best deployment option for a Java API Gateway?
Answer: There is no single preferred option. A Java API Gateway can run in a container, directly on the Java Virtual Machine, inside a Java web server such as Tomcat, in an OSGi runtime, or on operating systems including Linux, Windows, and macOS.
Question: How do I extend a Java gateway?
Answer: You can extend a Java gateway with Java or JVM languages such as Groovy, or by using expression languages. See the documentation for examples.
Membrane API Gateway is a Java-based gateway with OpenAPI validation and legacy XML/SOAP support.
Start with the Quick Start and discover the potential of Java API Gateways, even when running in a Docker container.
Java is a registered trademark of Oracle and/or its affiliates. Membrane API Gateway is an open-source project by predic8 and is not affiliated with, endorsed by, or sponsored by Oracle.