$30 off During Our Annual Pro Sale. View Details »

Serverless Java with Spring Boot

Serverless Java with Spring Boot

Applications in a microservices architecture can communicate with each other in different ways. Adopting an event-driven paradigm based on asynchronous messaging provides services with a way of communicating while reducing runtime coupling. Applications in a microservices architecture can communicate with each other in different ways. Adopting an event-driven paradigm based on asynchronous messaging provides services with a way of communicating while reducing runtime coupling. Functions are a natural way of implementing event-driven business logic regarding suppliers, processors, and consumers. Furthermore, when going serverless, we aim at executables with instant startup and efficiency. Enter Spring.

Spring Cloud Function favours using the functional programming paradigm to implement your business logic and provides useful features to build data pipelines, including type conversion and function composition. Functions can be exposed through different options (like web endpoints or message channels), and adapters can run them on platforms like Knative, AWS Lambda, Azure Functions, and GCP Functions.

Spring Cloud Stream integrates your functions with messaging systems like RabbitMQ and Kafka without requiring any change to your code.

Finally, Spring Native lets you compile your applications as native executables using GraalVM and provides instant startup, instant peak performance, and reduced memory consumption.

Thomas Vitale

June 08, 2022
Tweet

More Decks by Thomas Vitale

Other Decks in Technology

Transcript

  1. Thomas Vitale
    DevTalks
    June 8th, 2022
    Serverless Java
    With Spring Boot
    @vitalethomas

    View Slide

  2. Systematic
    • Software Architect at
    Systematic, Denmark.

    • Author of “Cloud Native Spring
    in Action” (Manning).

    • Spring Security and Spring
    Cloud contributor.
    Thomas Vitale
    thomasvitale.com @vitalethomas

    View Slide

  3. Serverless
    thomasvitale.com @vitalethomas

    View Slide

  4. Serverless Architectures
    Developers focus on code
    Focus on business logic
    Developer
    Platform
    Infrastructure

    Provisioning
    Workload

    Management
    Autoscaling

    Scaling to zero
    thomasvitale.com @vitalethomas

    View Slide

  5. Spring Native
    thomasvitale.com @vitalethomas

    View Slide

  6. Spring Native
    Native executables with GraalVM
    Slower

    Heavier

    Build
    Instant

    Startup
    Reduced

    Memory

    Consumption
    Instant

    Peak

    Performance
    Fewer

    Runtime

    Optimizations
    thomasvitale.com @vitalethomas

    View Slide

  7. Packaging Spring Boot
    JAR and native
    thomasvitale.com @vitalethomas
    JAR
    Native
    Gradle


    bootJar
    Maven


    spring-boot:repackage
    Gradle


    nativeCompile
    Maven


    -Pnative package

    View Slide

  8. Packaging Spring Boot
    Container images with Cloud Native Buildpacks
    thomasvitale.com @vitalethomas
    Container Image
    Gradle


    bootBuildImage
    Maven


    spring-boot:build-image

    View Slide

  9. Knative
    thomasvitale.com @vitalethomas

    View Slide

  10. Knative Serving
    Serverless Containers on Kubernetes
    Developer-friendly

    abstractions
    From code to URL
    Autoscaling

    Scaling to zero
    Progressive

    Rollouts
    Request-driven

    Event-driven
    Cloud agnostic
    thomasvitale.com @vitalethomas

    View Slide

  11. Serverless experience on Kubernetes
    From containers to deployment with Knative
    Image
    pack
    kpack
    bootBuildImage
    kn
    URL
    Kubernetes Cluster
    Container
    Container
    Container
    Knative
    Serving
    thomasvitale.com @vitalethomas

    View Slide

  12. Functions
    thomasvitale.com @vitalethomas

    View Slide

  13. Functional Programming Paradigm
    Java 8 Functional Interfaces
    thomasvitale.com @vitalethomas
    Supplier Function Consumer

    View Slide

  14. Spring Cloud Function
    thomasvitale.com @vitalethomas

    View Slide

  15. Spring Cloud Function
    Business logic as functions
    thomasvitale.com @vitalethomas
    Transparent

    Type

    Conversion
    Function

    Arity
    Function

    Composition
    Reactive

    Support
    JAR

    Functions

    View Slide

  16. Spring Cloud Function
    Deployment and integrations
    thomasvitale.com @vitalethomas
    Knative CloudEvents RSocket
    Azure

    Functions
    Google Cloud
    Functions
    AWS

    Lambda

    View Slide

  17. CloudEvents
    Interoperability and standardization
    Metadata
    Data
    Id

    Source

    Type
    Payload
    JSON

    AMQP

    Kafka

    MQTT
    thomasvitale.com @vitalethomas

    View Slide

  18. Spring Cloud Stream
    thomasvitale.com @vitalethomas

    View Slide

  19. Spring Cloud Stream
    Event-driven microservices
    thomasvitale.com @vitalethomas
    Integration with
    event brokers
    Bindings

    with functions
    Publish

    Subscribe
    Consumer Groups Partitions

    View Slide

  20. 'HVWLQDWLRQ%LQGHU
    'HVWLQDWLRQ
    %LQGLQJ
    .DIND 5DEELW04
    )XQFWLRQ
    6SULQJ%RRW$SSOLFDWLRQ
    'HVWLQDWLRQ
    %LQGLQJ
    6SULQJ&ORXG6WUHDP$SSOLFDWLRQ0RGHO
    thomasvitale.com @vitalethomas

    View Slide

  21. Discount codes
    Manning
    • 35% discount code, valid for
    all products in all format

    • ctwdevtalksro22


    • manning.com

    View Slide

  22. https://github.com/ThomasVitale/awesome-spring

    View Slide

  23. Resources
    Source code and more
    • Sample project:

    • https://github.com/ThomasVitale/devtalks-2022-serverless-java

    • Knative and Spring - Bringing back the func:

    • https://youtu.be/EKDYE_dStTI
    thomasvitale.com @vitalethomas

    View Slide

  24. Thomas Vitale
    DevTalks
    June 8th, 2022
    Serverless Java
    With Spring Boot
    @vitalethomas

    View Slide