light-4j is a free, open source api development & testing project written in Java and released under Apache-2.0. It has 3,676 GitHub stars, 623 forks and 15 open issues, and was last pushed 11 hours ago. On this registry it ranks #73 of 186 tracked projects in API Development & Testing, with 5 head-to-head comparisons available. It gained 3 stars over the last 30 tracked days.

What is light-4j?

light-4j is an Apache-2.0 licensed, Java-based open-source microservices framework built on the Undertow HTTP core for cloud-native and container deployment, intended for Java developers and platform teams that need high throughput and a small memory footprint rather than a heavyweight application server.

What it is

light-4j is a fast, lightweight and cloud-native microservices framework written in Java. It is built on top of the Undertow HTTP core and follows a set of principles published at doc.networknt.com. The author had worked on Java EE platforms since the early 2000s and ran into performance and productivity issues there; in 2014 it became clear that the industry was moving from monolithic to microservices architectures and from on-premise data centers to the public cloud, so the framework was started to get a small memory footprint, high throughput and low latency in Java.

The concrete problem it solves is the separation of business logic from technical cross-cutting concerns in a package that is genuinely designed for containers and the cloud. Java EE and Spring/Spring Boot are described in the README as too heavy for this purpose, and other lightweight Java platforms are criticized for mishandling that separation and for not being cloud-native. light-4j therefore replaces the Java EE and Spring/Spring Boot embedded Tomcat deployment model with an embedded gateway that handles OAuth2 JWT security, request and response validation, metrics, exception handling and other cross-cutting work, leaving service code to hold business logic. It lives in the Java ecosystem, with topics listing Java 8, Java 11, Docker, Consul and cloud-native.

Key capabilities

  • Embedded gateway built on a plugin architecture for startup and shutdown hooks and middleware components.
  • Distributed OAuth2 JWT security verification provided as part of the framework.
  • Request and response validation against an OpenAPI specification at runtime.
  • Metrics collected in InfluxDB or Prometheus and viewed from Grafana dashboards for both services and clients.
  • Global exception handling for runtime, API and other checked exceptions, sensitive data masking for items such as credit card and SIN numbers before logging, and cross-site scripting sanitization for query parameters, request headers and body.
  • Service registry and discovery support for direct, Consul and Zookeeper modes, plus client-side discovery and load balancing to eliminate proxies.
  • Body parser for different content types, standardized response codes and messages from the configuration file, externalized configuration for all modules, a CORS pre-flight handler for Angular or React single-page applications on another domain, and rate limiting for services exposed to the Internet.

Who uses it and how

  • Production deployments: the README states that many companies use light-4j in production with positive feedback.
  • Dockerized environments: externalized configuration for all modules keeps configuration outside the container image.
  • Internet-facing services: rate limiting is provided for services exposed outside the network.
  • SPA front ends hosted on another domain, served through the CORS pre-flight handler for Angular or React clients.
  • Discovery-based fleets coordinated through Consul or Zookeeper, with client-side load balancing and a client module tightly integrated with Light-OAuth2 that supports trace.

Getting started

The README excerpt gives no artifact coordinate, image name or run command; it points to documentation at doc.networknt.com and a contribution guide at doc.networknt.com/contribute/ as entry points. Dockerized deployment is implied by externalized configuration for all modules.

How it compares

Spring/Spring Boot embedded Tomcat and Java EE are named in the README as too heavy, while other lightweight Java platforms are faulted for weak separation of business logic from cross-cutting concerns and for not being cloud-native or designed for containers. The README claims light-4j is 44 times faster than Spring Boot embedded Tomcat and uses only one fifth of the memory, citing a benchmark repository and a third-party TechEmpower comparison.

When to use it — and when not to

A self-hoster must operate externalized configuration for all modules, a service registry (direct, Consul or Zookeeper), a metrics pipeline of InfluxDB or Prometheus with Grafana, and OAuth2 verification through Light-OAuth2 integration. Teams that want Spring Boot or Java EE conventions, a batteries-included monolith, or a non-Java stack should not pick it. The README excerpt is largely rationale and documentation links with no version, artifact or install detail, and the repository shows 15 open issues.

project readme (upstream, from github) — read inline

A fast, lightweight and cloud-native microservices framework.

Stack Overflow | Google Group | Gitter Chat | Subreddit | Youtube Channel | Documentation | Contribution Guide |

Build Status codecov.io

Why call it Light-4J

Light means lightweight, lightning fast and shedding light on how to program with modern Java SE for cloud-native deployment.

Why am I doing it

I had been working on the Java EE platforms since early 2000 and suffered the performance and productivity issues. In 2014, I realized that the IT industry was moving from Monolithic to Microservices and from on-premise data centers to the public clouds.

To reduce the production cost for my applications, I need to find a lightweight platform that has a small memory footprint, high throughput, and low latency in Java. Java EE and Spring/Spring Boot are too heavy to be considered. Other lightweight Java platforms all have different issues on the separation between the business logic and technical cross-cutting concerns. Moreover, they are not cloud-native or designed for container/cloud.

