Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Micronaut: A new way to build microservices

Micronaut: A new way to build microservices

Over the years microservices architecture has been widely adopted in conjunction with Spring Boot. But recently, we are witnessing the rise of microframeworks such as Micronaut, which has innovated the way we build microservices by providing low memory consumption, fast startup, non-blocking, and other important features that I will demonstrate and conceptualize in this talk.

Ef3b48913ea26665c25b2ad78e449d16?s=128

Luram Archanjo

July 17, 2019
Tweet

Transcript

  1. A new way to build microservices Luram Archanjo

  2. Who am I? • Software Engineer at Sensedia • MBA

    in java projects • Java and microservice enthusiastic
  3. Agenda • Microservices • Java & Frameworks • Ahead of

    Time (AOT) Compilation • GraalVM • Micronaut • Questions
  4. Moving to Microservices Feature A Feature B Feature C Monolith

    Microservice Microservice Microservices Microservice
  5. Scalability Feature A Monolith Scalability Microservice Microservice Microservices Scalability Microservice

    Microservice Microservice Microservice Microservice Microservice Microservice Microservice Feature B Feature C Feature A Feature B Feature C Feature A Feature B Feature C
  6. Our resources are finite!

  7. How to use less resources using Java language?

  8. Our frameworks are design to low memory footprint?

  9. No, because we’ve tried to adapt existing legacy technologies for

    Microservices
  10. What do Spring and Jakarta EE undertaking? What are the

    results about it? Spring is an amazing technical achievement and does so many things, but does them at Runtime. • Reads the byte code of every bean it finds. • Synthesizes new annotations for each annotation on each bean method, constructor, field etc. to support Annotation metadata. • Builds Reflective Metadata for each bean for every method, constructor, field etc.
  11. The rise of Java Microframeworks

  12. Microframeworks A microframework is a term used to refer to

    minimalistic web application frameworks: • Without authentication and authorization • Without database abstraction via an object-relational mapping. • Without input validation and input sanitation.
  13. Less modules, functions and dependencies are not enough!

  14. Ahead of Time (AOT) Compilation Ahead-of-time compilation (AOT compilation) is

    the act of compiling a higher-level programming language, or an intermediate representation such as Java bytecode, into a native machine code so that the resulting binary file can execute natively. Web Android Java Google Dagger 2 ?
  15. uses Ahead of Time (AOT) Compilation

  16. What are the results of using Ahead of Time (AOT)

    Compilation?
  17. The results of using Ahead of Time (AOT) Compilation Data

    from Micronaut website: • Startup time around a second. • All Dependency Injection, AOP and Proxy generation happens at compile time. • Can be run with as little as 10mb Max Heap.
  18. I don't believe, show me!

  19. Is it possible to improve more?

  20. Yes, with

  21. GraalVM GraalVM is an universal virtual machine: • Runs Java,

    Scala, Kotlin etc. • Native image compiled with ahead-of-time improves the startup time and reduce the memory footprint of JVM-based applications. GraalVM works well when: • Little or no runtime reflection is used. ◦ Use third party libraries selectively. • Limited or no dynamic classloading.
  22. Demo +

  23. AOT Summary Spring + JVM Micronaut + JVM Micronaut +

    GraalVM Startup ≃ 0.8s Memory ≃ 10mb Startup ≃ 6s Memory ≃ 15mb Startup ≃ 0.4s Memory ≃ 5mb
  24. What else does Micronaut do?

  25. Blocking or Non-Blocking HTTP server built on Netty With a

    smooth learning curve, Micronaut HTTP server makes it as easy as possible to expose APIs that can be consumed by HTTP clients. Blocking @Controller("/hello") public class HelloController { @Get public String hello() { return "Hello Micronaut"; } } Non-Blocking (RxJava + Netty) @Controller("/hello") public class HelloController { @Get public Single<String> hello() { return Single.just("Hello Micronaut"); } }
  26. Dependency Injection and Inversion of Control (IoC) This is a

    similar approach taken by Spring and Google Dagger, but without reflection and proxies. All the injections are done in compile time. @Singleton public class HelloService { public String hello() { return "Hello Micronaut"; } } @Controller("/hello") public class HelloController { @Inject private HelloService helloService; @Get public String hello() { return helloService.hello(); } }
  27. Cloud Native Features

  28. Distributed Tracing When operating Microservices in production it can be

    challenging to troubleshoot interactions between Microservices in a distributed architecture. Micronaut features integration with both Zipkin and Jaeger (via the Open Tracing API). @Controller("/hello") public class HelloController { @Inject private HelloService helloService; @Get("/{name}") @NewSpan("hello") public String hello(@SpanTag String name) { return helloService.hello(); } }
  29. Serverless Functions Serverless architectures where as a developer you deploy

    functions that are fully managed by the Cloud environment and are executed in ephemeral processes require a unique approach. @FunctionBean("hello-function") public class HelloFunction implements Supplier<String> { @Override public String hello() { return "Hello world"; } } @FunctionClient public interface HelloFunctionClient { String hello(); }
  30. Summary 2º Place 1º Place 3º Place Ahead of Time

    (AOT) Compilation • Low memory footprint • Fast Startup • IoC • Productivity with annotations • Blocking or Non-Blocking HTTP server built on Netty Cloud Native Features • Service Discovery • Distributed Tracing • Serveless • Distributed Configuration
  31. Thanks a million! Questions? /larchanjo /luram-archanjo