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

How I Built a Serverless Search for My Blog with Java, Quarkus, and AWS Lambda

How I Built a Serverless Search for My Blog with Java, Quarkus, and AWS Lambda

-- A presentation from QConPlus 2020 (https://plus.qconferences.com/plus2020/presentation/serverless-search-my-blog-java-quarkus-aws-lambda) --

A Serverless app? With Java?! Absolutely!

We’ll discuss when Serverless is a great fit (and when it isn’t!) and why you don’t need to leave the Java platform when going Serverless. Based on the real-world example of a Serverless blog search, you’ll learn how Quarkus and GraalVM help you with building apps for AWS Lambda, which are blazing fast to start up and are memory-efficient at the same time. We’ll explore

* Which options Quarkus provides for creating AWS Lambda apps, making noticeable cold-start delays a thing of the past
* What it takes to enable existing libraries like Apache Lucene to be used in GraalVM native binaries
* How to build Serverless apps which are portable across platforms, avoiding lock-in into specific cloud providers

Join us for this session to stop worrying about cold-starts and exploding costs, and learn how to love Serverless -- Java style!


Gunnar Morling

November 17, 2020

More Decks by Gunnar Morling

Other Decks in Programming


  1. (How I Built a) Serverless Search for My Blog With

    Java, Quarkus & AWS Lambda Gunnar Morling Software Engineer, Red Hat @gunnarmorling
  2. #ServerlessSearch @gunnarmorling 2 Today’s Topic https://www.morling.dev/

  3. #ServerlessSearch @gunnarmorling https://twitter.com/gunnarmorling/status/1289294902279442432 “Mythbusters - Serverless Edition”

  4. #ServerlessSearch @gunnarmorling 4 Gunnar Morling • Open source software engineer

    at Red Hat ◦ Debezium ◦ Quarkus • Spec Lead for Bean Validation 2.0 • Java Champion • @gunnarmorling
  5. #ServerlessSearch @gunnarmorling “Serverless computing refers to the concept of building

    and running applications that do not require server management. It describes a finer-grained deployment model where applications, bundled as one or more functions are uploaded to a platform and then executed, scaled, and billed in response to the exact demand needed at the moment” -- CNCF Definition, https://www.cncf.io/blog/2018/02/14/cncf-takes-first-step-towards-serverless-computing/ What is Serverless Again?
  6. #ServerlessSearch @gunnarmorling • Smaller attack surface • Lower cost •

    A learning opportunity Why Serverless For My Use Case?
  7. #ServerlessSearch @gunnarmorling 7 Solution Overview © https://pixabay.com/photos/hamburg-speicherstadt-channel-2976711/

  8. #ServerlessSearch @gunnarmorling Solution Overview System Architecture

  9. #ServerlessSearch @gunnarmorling Solution Overview Indexing and Searching • Hugo can

    provide searchable JSON • Indexed at build time ◦ Immutable image • Apache Lucene ◦ Stemming ◦ Highlighting ◦ Fuzzy Search
  10. #ServerlessSearch @gunnarmorling 10 Serverless Apps with Quarkus © Tom Hodgkinson

    https://flic.kr/p/oiZEm (CC BY-SA 2.0)
  11. #ServerlessSearch @gunnarmorling 11 Lambda Request Handler Serverless Apps with Quarkus

  12. #ServerlessSearch @gunnarmorling 12 Serverless Apps with Quarkus Funqy

  13. #ServerlessSearch @gunnarmorling 13 Serverless Apps with Quarkus Lambda with Vert.x

    Web, Servlet or RESTEasy
  14. #ServerlessSearch @gunnarmorling Serverless Apps with Quarkus When to Use What?

    Have existing code; specific APIs needed RequestHandler Simple GET/POST Funqy Full flexibility needed Web Stacks
  15. #ServerlessSearch @gunnarmorling 15 Serverless Apps with Quarkus Building for Lambda

    vs. K8s/Knative
  16. #ServerlessSearch @gunnarmorling 16 Cold Starts - A Dish Best Served

  17. #ServerlessSearch @gunnarmorling • Dragons beware! ◦ Reflection ◦ Method handles

    ◦ Finding all resources ◦ JNI • Quarkus extensions for many libraries Cold Starts - A Dish Best Served Fast Native Binaries via GraalVM
  18. #ServerlessSearch @gunnarmorling 18 Cold Starts - A Dish Best Served

    Fast No Quarkus Extension for Lucene Yet
  19. #ServerlessSearch @gunnarmorling 19 Cold Starts - A Dish Best Served

    Fast No Quarkus Extension for Lucene Yet
  20. #ServerlessSearch @gunnarmorling Cold Starts - A Dish Best Served Fast

    Leveraging Interaction Patterns
  21. #ServerlessSearch @gunnarmorling Cost Control © Pictures of Money https://flic.kr/p/s684tk (CC

    BY 2.0)
  22. #ServerlessSearch @gunnarmorling Cost Control • API Usage Plan (beware of

    CORS preflight requests!) • Throttling • Budget Circuit Breaker • CloudFlare Service Workers How To Prevent “Denial-of-Wallet” Attacks?
  23. #ServerlessSearch @gunnarmorling 23 Cost Control Budget Circuit Breaker

  24. #ServerlessSearch @gunnarmorling 24 Cost Control Budget Circuit Breaker

  25. #ServerlessSearch @gunnarmorling Summary © Sanja Matonickin https://flic.kr/p/cwknAL (CC BY-SA 2.0)

  26. #ServerlessSearch @gunnarmorling • Steep learning curve of AWS Lambda ◦

    IAM is a tricky beast ◦ More RAM → more CPU shares • Quarkus helps; avoids lock-in ◦ SAM templates ◦ Helper scripts • Protect against “denial-of-wallet” attacks Lessons Learned
  27. #ServerlessSearch @gunnarmorling Lessons Learned

  28. #ServerlessSearch @gunnarmorling Lessons Learned

  29. #ServerlessSearch @gunnarmorling • In-depth Write-up www.morling.dev/blog/how-i-built-a-serverless-search-for-my-blog/ • Source Code github.com/gunnarmorling/search.morling.dev/

    • Quarkus quarkus.io/ • Budget circuit breaker harishkm.in/2020/07/10/automatically-shutdown-your-api-on-amazon-api- gateway-when-it-breaches-a-certain-spending-threshold/ Resources
  30. #ServerlessSearch @gunnarmorling Q&A gunnar@hibernate.org @gunnarmorling

  31. None