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 full-size 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 full-size slide

  3. Serverless
    @vitalethomas

    View full-size slide

  4. 1. No Servers
    @vitalethomas

    View full-size slide

  5. 1. No Servers Infrastructure
    @vitalethomas

    View full-size slide

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

    Provisioning
    Workload

    Management
    Dynamic

    Scaling
    @vitalethomas

    View full-size slide

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

    View full-size 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 full-size slide

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

    View full-size slide

  10. 2. Scale to Zero
    @vitalethomas

    View full-size slide

  11. 2. Scale to from Zero
    @vitalethomas

    View full-size slide

  12. GraalVM
    @vitalethomas

    View full-size 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 full-size slide

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

    Build

    Time
    Additional
    con
    fi
    guration
    might be
    needed
    @vitalethomas

    View full-size slide

  15. CRaC
    @vitalethomas

    View full-size slide

  16. 3. Functions
    @vitalethomas

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  19. Spring Cloud Function
    @vitalethomas

    View full-size slide

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

    View full-size slide

  21. Spring Cloud Function
    Business logic as functions
    Transparent

    Type

    Conversion
    Function

    Arity
    Function

    Composition
    Reactive

    Support
    JAR

    Functions
    @vitalethomas

    View full-size slide

  22. 4. Triggers
    @vitalethomas

    View full-size slide

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

    View full-size slide

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



    org.springframework.cloud


    spring-cloud-function-adapter-aws



    View full-size slide

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



    org.springframework.cloud


    spring-cloud-function-adapter-azure



    View full-size slide

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



    org.springframework.cloud


    spring-cloud-function-adapter-aws



    View full-size slide

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

    View full-size slide

  28. 5. Event-driven
    @vitalethomas

    View full-size slide

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

    View full-size slide

  30. Spring Cloud Stream
    @vitalethomas

    View full-size slide

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

    with functions
    Publish

    Subscribe
    Consumer Groups Partitions
    @vitalethomas

    View full-size 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 full-size slide

  33. 6. Developer Experience
    @vitalethomas

    View full-size 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 full-size slide

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

    View full-size 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 full-size slide

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

    View full-size slide

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

    View full-size 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 full-size 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 full-size slide

  41. Resources
    @vitalethomas

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide