SpringOne Platform 2017
Mark Fisher, Pivotal
This live coding session will introduce Spring Cloud Function, from the basic programming model all the way to multicloud deployments. Along the way, we'll explore the current state of Java across Function-as-a-Service providers and demonstrate what role Spring can play in the Serverless world.
3. Why Serverless?
3
1. Narrowly-scoped units of code, and the simplicity of built-in event integration,
contribute to software development efficiencies.
2. Functions which don't consume resources when idle can provide significant
resource efficiencies.
3. Applying serverless to distributed computing brings operational efficiencies
based on automated event-based scheduling and self-scaling.
4. Use Cases
4
Large Scale Data
⢠Bulk Processing
⢠IoT streams
⢠Log ingestion
⢠Machine Learning
⢠Stateful Stream Processing
Web Events
⢠Website back-end services like form
post handlers, authentication, tracking
and logging.
⢠APIs to back-end data services for
mobile and web apps e.g GraphQL
⢠Webhook handlers
⢠CI/CD automation
⢠Chat integrations
⢠Digital assistant services e.g. Alexa
skills
Event-based Integration
⢠Scheduled tasks, ETL
⢠File processing
e.g. images and videos
⢠Security scanning
⢠Complex Event Processing
and Change Data Capture
⢠Monitoring, notifications and
alerting
⢠Custom auth
e.g. via API Gateway
CNCF Serverless Working Group
11. Unless otherwise indicated, these slides are Š 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
what is riff?
11
riff provides developers
with a service for
executing Functions in
response to Events.
Features
â event streaming
â polyglot
â Kubernetes-native
Events
f(x)
f(x)
f(x)
Functions
f(x)
riff
12. Unless otherwise indicated, these slides are Š 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
12
Immediate
Instant-on
Consistent
Immutable
Containers
Efficient
Scale to Zero
Choice of Compromises:
⢠Launch Function containers on demand
=> Slow start
⢠Inject Function code into running containers
=> Breaks container immutability
⢠Keep Function containers running
=> Pay for idle resources
ICE
Want serverless?... pick 2
13. Unless otherwise indicated, these slides are Š 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
functions are packaged as containers
13
Function
Invoker
Function Code
Container Base Image
Function Layer
Container
Registry
14. Unless otherwise indicated, these slides are Š 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
sidecars connect functions with event brokers
14
Function Pod
Function ContainerSidecar Container
Event
Broker
broker-specific
API
binder dispatcher invoker function
HTTP
gRPC
stdio
15. Unless otherwise indicated, these slides are Š 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
15
functions and topics are Kubernetes resources
Function
Controller
Function YAML
- name
- input / output topics
- artifact / params
Topic YAML
- name
- params
KafkaHttp Gateway
Topic
Controller
Sc Fn
Pod
Sc Fn
Pod
Sc Fn
Pod
k8s
API
16. Unless otherwise indicated, these slides are Š 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
functions scale with events
riff function controller
â interacts with K8s API
â scales functions 0-1 and 1-N
â monitors event-lag in Kafka
16
Event Broker
f(x)
f(x)
f(x)
k8s
API
17. Unless otherwise indicated, these slides are Š 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
17
public class VoteStreamProcessor implements Function<Flux<String>, Flux<Map<String, Object>>> {
public Flux<Map<String, Object>> apply(Flux<String> words) {
return words.window(Duration.ofSeconds(60), Duration.ofSeconds(2))
.concatMap(w -> w.collect(VoteAggregate::new, VoteAggregate::sum)
.map(VoteAggregate::windowMap), Integer.MAX_VALUE);
}
}
functions can process streams using Reactor
18. Unless otherwise indicated, these slides are Š 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
18
helm init
helm repo add riffrepo https://riff.charts.storage.googleapps.com
helm repo update
helm install riffrepo/riff --name demo
installing riff via helm
helm install riffrepo/riff --name demo --set create.rbac=true
--set httpGateway.service.type=NodePort
19. Unless otherwise indicated, these slides are Š 2013-2017 Pivotal Software, Inc. and licensed under a Creative Commons
Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
demo
19
Kafka
f(x)
f(x)
vote-counter
vote-stream
processor
votes
topic
redis
20. Learn More. Stay Connected.
cloud.spring.io/spring-cloud-function
github.com/projectriff/riff
20
#springone@s1p