Without finding anything suitable, I started to build my open-source platform light-4j on top of the Undertow HTTP core by following the principles. Because my approach is very radical, and it is against products from big corporations, I have been attacked by some entities online and offline constantly. However, I am so convinced that my approach is the future direction and spend all my effort to continue the development. Today, a lot of companies are using light-4j on production with very positive feedback. It further encourages me to devote myself to the framework and to extend the platform to build an ecosystem.

For users who benefit from the platform, you can become a sponsor for me so that I can put all my effort into the open-source projects.

Why use this framework

Fast and small memory footprint to lower production cost.

It is 44 times faster than the most popular microservices platform Spring Boot embedded Tomcat and use only 1/5 of memory. Here are the benchmark results compare with Spring Boot and other microservices frameworks. Here is the third party comparison with other Web frameworks.

Provide an embedded gateway to address cross-cutting concerns.

  • Plugin architecture for startup/shutdown hooks and middleware components
  • Distributed OAuth2 JWT security verification as part of the framework
  • Request and response validation against OpenAPI specification at runtime
  • Metrics collected in Influxdb/Prometheus and viewed from Grafana Dashboard for both services and clients
  • Global exception handling for runtime exception, API exception, and other checked exceptions
  • Mask sensitive data like the credit card, sin number, etc. before logging
  • Sanitize cross-site scripting for query parameters, request headers and body
  • Audit to dump important info or entire request and response.
  • Body parser to support different content types
  • Standardized response code and messages from the configuration file
  • Externalized configuration for all modules for the dockerized environment
  • CORS pre-flight handler for SPA (Angular or React) from another domain
  • Rate limiting for services that exposed outside to the Internet
  • Service registry and discovery support direct, Consul and Zookeeper
  • Client-side discovery and load balance to eliminate proxies
  • A client module that is tightly integrated with Light-OAuth2 and supports traceability

Design and Test driven development to increase productivity

Design OpenAPI specification and generate the service from it. The specification is also part of the framework to drive security verification and request validation at runtime.

Unit/End-to-End test stubs are generated to enable test driven approach for quality product.

Debugging within IDE just like standalone application for better developer productivity.

Built-in DevOps flow to support continuous integration to production

Dockerfile and DevOps supporting files are generated to support dockerization and continuous integration to production.

Multiple frameworks for different type of microservices

  • light-rest-4j is a RESTful microservice framework with OpenAPI specification for code generation and runtime security and validation
  • light-graphql-4j is a GraphQL microservice framework that supports schema generation from IDL and plugin.
  • light-hybrid-4j is a hybrid microservice framework that takes advantages of both monolithic and microservice architectures.
  • light-eventuate is a messaging based microservice framework based on Kafka, event sourcing and CQRS

Multiple languages support

All the open sourced frameworks are built in Java and we are working on Nodejs framework internally. In the future, we might provide Golang framework as well and all them are sharing the same eco-system and market place.

OAuth2 server, portal and services to form ecosystem

OAuth2 Server for security and Portal for production monitor and management. The portal is also a marketplace to link clients and services together.

Getting Started

There are two ways to start your project:

Light-codegen generator

You can use light-codegen to generate a working project. Currently, it supports light-rest-4j, light-graphql-4j, light-hybrid-server-4j and light-hybrid-service-4j. light-eventuate code generator is coming.

The light-codegen project README.md describes four ways to use the generator with examples.

  • Clone and build the light-codgen and use the codegen-cli command line utility
  • Use docker image networknt/light-codegen to run the codegen-cli command line utility
  • Use generate.sh from model-config repo to generate projects based on conventions.
  • Generate code from web site with codegen-web API. (API is ready but UI needs to be built)

Starting from an example project

The other way to start your project is to copy from light-example-4j.

You can find the description of these examples

Also, there are some tutorials

Debugging

To run/debug from IDE, you need to configure a Java application with main class "com.networknt.server.Server" and working directory is your project folder. There is no container and you are working on just a standalone Java application.

Start Server

In IDE

create a Java application that main class is com.networknt.server.Server and working directory is your project root folder. You can debug your server just like a POJO application.

From Maven

mvn exec:exec

Command Line

java -jar target/demo-0.1.0.jar

Stop Server

you can use Ctrl+C to kill the server but for production use the following command

kill -s TERM <pid>

The server has a shutdown hook and the above command allow it to clean up. For example, complete in-flight requests and close the database connections etc. If service registry and discovery is used, then the server will send shutdown event to service registry and keep processing requests for 30 seconds until all clients refreshes their local cache before shutting down.

Appreciation

License

Light-4j and all light-*-4j frameworks are available under the Apache 2.0 license. See the LICENSE file for more info.

Frequently asked questions

Is light-4j free to use?

light-4j is open source under the Apache-2.0 licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does light-4j do?

A fast, lightweight and more productive microservices framework

What is light-4j written in?

light-4j is primarily written in Java. Its source is publicly available at https://github.com/networknt/light-4j, and it has 3,676 GitHub stars.