aws-samples / serverless-java-frameworks-samples

MIT No Attribution
150 stars 38 forks source link

Lambda demo with common Java application frameworks

Architecture Diagram

This is a simple serverless application built in Java using popular frameworks — Micronaut, Quarkus, and Spring Boot

It consists of an Amazon API Gateway backed by four AWS Lambda functions and an Amazon DynamoDB table for storage.

Requirements

Software

Each of the sub folders contains a Product Maven project. Each Maven project contains all the code for all four Lambda functions. It uses the hexagonal architecture pattern to decouple the entry points from the main domain logic and the storage logic.

Infrastructure

The sample application can be deployed in three different ways:

  1. Managed Java Runtime (without SnapStart) — This mode uses zip packaging style and runs on the JVM inside the Lambda environment.
  2. Managed Java Runtime (with SnapStart) — This mode enables SnapStart on the Lambda functions. Current examples only include Spring Boot and Quarkus versions of the application. Stay tuned for other framework examples with SnapStart. Learn more about SnapStart here.
  3. Custom Runtime — This mode uses GraalVM native image and uses Custom Runtime to run on Lambda. GraalVM native image is a stand-alone execution binary and does not require a JVM to run.

Deployment and Testing

Micronaut

Quarkus

Spring Boot

Dagger

Summary

Below is the cold start and warm start latencies observed. Please refer to the "Load Test" section of each subproject for more details. All latencies listed below are in milliseconds.

Artillery is used to make 100 requests / second for 10 minutes to our API endpoints.

Results from Managed Java Runtime without SnapStart

Cold Start (ms) Warm Start (ms)
p50 p90 p99 max p50 p90 p99 max
Micronaut (Java 17) 4609.07 4943.09 5501.05 6657.94 8.52 14.31 32.52 314.99
Quarkus (Java 17) 2525.22 3146.27 4055.57 6343.83 7.50 12.28 29.87 231.52
Spring Boot (Java 17) 5311.93 5645.88 6183.47 7027.66 8.13 13.01 30.03 251.27
Dagger * 3213.00 3629.68 4850.11 6896.54 8.94 16.34 40.38 292.20

*: Dagger is not fully comparable to other frameworks as it only provides dependency injection, and thus is much lighter than the others, which explains these results. When choosing a framework, be conscious of the features available. Dagger was initially done with Android in mind, to provide a lightweight dependency injection framework, without introspection (like Spring). It fits particularly well with Lambda to reduce the initialization time, but does not provide the breadth of the others.

Results from Managed Java Runtime with SnapStart enabled Lambda functions

Cold Start (ms) Warm Start (ms)
p50 p90 p99 max p50 p90 p99 max
Micronaut (Java 17) 726.11 815.37 931.30 1047.49 7.68 12.30 28.18 244.82
Quarkus (Java 17) 487.31 586.87 732.67 932.17 7.38 11.91 25.20 147.26
Spring Boot (Java 17) 1047.87 1200.45 1597.68 1779.53 7.62 13.01 27.73 262.25

Results from GraalVM Native images running in custom runtime

Cold Start (ms) Warm Start (ms)
p50 p90 p99 max p50 p90 p99 max
Micronaut (22.3.r17) 638.27 722.49 960.60 1416.85 7.56 12.11 23.46 1029.55
Quarkus (22.3.r17) 467.27 599.77 802.43 1348.78 6.7 11.63 24.03 168.47
Spring Boot 620.66 684.53 721.77 751.98 9.10 14.22 23.61 259.16

👀 With other languages

You can find implementations of this project in other languages here:

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.