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

Serverless Java with Spring Boot (DevBcn 2023)

Serverless Java with Spring Boot (DevBcn 2023)

Serverless technologies have one clear goal: enabling developers to focus on delivering value while the platform takes care of all the infrastructural concerns. How does Java fit into this space?

This session will demonstrate how to use the native constructs in the Java standard libraries to follow a functional programming paradigm when implementing the business logic of your applications. Functions will be transparently enhanced by Spring Cloud Function, a framework that enriches standard Java to build data pipelines, including features like type conversion and function composition.

Building functions is not enough. We need a strategy to expose and integrate them with the rest of the system. This presentation will show different options to consume Java functions via platforms like Knative, AWS Lambda, Azure Functions, and GCP Functions.

Events are a fundamental part of serverless applications. You’ll see how to use the CloudEvents standard and how to integrate functions with message brokers like RabbitMQ and Kafka. Spring Cloud Stream provides such functionality without requiring any change to your code.

Functions are usually deployed to platforms with autoscaling and scale-to-zero features. GraalVM will be used to compile Java functions as native executables and provides instant startup, instant peak performance, and reduced memory consumption.

Thomas Vitale

July 05, 2023
Tweet

More Decks by Thomas Vitale

Other Decks in Technology

Transcript

  1. Thomas Vitale
    DevBcn
    July 4th, 2023
    Serverless Java
    with Spring Boot
    @vitalethomas

    View Slide

  2. Systematic
    • Software Engineer and Cloud
    Architect.

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

    • OSS contributor (Java, Spring,
    Cloud Native Technologies)
    Thomas Vitale
    thomasvitale.com @vitalethomas

    View Slide

  3. Serverless
    @vitalethomas

    View Slide

  4. 1. No Servers
    @vitalethomas

    View Slide

  5. 1. No Servers Infrastructure
    @vitalethomas

    View Slide

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

    Provisioning
    Workload

    Management
    Dynamic

    Scaling
    @vitalethomas

    View Slide

  7. JAR
    Serverless Platforms
    From application artifact to URI
    @vitalethomas
    packaged as
    OCI Image
    deployed on
    deployed on

    View Slide

  8. Serverless Platforms
    From application artifact to URI
    @vitalethomas
    aws lambda create-function


    --function-name Uppercase


    --zip-file java-function.jar
    kn service create uppercase


    --image ghcr.io/thomasvitale/java-function

    View Slide

  9. thomasvitale.com @vitalethomas
    https://tag-app-delivery.cncf.io/whitepapers/platforms @vitalethomas

    View Slide

  10. 2. Scale to Zero
    @vitalethomas

    View Slide

  11. 2. Scale to from Zero
    @vitalethomas

    View Slide

  12. GraalVM
    @vitalethomas

    View Slide

  13. Spring Boot 3 and Native Executables
    The bene
    fi
    ts of GraalVM
    Instant

    Startup
    Low

    Resource

    Usage
    Instant

    Peak

    Performance
    @vitalethomas
    Reduced

    Surface

    Attack
    Compact

    Packaging

    View Slide

  14. Spring Boot 3 and Native Executables
    The downsides of GraalVM
    Longer

    Build

    Time
    Additional
    con
    fi
    guration
    might be
    needed
    @vitalethomas

    View Slide

  15. CRaC
    @vitalethomas

    View Slide

  16. 3. Functions
    @vitalethomas

    View Slide

  17. Functional Programming Paradigm
    Java Functional Interfaces
    Supplier Function Consumer
    @vitalethomas

    View Slide

  18. Function Composition
    Data processing via functions
    uppercase() sentence()
    “I play the PIANO”
    “piano” “PIANO”
    @vitalethomas

    View Slide

  19. Spring Cloud Function
    @vitalethomas

    View Slide

  20. @vitalethomas
    Spring Cloud Function
    Java Function
    Spring Cloud Function

    View Slide

  21. Spring Cloud Function
    Business logic as functions
    Transparent

    Type

    Conversion
    Function

    Arity
    Function

    Composition
    Reactive

    Support
    JAR

    Functions
    @vitalethomas

    View Slide

  22. 4. Triggers
    @vitalethomas

    View Slide

  23. @vitalethomas
    Spring Cloud Function
    Java Function
    Spring Cloud Function

    View Slide

  24. @vitalethomas
    AWS Lambda
    Spring Cloud Function
    Java Function
    AWS Lambda



    org.springframework.cloud


    spring-cloud-function-adapter-aws



    View Slide

  25. @vitalethomas
    Azure Function
    Spring Cloud Function
    Java Function
    Azure Functions



    org.springframework.cloud


    spring-cloud-function-adapter-azure



    View Slide

  26. @vitalethomas
    Google Cloud Function
    Spring Cloud Function
    Java Function
    Google Cloud Functions



    org.springframework.cloud


    spring-cloud-function-adapter-aws



    View Slide

  27. @vitalethomas
    Spring Web
    Spring Cloud Function
    Java Function
    Web Applications

    View Slide

  28. 5. Event-driven
    @vitalethomas

    View Slide

  29. @vitalethomas
    Spring Cloud Stream
    Spring Cloud Function
    Java Function
    Event-driven Applications

    View Slide

  30. Spring Cloud Stream
    @vitalethomas

    View Slide

  31. Spring Cloud Stream
    Event-driven applications
    Integration with
    event brokers
    Bindings

    with functions
    Publish

    Subscribe
    Consumer Groups Partitions
    @vitalethomas

    View Slide

  32. Testcontainers
    Development and testing with external dependencies
    OCI containers
    Run external
    dependencies as


    OCI containers
    Data Layer Tests
    Ensure environment
    parity by testing the data
    layer with the real
    database
    Integration Tests
    Use containers for
    databases, message
    queues, and web servers
    @vitalethomas

    View Slide

  33. 6. Developer Experience
    @vitalethomas

    View Slide

  34. Developer Experience
    “…developer experience could be defined as a means for
    capturing how developers think and feel about their
    activities within their working environments,

    with the assumption that an improvement of the developer
    experience has positive impacts on characteristics such
    as sustained team and project performance.”

    (F. Fagerholm, J. Münch)
    Developer Experience: Concept and De
    fi
    nition
    (F. Fagerholm, J. Münch)
    @vitalethomas

    View Slide

  35. “Friends don’t let friends write Dockerfiles!”
    - Josh Long
    @vitalethomas

    View Slide

  36. Dockerfiles
    “Dockerfiles are easy to write, but the current
    development guidelines do not produce
    containers that are repeatable and hardened.”

    CNCF Software Supply Chain Security Paper
    https://github.com/cncf/tag-security/tree/main/supply-chain-security
    @vitalethomas

    View Slide

  37. Image
    pack build
    Cloud Native Buildpacks
    From source code to container image
    @vitalethomas

    View Slide

  38. Image
    pack build
    gradle bootBuildImage
    Cloud Native Buildpacks
    From source code to container image
    @vitalethomas

    View Slide

  39. Deploying Functions with Knative
    From idea to deployment with autoscaling
    URL
    func create
    Image
    func deploy
    Kubernetes Cluster
    Container
    Container
    Container
    Knative
    Serving
    @vitalethomas

    View Slide

  40. Deploying Functions with Knative
    From idea to deployment with autoscaling
    URL
    func create
    Image
    func deploy
    Kubernetes Cluster
    Container
    Container
    Container
    Knative
    Serving
    @vitalethomas

    View Slide

  41. Resources
    @vitalethomas

    View Slide

  42. github.com/ThomasVitale/serverless-java-with-spring-boot

    View Slide

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

    View Slide

  44. Thomas Vitale
    DevBcn
    July 4th, 2023
    Serverless Java
    with Spring Boot
    @vitalethomas

    View Slide