Mauricio Salatino & Thomas Vitale
Devoxx UK
May 11th, 2022
Knative and Spring
Bringing back the func
@salaboy @vitalethomas
Mauricio Salatino
VMware - Knative OSS
* a.k.a @Salaboy

* Sta
ff
Engineer - Knative Eventing
tech lead for VMware 

* Knative OSS core contributor

* Passionate about Functions,
Platforms, Open Source and
Kubernetes

salaboy.com
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
Quiz Game
thomasvitale.com @vitalethomas
@salaboy @vitalethomas
Building applications using functions
Serverless
@salaboy @vitalethomas
Serverless Architectures
Developers focus on code
Focus on business logic
@salaboy @vitalethomas
Developer
Platform
Infrastructure

Provisioning
Workload

Management
Dynamic

Scaling
Knative Serving
Serverless Containers on Kubernetes
Developer-friendly

abstractions
From code to URL
Autoscaling

Scaling to zero
Progressive

Rollouts
Request-driven

Event-driven
@salaboy @vitalethomas
Cloud agnostic
Demo
thomasvitale.com @vitalethomas
@salaboy @vitalethomas
Knative Serving - From code to URL
Functions
@salaboy @vitalethomas
Functions
Functional programming model
Triggered by
requests or events
Stateless Smaller scope
Cold start Cost optimization
@salaboy @vitalethomas
Functions Patterns
Synchronous Interactions
Function
HTTP
Fire and Forget
Functions Patterns
Synchronous Interactions
Function
HTTP
Request / Response
Functions Patterns
Synchronous Interactions
Function
HTTP
Request / Response (Sync)
State
Functions Patterns
Synchronous Interactions
Function
HTTP
Request / Response (Scaling)
State
Function
Function
Load
Balancer
Functions Patterns
Synchronous Interactions
HTTP
Request / Response (Scaling)
State
Load
Balancer
Not running 

useless containers
Functions Patterns
Asynchronous Interactions
Async Processing
Function
HTTP
Doing
something that
takes a long time
……………………………………………
…………………………………………………
……………………………………………………
………………………………………………
………………………………………
Results
Functions Patterns
Asynchronous Interactions
Event Based
Function
CloudEvent CloudEvent
Functions Patterns
Asynchronous Interactions
Chaining Functions
Function
CloudEvent
Event Router
Function Function
Functions Patterns
Mix and match
Function
Request / Reply + Events
CloudEvent
HTTP
Event Router
Knative Functions
Working with the func CLI
@salaboy @vitalethomas
func create
‣Initialize project


‣Polyglot support


‣Java, Go, Python
1
func build
‣Build and containerize


‣Use Buildpacks


‣No Docker
fi
le
2
func deploy
‣Run on Kubernetes


‣Knative deployment


‣No YAML
3
Demo
thomasvitale.com @vitalethomas
@salaboy @vitalethomas
Knative Functions - From code to URL (GO)
Func - extras
In active development, join the community!
* External template repos

* func run
* On-cluster build, no Docker locally

* 1.0 GA is on the roadmap
Functions with Spring
@salaboy @vitalethomas
Spring Native
Native executables with GraalVM
Slower

Heavier

Build
Instant

Startup
Reduced

Memory

Consumption
Instant

Peak

Performance
Fewer

Runtime

Optimizations
@salaboy @vitalethomas
Functional Programming Paradigm
Java 8 Functional Interfaces
Supplier<O> Function<I,O> Consumer<I>
@salaboy @vitalethomas
Spring Cloud Function
Business logic as functions
Transparent

Type

Conversion
Function

Arity
Function

Composition
Reactive

Support
JAR

Functions
@salaboy @vitalethomas
Demo
thomasvitale.com @vitalethomas
@salaboy @vitalethomas
Knative Functions - From code to URL (Spring)
Function Composition
Data processing via functions
uppercase() sentence()
Data processing
“I play the PIANO”
“piano” “PIANO”
Spring Cloud Function
Deployment and integrations
Knative CloudEvents RSocket
Azure

Functions
Google Cloud
Functions
AWS

Lambda
@salaboy @vitalethomas
Game - Architecture
@salaboy @vitalethomas
Kubernetes Cluster
Function-based Game architecture
Game architecture
<Client Side>


React Application
<Orchestrator>


Game FrontEnd
<Function>


Start Game
<Function>


Level X


…
<Function>


Get LeaderB
Redis


(State)
HTTP
SYNC
<Function>


Level 1


…
Takeaways and challenges
Synchronous functions
Functions scale up
and down based on
demand
An Orchestrator is
needed
Synchronising state
is hard
Make sure that the
data store is not a
bottleneck
Latency can
become an issue
@salaboy @vitalethomas
Events
@salaboy @vitalethomas
Knative Eventing
Event routing and triggers
Developer-friendly

abstractions
Event-driven
architectures
Event routing
Polyglot support
with CloudEvents
Pluggable
@salaboy @vitalethomas
Cloud agnostic
CloudEvents
Interoperability and standardization
Metadata
Data
Id

Source

Type
Payload
JSON

AMQP

Kafka

MQTT
Game - Events
@salaboy @vitalethomas
Routing Events with Knative Eventing
CloudEvents & RSocket
Kubernetes Cluster
<Client Side>


React Application
<Orchestrator>


Game FrontEnd
<Function>


Level X


…
Redis
HTTP SYNC
Broker
Trigger
Score 

CloudEvent
RSocket
GameScore 

CloudEvent
Trigger
Another
Function
Takeaways and challenges
Eventing
An event-based
approach enable
more reactive
scenarios
Knative Eventing
abstracts the
message broker
implementations
CloudEvents
provide a standard
structure for

sharing data
Monitoring is
required to
understand how
data is
fl
owing
We need to deal
with eventual
consistency in our
applications
@salaboy @vitalethomas
Discount codes
Manning
• 35% discount code, valid for
all products in all format

• ctwdevoxxuk22


• manning.com
Resources
Source code
• Learn more about the game: 

• https://github.com/salaboy/from-monolith-to-k8s/tree/main/game

• Deploy the game on Kubernetes:

• https://github.com/ThomasVitale/eventing-game

• Spring Cloud Function samples:

• https://github.com/ThomasVitale/devoxxuk-2022-knative-spring-func
Mauricio Salatino & Thomas Vitale
Devoxx UK
May 11th, 2022
Knative and Spring
Bringing back the func
@salaboy @vitalethomas

Knative and Spring - Bringing back the func.pdf