2. What is Serverless?
● Serverless is an abstraction of infrastructure and its operations
including provisioning, scaling, patching, etc.
● Serverless architecture is when an app is built entirely on
serverless components (compute, storage, networking)
● FaaS (Functions as a Service) is the compute component in a
serverless architecture
2
3. Functions as a Service
● Functions are small bits of code that do one thing well and are
easy to understand and maintain
● As a Service means no complicated plumbing, the system
takes care of provisioning, scaling, patching, maintaining, etc.
Each function scales independently. 3
In mathematics, a function is a relation between
a set of inputs and a set of permissible outputs
with the property that each input is related to
exactly one output.
Function (mathematics) - Wikipedia
https://en.wikipedia.org/wiki/Function_(mathematics)
10. Introducing the Fn Project
● Open-source serverless compute platform
● Can be deployed to any cloud and on-premise
● Simple, elegant, and extensible by design
● Containers are primitives
● Active w/ 2500+ commits across 50+ contributors
● Independently governed with representation at Container
Native Compute Foundation (CNCF)
● Strong enterprise focus (security, scalability, observability, etc.)
10
11. An Fn Function
11
● Code wrapped in a container
image
● Input from STDIN and
environment
● Output to STDOUT
● Logs to STDERR
The Fn server handles everything else
12. Function Development Kits (FDKs)
● Used to help with parsing input and writing output
● Simply write a `handler` function that adheres to the FDK’s
interface and it will parse STDIN and provide the input data to
your function and deal with writing the proper output format.
● Makes it a lot easier to write functions
12
13. Functions == Containers
13
Functions are packaged as
containers—so any
container can be deployed
as a function
Package and reuse open
source libraries as functions!
14. Containers vs Functions
Fn Function is a container with
a set of known traits:
● Short running
● Ephemeral
● Stateless
● Invoked
● Single Purpose
● Self-contained
14
15. Fn CLI
● fn init --runtime go
● fn run
● fn test
● fn deploy --app myapp
● fn call myapp myfunc
route → http://localhost:8080/r/myapp/myfunc 15
17. Fn Server
● Handles CRUD operations for setting up routes and functions
● Executes sync functions, returning responses to clients
immediately
● Queues async function calls
● Executes async functions when capacity is available
● Written in Go, easy to extend via plugin module system
18. Fn LB
● Simple, fast load balancer that routes functions to certain
nodes consistently for hot function efficiency
● Scales each function independently based on traffic to any
particular function
● Can be used to scale Fn servers and infrastructure as well as it
has a view of global state of all fn servers
20. fn deploy details
1. Builds container (multi-stage) + bumps version
MyFunc:0.0.2
Your code
1
20
21. fn deploy details
1. Builds container (multi-stage) + bumps version
2. Pushes container to registry
MyFunc:0.0.2
MyFunc:0.0.2
Your code
1 2
21
22. fn deploy details
1. Builds container (multi-stage) + bumps version
2. Pushes container to registry
3. Creates/updates function route (fn servers lazy load images)
MyFunc:0.0.2
MyFunc:0.0.2 MyFunc:0.0.2
Your code
Fn Service
myfunc →
/r/myapp/myfunc:0.0.2
1 2 3
22
23. fn deploy --local
1. Builds container (multi-stage) + bumps version
2. Pushes container to registry
3. Creates/updates function route (fn servers lazy load images)
MyFunc:0.0.2
MyFunc:0.0.2
Your code
Fn Service
myfunc →
/r/myapp/myfunc:0.0.2
1
MyFunc:0.0.2
2 3
23
24. Debugging
● fn calls list myapp
● fn calls get myapp <call-id>
● fn logs get myapp <call-id>
● Metrics created using OpenTracing w/ initial collectors and
extensions for Prometheus, ZipKin, and soon Jaeger
24
29. Fn Flow
● For long-running, reliable, scalable functions with primitives for
fork-join, chaining, delays and error handling
● Java support using CompletableFuture API from Java 8—
Node, Python, Go support on the way!
29
30. Fn Flow Example—Generate Resized Images
30
public Response handleRequest(byte[] imageBuffer) {
String id = java.util.UUID.randomUUID().toString();
CloudThreadRuntime runtime = CloudThreads.currentRuntime();
mm.notify("Resizing " + imageBuffer.length + " with id " + id);
runtime.allOf(
runtime.invokeFunction("myapp/resize128", imageBuffer)
.thenAccept((img) -> swiftClient.swiftUpload(img, id + "-128.png"))
.thenRun(() -> mm.notify("Uploaded 128px image")),
runtime.invokeFunction("myapp/resize256", imageBuffer)
.thenAccept((img) -> swiftClient.swiftUpload(img, id + "-256.png"))
.thenRun(() -> mm.notify("Uploaded 256px image")),
runtime.invokeFunction("myapp/resize512", imageBuffer)
.thenAccept((img) -> swiftClient.swiftUpload(img, id + "-512.png"))
.thenRun(() -> mm.notify("Uploaded 512px image")),
runtime.invokeAsync(() -> swiftClient.swiftUpload(imageBuffer, id + ".png"))
).whenComplete((val,err) -> {
if(err!= null){
mm.notify("An error occurred while uploading images " + err.getMessage());
} else {
mm.notify("All images uploaded to id " + id);
}
});
return new Response(id);
}
31. 31
Fn Flow Example—Multiple Stages & Threads
Notify the user “Resizing is being performed”
Do all of the following in parallel:
Run function "myapp/resize128” to resize image to 128px
Then upload the 128px image to storage
Then notify the user the 128px image was uploaded
Run function "myapp/resize256” to resize image to 256x256
Then upload the 128px image to storage
Then notify the user the 128px image was uploaded
Run function “myapp/resize512” to resize image to 512x512
Then upload the 128px image to storage
Then notify the user the 128px image was uploaded
Upload the original image to storage
When all functions are complete:
Then notify the user that "All images uploaded"
2.a
2.b
2.c
2.d
3
1
37. Fn—An Ideal Functions Platform?
✅ Open Source—no vendor lock-in
✅ Platform Independent—laptop, server, cloud
✅ Approachable—easy for new users, low level controls for
advanced users
✅ Docker Based—leverage Docker ecosystem
✅ Scheduler Independent—deploy to Kubernetes, Swarm,
Mesos, etc.
37
http://fnproject.io
38. Thank you!
1. Star the project: github.com/fnproject/fn
2. Join the conversation: slack.fnproject.io
3. Learn more: fnproject.io
Shaun Smith
@shaunMsmith
Get Involved
Hinweis der Redaktion
Easier: Just think about your code, not infrastructure
Powerful: Transparent and limitless scaling
Faster: Deploy faster, iterate faster, innovate faster
Cheaper: Only pay for what you use to the 100ms (never idle)
I’ll let you into a secret. There are servers. Lots of servers. And networking gear. Storage too. We just don’t want to have to think about them anymore. In this session we’ll learn how to build, from the ground up, a scalable, reliable app without once mentioning virtual machines, load balancers, volumes, auto-scaling groups (or even containers that much).
I’ll let you into a secret. There are servers. Lots of servers. And networking gear. Storage too. We just don’t want to have to think about them anymore. In this session we’ll learn how to build, from the ground up, a scalable, reliable app without once mentioning virtual machines, load balancers, volumes, auto-scaling groups (or even containers that much).
Your FaaS platform will enable your app to scale organically per-request without you having to write any special code to handle it. And not just the gentle seasonal changes in demand that a retail business might experience but also sudden, dramatic surges in demand caused by your app going viral.
17 minutes to here
24.5 minutes to here.
29.5 to here
OK so so have a great way to build small, scalable functions but what do we do when we want to write a more complex app. One that has long-lived workflows and fault cases that we need to handle gracefully?
This workflow or composition problem is actually a general one that most serverless applications have once they reach some level of complexity. There are 2 naive approaches:
- Write a blocking master function that runs one function, waits for the result, then runs the next etc. This might be easy to understand but we lose a lot of the nice characteristics of a serverless app when we do this. This master function is long-running and consumes resources for the whole time that the individual functions are running. When the booking processes take minutes this can get expensive. It's also not very reliable: if this master function dies then we've got no easy way of recovering.
- Chain the next function by directly calling it. This ends up being a maintenance nightmare very quickly as all of a sudden each upstream function has to know about every downstream one so that it can gather and pass the right data down the chain. It's also very difficult to deal with errors. Fan-in / join is tricky.
Details:
----------
Built on familiar CompletionStage interface from Java 8
Chain together many functions in an arbitrary graph
Fan-out / fan-in, timeouts, exception handling
Orchestrate complex workflows in one place
Language native function orchestration—natural for developer
Java initially with additional language support to follow
29.5 to here
OK, so let’s just recap what we’ve just seen and what it enables you to do.
Develop small, reusable functions in Java and have the platform deal with scale, deployment and all the infrastructure concerns
Then use a familiar API in your favorite language (still Java) to orchestrate work. No more ‘programming’ in large globs of JSON. Or XML <shudder>
Orchestrate many functions in an arbitrary graph
Fan-out / fan-in, timeouts, exception handling
Java language binding using standard API
Other language bindings coming soon
Powerful but easy to use
Fn Flow started with Java but there’s already early support for Go, Node.js, and even Amazon Step Functions text format. With Fn Flow you can work in your language of choice and compose and orchestrate functions to build sophisticated applications.