The Fn Project

Title (dupe me and change to your title/name)

person

Open Source Serverless Computing

Intro Option 1

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)

Functions-as-a-service (FaaS)

Abstractions

Decreasing concern (and control) over infrastructure implementation

Virtual machines

Functions

Containers

Bare Metal

What is a function?

SHORT

DURATION

STATELESS

LOWER

COST

EVENT

DRIVEN

What’s in a function?

Framework handles hosting and infrastructure to deal with incoming messages and response

    • Provide access via an HTTP(s) API
    • Connect to a set of "Triggers”
    • log, etc.

Functions-as-a-service

Event Sources

Triggers

Function Execution

Backend Services

Business
Intelligence

Analytics

Databases

Compute, Network, Storage

Kubernetes, Docker, and/or Hypervisor

F(n)

F(n)

F(n)

F(n)

Back to Serverless

  • Serverless [Compute] takes FaaS and adds infrastructure management:
    • Auto-scaling based on demand
    • Scaling down to zero instances when not being invoked
    • Patching, rotating, etc.

"Serverless" means not needing to worry about anything under the code.

Intro Option 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 is the compute component in a serverless architecture

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.

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)

Why Serverless? (option 1 dev’y)

  • 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)

Why Serverless? (option 2 businessey)

  • Cost Reduction: Pay only for execution, not for idle, and reduce ops costs
  • Agility: Devs move faster with less dependencies
  • Reliability: Increase reliability of critical apps using modern architectures
  • Innovation: Devs can quickly iterate on new ideas for pennies

Containers vs Functions

Function is a container with a set of known traits:

  • Short running
  • Ephemeral
  • Stateless
  • Invoked
  • Single Purpose
  • Self-contained

What about Microservices?

The Fn Project

  • Independent open-source serverless compute platform built by Iron.io team that led Docker-centric serverless
  • Can be deployed to any cloud and on-premise
  • Containers are primitives
  • Active w/ large core team, 3500+ commits, 75+ contributors
  • Simple by design, enterprise built
  • Native CloudEvents support
  • Will likely contribute to the CNCF
  • Language-based Workflow w/ Fn Flow

For Developers

An Fn Function

  • Small chunk of code wrapped into a container image
  • Gets input via FDK http-stream and environment
  • Produces output to http-stream
  • Logs to STDERR / syslog

The Fn server handles everything else, like the API gateway, piping things around, storing logs, etc.

Fn CLI

  • fn init --runtime go
  • fn deploy --app myapp
  • fn invoke myapp myfunc

→ http://localhost:8080/t/myapp/myfunc

fn deploy details

  • Builds container (multi-stage) + bumps version
  • Pushes container to registry
  • Creates/updates function & triggers (fn servers lazy load images)

MyFunc:0.0.2

MyFunc:0.0.2

MyFunc:0.0.2

Your code

Fn Service

myfunc →

/t/myapp/myfunc:0.0.2

1

2

3

Debugging

  • fn update app cloudevents --syslog-url="tcp+tls://logs7.papertrailapp.com:40277"
  • Metrics created using OpenTracing w/ initial collectors and extensions for Prometheus, ZipKin, and soon Jaeger

Function Development Kits (FDKs)

  • Used to help with parsing input and writing output
  • Familiar syntax for Lambda developers
  • Simply write a `handler` function that adheres to the FDK’s interface and it will parse http-stream and provide the input data to your function and deal with writing the proper output format.
  • Makes it a lot easier to write hot functions

Fn UI

For Operators

Architecture

Fn Server

  • Handles CRUD operations for setting up triggers 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

Runner LB

  • Built into runner with env FN_NODE_TYPE=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

Fn LB Details

Supporting Services

  • DB, MQ, blob store are all pluggable modules that are thin wrappers around their respective drivers.
    • DB: MySQL, sqlite3, Postgres
    • Queue: Redis, Kafka
    • Registry: Any Docker v2-compliant, even private
  • Metrics/Monitoring
    • OpenTracing API for metrics
    • Prometheus support, pluggable backends
    • Logging via syslog

Open Tracing and Prometheus

Request Flow

Request Flow (use this one or the next 2)

Sync Request

Async Request

Scheduling

Fn Scheduling

T0

Fn Scheduling

T1

Fn Scheduling

T2

Fn Scheduling

T3

Fn Scheduling

T4

Fn Scheduling

T5

Fn Scheduling

T6

Kubernetes

Kubernetes

  • Fn is scheduler agnostic but lots of optimization/management work in process to optimize on Kubernetes
  • Helm chart available at https://github.com/fnproject/fn-helm
  • Thinking about deeper Kubernetes integrations including CRD’s to model functions

