Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building Microservices with Micronaut®

You're reading from   Building Microservices with Micronaut® A quick-start guide to building high-performance reactive microservices for Java developers

Arrow left icon
Product type Paperback
Published in Sep 2021
Publisher Packt
ISBN-13 9781800564237
Length 362 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Zack Dawood Zack Dawood
Author Profile Icon Zack Dawood
Zack Dawood
Nirmal Singh Nirmal Singh
Author Profile Icon Nirmal Singh
Nirmal Singh
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Section 1: Core Concepts and Basics
2. Chapter 1: Getting Started with Microservices Using the Micronaut Framework FREE CHAPTER 3. Section 2: Microservices Development
4. Chapter 2: Working on Data Access 5. Chapter 3: Working on RESTful Web Services 6. Chapter 4: Securing the Microservices 7. Chapter 5: Integrating Microservices Using Event-Driven Architecture 8. Section 3: Microservices Testing
9. Chapter 6: Testing Microservices 10. Section 4: Microservices Deployment
11. Chapter 7: Handling Microservice Concerns 12. Chapter 8: Deploying Microservices 13. Section 5: Microservices Maintenance
14. Chapter 9: Distributed Logging, Tracing, and Monitoring 15. Section 6: IoT with Micronaut and Closure
16. Chapter 10: IoT with Micronaut 17. Chapter 11: Building Enterprise-Grade Microservices 18. Assessment 19. Other Books You May Enjoy

Why Micronaut is the best choice for developing microservices

In the previous sections, we learned about the maturity on the architectural side of microservices. Unfortunately, on the implementation side, an overhaul shift to build/develop microservices is not as mature as microservices architecture. To address some of these implementation challenges, many traditional Java frameworks have added small, iterative changes, but much-sought-after disruptive and overhauled changes are missing. At the core, these traditional Java frameworks have stayed almost the same since the time of monolithic services. Reflections, runtime proxies, and bulky configuration management have plagued all traditional frameworks with slower boot time and bigger memory footprints, making them unsuitable for microservices development.

Micronaut is developed from the bottom up, considering these important challenges, to organically support microservices development:

  • Dependency injection: Micronaut uses JSR-330 @Inject for dependency injection. It adds the Java inject module to the compiler and all the annotations are processed at compile time. The compiler generates the byte code for all the classes based on the annotations that are used in their source code. This is all done at compile time. At runtime, Micronaut can instantiate the beans and read their metadata from the generated byte code and does not need to use the slow reflection API.
  • Ahead-of-time compilation: As discussed before, one of the key contrasts is that Micronaut performs dependency injection, configuration management, and aspect-oriented programming proxying at compile time. Micronaut relies on one or more annotation processors to process the annotation metadata into ASM-generated (assembly) byte code. Furthermore, this ahead-of-time-generated byte code is further optimized by Java's just-in-time (JIT) compiler. Other frameworks use reflection and produce the annotation metadata at application boot-up. This metadata is loaded to runtime memory, therefore increasing the memory footprint. Instead of the Java Reflection API, Micronaut uses the Java annotation processor API, the Kotlin compiler plugin for annotation processors, and Groovy AST transformations for metaprogramming.
  • Faster boot-up time and lower memory consumption: Other frameworks use Java reflections and at application boot-up, all classpaths are scanned to generate reflection metadata for each field, method, and constructor. This metadata is then used to determine and inject the required object into the application runtime. This adds significantly to boot-up time as well as runtime memory. As discussed previously, Micronaut uses ahead-of-time compilation and the Java annotation processor API to offload such work from the runtime and reduce memory requirements by not pushing unnecessary reflection metadata onto runtime memory.
  • Serverless applications support: One of the key issues in serverless applications is boot-up time. With a huge memory footprint and slower boot-up time, traditional frameworks are not a prudent choice to develop serverless applications. Micronaut organically supports serverless application development by keeping the minimal runtime memory footprint and sub-second boot-up time. Furthermore, Micronaut natively supports commonly used cloud platforms for serverless function development.
  • Language-agnostic framework: The Micronaut framework supports the Java, Kotlin, and Groovy programming languages. With varied support for major programming languages, developers can choose their preferred language option when considering cloud requirements. For example, for IoT requirements, Groovy could be a good option. This language-agnostic enablement makes it flexible and apt for varied requirements of mobile/web/cloud solutions.
  • Support to GraalVM: Since Micronaut doesn't use reflections, any Micronaut-based application can be ahead-of-time compiled into a GraalVM native image. GraalVM is a universal virtual machine offered by Oracle that can run a Java application down to machine code. This increases application performance significantly. Any Micronaut application compiled to a GraalVM native image can boot up in milliseconds.

In light of the preceding key points, Micronaut stands out as a preferred framework to develop cloud-native, ultra-light, and rapid microservices. In addition, we performed a quick benchmark experiment to compare the application startup times for Micronaut versus another popular traditional framework. In the following chart, startup times are shown for both Micronaut and a traditional framework:

Figure 1.4 – Startup times for a traditional framework versus Micronaut

Figure 1.4 – Startup times for a traditional framework versus Micronaut

As shown in the preceding chart, the traditional framework took 6,156 milliseconds to boot up whereas Micronaut took only 3,750 milliseconds. This time difference in booting up the application is significant and sets Micronaut as a go-to framework for developing cloud-native and rapid microservices.

In the following section, we will get started with using the Micronaut framework on both Windows as well as mac OS.

You have been reading a chapter from
Building Microservices with Micronaut®
Published in: Sep 2021
Publisher: Packt
ISBN-13: 9781800564237
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime