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

Cloud Native Development With Quarkus (GOTO masterclass)

Cloud Native Development With Quarkus (GOTO masterclass)

Cloud native development means running on the cloud (obviously), releasing on a rapid cadence, and automated testing, so that you have the confidence to release often. Traditional Java didn’t make this particularly easy, but Quarkus does.

This masterclass introduces Quarkus, and shows how develop, test, and deploy a microservices application. Along the way we’ll cover TDD with Quarkus, contract testing, developer services, REST applications, Hibernate and persistence, authentication with JWT and keycloak, native compilation, GraalVM, packaging, troubleshooting, how to integrate with Kubernetes, health checks, metrics, and observability. If time permits, we will cover custom extensions and reactive programming.

Here’s what you’ll learn:

How to be cloud native

The test pyramid and beyond

TDD with Quarkus

Writing a Quarkus REST application

Persistence with Hibernate and Panache

Microservices with Quarkus

JWT and Keycloak

Deciding between native and Java compilation

Deploying Quarkus apps to Kubernetes

Troubleshooting + observability

Holly Cummins

October 14, 2022
Tweet

More Decks by Holly Cummins

Other Decks in Programming

Transcript

  1. hi!

  2. @holly_cummins #RedHat how today works: 08:00: Registration and breakfast 


    09:00: Masterclass starts 
 10:30-10:45: Coffee break 
 12:00-13:00: Lunch 
 14:30-14:45: Coffee break 
 16:00: Masterclass ends
  3. @holly_cummins #RedHat how today works: • Quark-what? • How to

    be cloud native • The test pyramid and beyond • TDD with Quarkus • Writing a Quarkus REST application • Persistence with Hibernate and Panache • Microservices with Quarkus • Contract testing • JWT and Keycloak • Deciding between native and Java compilation • Deploying Quarkus apps to Kubernetes • Troubleshooting + observability • Q&A + wrap up + retrospective
  4. @holly_cummins #RedHat who are you? • what’s your name? •

    who do you work for? • what’s your role? • what’s in your tech stack?
  5. $18,000 Sun Sparc App Server Box (4 CPUs, 2GB of

    RAM) + $60,000 BEA Weblogic + $92,000 Sun Sparc DB Server Box (8 CPUs) + $243,000 Oracle RDBMS + $50,000 Symantec Visual Café for 10 developers -------------------------------------------------- $463,000 (capex) + ~$80,000 annual maint (opex) Cost of a Java-based Web App circa 1999
  6. Historical Enterprise Java Stack Operating System + Hardware/VM Java Virtual

    Machine (Hotspot) Application Server App App App App App Dynamic Application Frameworks Architecture: Monoliths 
 
 Deployment: multi-app, 
 appserver App Lifecycle: Months Memory: 1GB+ RAM Startup Time: 10s of sec
  7. Modern Enterprise Java Stack Java Virtual Machine (Hotspot) Application Server

    App Dynamic Application Frameworks Architecture: Microservices 
 
 Deployment: Single App 
 
 App Lifecycle: Days Memory: 100 MB + RAM Startup Time: Seconds No Change QUARKUS WORKSHOP
  8. Quarkus - Optimizing the Stack Java Virtual Machine (Hotspot) App

    (Imperative / Reactive) Optimized Application Frameworks Architecture: Microservices, 
 Serverless 
 
 Deployment: Single App 
 
 App Lifecycle: Minutes/Days Memory: 10 MBs + RAM Startup Time: Milliseconds Optional QUARKUS WORKSHOP
  9. Kubernetes-Native Development with Quarkus Solid Foundation Java consistently ranks in

    the Top 3 of programming languages in use today with a community of 7-10 million developers. Stunning Performance Optimized to provide native-level memory footprint and startup time, allowing for increased density, performance and elasticity at lower cost. Toolchain End-to-end toolchain including OpenShift Developer Console, Code Ready Workspaces, project generators in IDE and web, live- reload for lightning fast inner loop workflow, and CI/CD integration. Community Massive catalog of extensions connects your applications with best of breed-technologies including Camel, Jaeger, Prometheus, Istio, Kafka and more. TIOBE : #1 IEEE : #1 SlashData : #2 RedMonk : #2
  10. Quarkus Brings Real Developer Joy A cohesive platform for optimized

    developer joy: • Based on standards, but not limited • Unified configuration • Reactive & Imperative, all in one • Zero config, live reload in the blink of an eye • Streamlined code for the 80% common usages, flexible for the 20% • No hassle native executable generation
  11. Quarkus + GraalVM 13 MB Quarkus + OpenJDK 74 MB

    Traditional Cloud-Native Stack 140 MB REST https://quarkus.io/blog/runtime-performance/ Quarkus Improves Memory Utilization
  12. Quarkus Improves Startup Time Quarkus + GraalVM 0.014 Seconds REST

    REST + CRUD Quarkus + OpenJDK 0.75 Seconds Quarkus + GraalVM 0.055 Seconds Quarkus + OpenJDK 2.5 Seconds Traditional Cloud-Native Stack 9.5 Seconds Traditional Cloud-Native Stack 4.3 Seconds https://quarkus.io/blog/runtime-performance/
  13. Quarkus Unifies Imperative and Reactive • Combines both Reactive and

    imperative development in the same application • Reactive Messaging - Apache Kafka, MQTT, AMQP… • Reactive Services @Inject SayService say; @GET @Produces(MediaType.TEXT_PLAIN) public String hello() { return say.hello(); } @Inject @Stream(”kafka”) Publisher<String> reactiveSay; @GET @Produces(MediaType.SERVER_SENT_EVENTS) public Publisher<String> stream() { return reactiveSay; }
  14. Quarkus uses Best of Breed Frameworks & Standards Eclipse Vert.x

    Hibernate RESTEasy Apache Camel Eclipse MicroProfile Netty Kubernetes OpenShift Jaeger Prometheus Apache Kafka Infinispan Flyway Neo4j MongoDB MQTT KeyCloak Apache Tika
  15. 40 They load way too many classes They are way

    too dynamic / reflective They perform a lot of initialization at Runtime What is Wrong with Java Frameworks
  16. @
 @ </> Load and parse config files, properties, yaml,

    xml, etc. Build Time Runtime How does a framework start?
  17. @
 @ </> Classpath scanning and annotation discovery Attempt to

    load class to enable/disable features Build Time Runtime How does a framework start?
  18. @
 @ </> Build its metamodel of the world. Build

    Time Runtime How does a framework start?
  19. @
 @ </> Start thread pools, IO, etc. Build Time

    Runtime How does a framework start?
  20. Do the work once, not at each start Get rid

    of all bootstrap classes Less time to start, less memory needed Less or no reflection nor dynamic proxies What if we Initialize at Build time?
  21. @
 @ </> Build Time Do the work once, not

    at each start Get rid of all bootstrap classes Less time to start, less memory needed Less or no reflection nor dynamic proxies What if we Initialize at Build time?
  22. @
 @ </> Runtime Build Time Do the work once,

    not at each start Get rid of all bootstrap classes Less time to start, less memory needed Less or no reflection nor dynamic proxies What if we Initialize at Build time?
  23. @
 @ </> The Traditional vs. Quarkus Ways @
 @

    </> Build Time Runtime Build Time
  24. @
 @ </> The Traditional vs. Quarkus Ways @
 @

    </> Build Time Runtime Runtime Build Time
  25. @holly_cummins #RedHat Capabilities of a Cloud Native Application Architectures? The

    benefits of cloud native application architectures enable speed of development and deployment, flexibility, quality, and reliability. More importantly, it allows developers to integrate the applications with the latest open source technologies without a steep learning curve. While there are many ways to build and architect cloud native applications following are some great ingredients for consideration: • Runtimes - More likely to be written in the container first or/and Kubernetes native language, which means runtimes such as Java, Node.js, Go, Python, and Ruby, etc. • Security - Deploying and maintaining applications in a multi cloud, hybrid cloud application environment, security becomes of utmost importance and should be part of the environment. • Observability - The ability to observer applications and their behavior in the cloud. Tools that can give realtime metrics, and more information about the use e.g., Prometheus, Grafana, Kiali, etc. • Efficiency - Focused on tiny memory footprint, small artifact size, and fast booting time to make portable applications across hybrid/multi-cloud platforms. Primarily, it will leverage an expected spice in production via rapid scaling with consuming minimal computing resources. • Interoperability - Easy to integrate cloud native apps with the latest open source technologies such as Infinispan, MicroProfile, Hibernate, Apache Kafka, Jaeger, Prometheus, and more for building standard runtimes architecture. • DevOps/DevSecOps - Designed for continuous deployment to production in line with the minimum viable product (MVP), with security as part of the tooling together with development, automating testing, and collaboration.
  26. @holly_cummins #RedHat Capabilities of a Cloud Native Application Architectures? The

    benefits of cloud native application architectures enable speed of development and deployment, flexibility, quality, and reliability. More importantly, it allows developers to integrate the applications with the latest open source technologies without a steep learning curve. While there are many ways to build and architect cloud native applications following are some great ingredients for consideration: • Runtimes - More likely to be written in the container first or/and Kubernetes native language, which means runtimes such as Java, Node.js, Go, Python, and Ruby, etc. • Security - Deploying and maintaining applications in a multi cloud, hybrid cloud application environment, security becomes of utmost importance and should be part of the environment. • Observability - The ability to observer applications and their behavior in the cloud. Tools that can give realtime metrics, and more information about the use e.g., Prometheus, Grafana, Kiali, etc. • Efficiency - Focused on tiny memory footprint, small artifact size, and fast booting time to make portable applications across hybrid/multi-cloud platforms. Primarily, it will leverage an expected spice in production via rapid scaling with consuming minimal computing resources. • Interoperability - Easy to integrate cloud native apps with the latest open source technologies such as Infinispan, MicroProfile, Hibernate, Apache Kafka, Jaeger, Prometheus, and more for building standard runtimes architecture. • DevOps/DevSecOps - Designed for continuous deployment to production in line with the minimum viable product (MVP), with security as part of the tooling together with development, automating testing, and collaboration. lots of words
  27. @holly_cummins #RedHat the first module has TDD instructions the rest

    do not challenge in each module, scroll forward, find the tests, and work backwards.!
  28. @holly_cummins #RedHat tools evolve end-to-end tests unit tests integration tests

    low effort high realism tests with application server
  29. @holly_cummins #RedHat tools evolve end-to-end tests unit tests integration tests

    low effort high realism tests with application server test REST endpoints
  30. @holly_cummins #RedHat tools evolve end-to-end tests unit tests integration tests

    low effort high realism tests with application server test REST endpoints
  31. 79 @Entity public class Todo extends PanacheEntity { // id

    is inherited public String title; public boolean completed; public String url; @Column(name = "ordering") public int order; public static List<Todo> search(String query) { return list("completed = ?1 and title like ?2", false, query); } public static List<Todo> findNotCompleted() { return list("completed", false); } public static long deleteCompleted() { return delete("completed", true); } } Define entity with Panache
  32. 80 @GET public List<Todo> getAll() { return Todo.listAll(Sort.by("order")); } @POST

    @Transactional public void addTodo(@Valid Todo todo) { return todo.persist(); } @GET @Path("/search/{query}") public List<Todo> search(@PathParam("query") @NotBlank String query) { return Todo.search(query); } Accessing entities with Panache Convenient methods for lazy people (aka good devs)
  33. @holly_cummins #RedHat quarkus supports both blocking and reactive • it

    easier to become blocking on a reactive core than to become non- blocking on a blocking core
  34. @holly_cummins #RedHat Uni<Something> • returning a Uni makes a method

    non- blocking* • a Uni is like a node.js promise • Unis mix nicely with lamdas for chaining • you can mix blocking and non-blocking in an application, but be careful how finely you mix * there are limitations - you can get some subtle bugs!
  35. @holly_cummins #RedHat the limitations of unit tests “why do my

    colleagues tell me my code is broken, even though my unit tests all pass?”
  36. @holly_cummins #RedHat our code our mock our code their actual

    code tests ✔ why mocks aren’t enough
  37. @holly_cummins #RedHat our code our mock our code their actual

    code tests ✔ reality ✘ why mocks aren’t enough
  38. @holly_cummins #RedHat our code their code contract test mock functional

    test our tests ✔ their tests ✔ reality ✔ why mocks aren’t enough
  39. @holly_cummins #RedHat our code their code contract test mock functional

    test our tests ✔ their tests ✘ reality ✘ why mocks aren’t enough
  40. @holly_cummins #RedHat our code their code contract test mock functional

    test our tests ✘ their tests ✔ reality ✘ why mocks aren’t enough
  41. #RedHat @holly_cummins • consumer-driven contract testing can save your bacon

    • pact is a mock for the consumer • pact is a functional test for the producer • shared json contracts aligns expectations across services
  42. @holly_cummins #RedHat pitfalls of contract testing: • we have to

    talk to the other team • our consumers can break our CI?! • versions • pact is hard to grok • testing the mock • but I’ve invested in wiremock • duplicated tests is overhead
  43. @holly_cummins #RedHat contract testing options: • pact.io • spring contract

    • OpenAPI schema validation + mock generation • prism • schemathesis
  44. @holly_cummins #RedHat use case for native • low workload (so

    throughput isn’t the bottleneck) • resource-constrained or old hardware (especially memory) • high re-deploy rate (applications never get warmed up before being spun down) • serverless (of course) 
 use case for JVM • high workload (you need lots of throughput) • long-lived processes (the rapid start of native doesn’t save you much over the lifetime) • stable workload or very little elasticity in underlying orchestration is native better?
  45. @holly_cummins #RedHat is there a sustainability aspect? yes … and

    it’s just as depend-y! optimising • cost • application performance will also be optimising carbon
  46. @holly_cummins #RedHat native vs JVM is not an either-or •

    consider hybrid deployment models • a strength of Quarkus is application code is the same for native and JVM
  47. Customers using Quarkus Today “We could run 3 times denser

    deployments without sacrificing availability and response times of service” “When you adopt Quarkus, you will be productive from day one since you don’t really need to learn new technologies.” “Quarkus seemed to provide the performance boost we needed while at the same time having a good backer (Red Hat) and relying on battle- tested technologies” Thorsten Pohl Lufthansa Technik AVIATAR Product Owner Automation & Platform Architect Roberto Cortez Talkdesk Principal Architect Christos Sotiriou DXL technical lead at Vodafone Greece