Kubernetes

Deployment

Why not K8s scheduling?

  • Speed
    • Pod launch time is too slow for sync requests
    • Coordinating all resource alloc to one k8s master is slow
    • Yes we can preload + hot pod like we do with current scheduling but…
  • Scale
    • Runs out of addressable network space quickly
    • Functions easily scale to the hundreds of thousands / millions

Docker

Storage Stuff

  • Tried a lot of various storage drivers
    • Overlay1 ran out of file descriptors / blocks
    • Btrfs container creation / deletion under load was minutes
    • Overlay2 was the only one that ended up tenable

Why DinD?

  • Contained blast radius
    • Doesn’t affect outer VM
    • Kick the fn container and fire up a new one
    • Systemd can manage Fn nicely
  • Control Docker version / config easier for our customers
    • Inner can differ from outer
  • Container name collisions as siblings

Fn Flow

Fn Flow

  • Build long-running, reliable, scalable functions with rich sets of language-specific primitives including fork-join, chaining, delays and error handling
  • Supports complex parallel processes that are readable and testable (including unit tests) with standard programming tools
  • Java support using CompletableFuture API from Java 8 with JS, Python, Go language support on the way!

Plate Detect Function

Draw Function

Slack

Function

Twitter

Function

Scraper

Scraper

Plate Detect Function

Draw Function

Slack

Function

Twitter

Function

FlowFuture.invoke()

thenCompose()

thenCompose()

allOf()

whenComplete()

Scraper

Plate Detect Function

Draw Function

Slack

Function

Twitter

Function

FlowFuture.invoke()

thenCompose()

thenCompose()

allOf()

whenComplete()

Flow Function

Thank you!

Get Involved

  • Star the project: github.com/fnproject/fn
  • Join the conversation: slack.fnproject.io
  • Learn more: fnproject.io
  • We’re hiring engineers and evangelists: chad.arimura@oracle.com

Name

Title

@twitter

Appendix

The Fn Project

FDK’s

Fn Server

Fn Flow

Use Cases

Automation and DevOps

ORACLE CLOUD

Compute

State Change Triggers

Storage

Other

  • Check tags
  • Check security roles
  • Patch or update
  • Modify/kill resource
  • Vulnerability assess

Reports/Notifications

Internet of Things

ORACLE CLOUD

Check data against thresholds. If exceeded, raise support incidents, send notifications

IoT

Trigger functions

Functions

Devices and things streaming sensor data

Incident created in Service Cloud, notification sent to the technician

Mobile

Technician App

Service Cloud

Executive Dashboard

Mobile

ORACLE CLOUD

Identity

Process data

Trigger functions

Functions

Web, Mobile Apps

API Platform

Mobile

Data persisted

Database

Storage

Stream Processing

ORACLE CLOUD

Kafka / Streaming

Database

Perform user sentiment analysis

Trigger functions

Functions

Data from multiple sources – Product Reviews and Ratings, Customer Service Interactions, Social Media, etc.

Records saved in database

Dashboards with user sentiment analysis trends

File Processing

ORACLE CLOUD

Storage

Database

Generate images of different resolutions
and sizes

Trigger functions

Functions

High resolution product image uploaded to storage

Storage

Images saved
in Storage, metadata in Database

Generated images displayed on various pages and devices

Batch

ORACLE CLOUD

Database

Database

Calculate
bonus points

Functions

Utility consumption

Storage

Bonus
points updated

Utility bill PDF file

Transaction details

Scheduled batch job

Functions

Database

Generate utility bill PDF file

PDF files saved in Storage

Consumption details

Scheduled batch job

Loyalty bonus received

Credit card transactions

Best Practices

Best Practice: Keep it Simple

  • Functions should do one thing
  • Don’t import tons of dependencies
  • Don’t string lots of functions together
  • Avoid opening connections

Best Practice: Testing and CI/CD

  • Test functions in the real world (production)
  • Instrument using distributed tracing
  • Log to a service
  • Cold starts happen, test for them
  • Don’t assume scaling is a given

Best Practice: Data

  • Use a data service wherever possible
  • Don’t open connections
  • Understand your queries, serverless does not fix bad data structure

Best Practice: Security

  • Functions broaden the surface area of attack
  • Apply security at the function level
  • Ensure minimum access policies
  • Use container security measures when applicable

Best Practice: Start

  • Start simple and add over time
  • Don’t migrate or rewrite large apps
  • Low hanging fruit
    • Devops use cases (new iaas scanning, auditing running iaas, etc.)
    • Simple, isolated, and async
    • Data processing pipelines
    • Triggers from cloud vendors (storage, compute, etc.)
The Fn Project (master) - Google Slides