+ All Categories
Home > Software > Future of Serverless

Future of Serverless

Date post: 21-Jan-2018
Category:
Upload: yoav-avrahami
View: 285 times
Download: 0 times
Share this document with a friend
67
Transcript
Page 1: Future of Serverless
Page 2: Future of Serverless
Page 3: Future of Serverless

About meYoav Abrahami

Head of Wix Code, Wix.com

https://www.linkedin.com/in/yoavabrahami/

https://www.slideshare.net/yoavaa/

@yoavabrahami

Page 4: Future of Serverless

What we will be talking about?● What is Serverless

● What we at Wix learned by building a serverless platform

● The potential

● The Technology Challenges

● Disruption

Page 5: Future of Serverless

2013, The Cloud Space

Page 6: Future of Serverless

2013, The Cloud Space

We have identified a gap in the cloud platforms space.

No platform aimed at Web AppsNo platform aimed at Websites

Mobile

Page 7: Future of Serverless

2013, The Cloud Space

We set out to build Wix Code

A Serverless Platform for Web Apps and Websites

Mobile

Page 8: Future of Serverless

So...What is Serverless?

Page 9: Future of Serverless

Amazon Lambdavar AWS = require('aws-sdk');

exports.handler = function(event, context) {

handleEvent(event, context);

};

function handleEvent(event, context) {

var cloudSearchDomain = new AWS.CloudSearchDomain({endpoint: config.SearchEndpoint});

var params = {query: event.searchTerm, size: 10, start: 0 };

cloudSearchDomain.search(params, function(err, data) {

if (err) {

context.fail(new Error('Error'));

} else {

context.succeed(processSearchResults(data));

}

});

}

Triggered by:● S3 upload event● Kinesis stream● DynamoDB data change● API Gateway for Mobile● API Gateway for Web Apps

Page 10: Future of Serverless

Amazon Lambdavar AWS = require('aws-sdk');

exports.handler = function(event, context) {

handleEvent(event, context);

};

function handleEvent(event, context) {

var cloudSearchDomain = new AWS.CloudSearchDomain({endpoint: config.SearchEndpoint});

var params = {query: event.searchTerm, size: 10, start: 0 };

cloudSearchDomain.search(params, function(err, data) {

if (err) {

context.fail(new Error('Error'));

} else {

context.succeed(processSearchResults(data));

}

});

}

Amazon Specific APIs

Triggered by:● S3 upload event● Kinesis stream● DynamoDB data change● API Gateway for Mobile● API Gateway for Web Apps

Page 11: Future of Serverless

Google Functions// HTTP functions

exports.helloHttp = function helloHttp (req, res) {

res.send(`Hello ${req.body.name || 'World'}!`);

};

// background functions

exports.helloBackground = function helloBackground (event, callback) {

callback(null, `Hello ${event.data.name || 'World'}!`);

};

Triggered by:● HTTP triggers● Cloud Pub/Sub● Cloud Storage Triggers

Page 12: Future of Serverless

Google Functions// HTTP functions

exports.helloHttp = function helloHttp (req, res) {

res.send(`Hello ${req.body.name || 'World'}!`);

};

// background functions

exports.helloBackground = function helloBackground (event, callback) {

callback(null, `Hello ${event.data.name || 'World'}!`);

}; Google Specific APIs

Triggered by:● HTTP triggers● Cloud Pub/Sub● Cloud Storage Triggers

Page 13: Future of Serverless

Microsoft Azure Functionsmodule.exports.hello = (context, req) => {

const res = {};

if (req.query.name || (req.body && req.body.name)) {

const name = req.query.name || req.body.name;

res.body = `Hello ${name}`;

} else {

res.status = 400;

res.body = 'Please pass a name on the query string or in the request body';

}

context.done(null, res);

};

// another examplemodule.exports.hello = function(context, item) {

context.log("Received item: ${item}");

context.done();

};

Triggered by:● Data Processing● Schedule● Web Hook

Page 14: Future of Serverless

Microsoft Azure Functionsmodule.exports.hello = (context, req) => {

const res = {};

if (req.query.name || (req.body && req.body.name)) {

const name = req.query.name || req.body.name;

res.body = `Hello ${name}`;

} else {

res.status = 400;

res.body = 'Please pass a name on the query string or in the request body';

}

context.done(null, res);

};

// another examplemodule.exports.hello = function(context, item) {

context.log("Received item: ${item}");

context.done();

};

Azure Specific APIs

Triggered by:● Data Processing● Schedule● Web Hook

Page 15: Future of Serverless

Twilio Functionsexports.handler = function(context, event, callback) {

const response = new Twilio.Response();

response.setBody({

hello: 'world'

});

response.appendHeader('Content-Type', 'application/json');

response.appendHeader('MyHeader', 'MyContent');

callback(null, response);

};

Triggered by:● Incoming Voice calls● Incoming Messages

Page 16: Future of Serverless

Twilio Functionsexports.handler = function(context, event, callback) {

const response = new Twilio.Response();

response.setBody({

hello: 'world'

});

response.appendHeader('Content-Type', 'application/json');

response.appendHeader('MyHeader', 'MyContent');

callback(null, response);

};

Twilio Specific APIs

Triggered by:● Incoming Voice calls● Incoming Messages

Page 17: Future of Serverless

Wix Code - Web Modules// server code - calculator.jsw

export function calculateLoad(latency, concurrency, traffic) {

let opsPerMinite = 60000 / latency;

return {

idle: Math.max((1 - traffic / opsPerMinite), 0),

utilization: traffic / opsPerMinite / concurrency

};

}

// client code

import {calculateLoad} from 'backend/calculator';

function doLoadCalculation() {

calculateLoad($w('#latency').value, $w('#concurrency').value, $w('#traffic').value)

.then(res => {

$w('#utilized').text = `${toPercent(res.utilization)} Utilized`;

$w('#idle').text = `${toPercent(res.idle)} Idle`;

});

}

Page 18: Future of Serverless

Wix Code - HTTP Functions// server code

import {ok} from 'wix-functions';

export function get_calculateLoad(request) {

let latency = request.query.latency;

let concurrency = request.query.concurrency;

let traffic = request.query.traffic;

let opsPerMinite = 60000 / latency;

return ok({

body: {

idle: Math.max((1 - traffic / opsPerMinite), 0),

utilization: traffic / opsPerMinite / concurrency

}

});

}

// a call from a client

curl https://yoav68.wixsite.com/load-calculator/_functions-dev/calculateLoad\?latency\=10\& concurrency\=20\&traffic\=1000

Page 19: Future of Serverless

… Server-Side logic ... … written by the application developer …... run in stateless compute containers ...

... event-triggered, ephemeral (...), and fully managed by a 3rd party

-- Martin Fowler quoting ThoughtWorks

Page 20: Future of Serverless

The Magic Pitch● No Servers to Manage● Magic Scaling● Pay only for what you use● Just throw your code

Almost sounds like:

Serverless is the DevOps holy grail - Just throw your code over the wall...

Page 21: Future of Serverless

The TradeGoing Serverless means a trade:

You trade your Freedom for a Managed Service

Sign here to use my Serverless

Page 22: Future of Serverless

The TradeYou trade your Freedom for a Managed Service

Select web framework

Websockets

HTTP streaming / chunked

TCP / IP / UDP

Select programming Language

Page 23: Future of Serverless

The Future of Serverless

Page 24: Future of Serverless

History of ServerlessM

anag

ed S

olut

ion

1995 1999 2006 2008 2012 2014 2017

Hosted PHP

Ease of useFreedom

Page 25: Future of Serverless

History of ServerlessM

anag

ed S

olut

ion

1995 1999 2006 2008 2012 2014 2017

Hosted PHP

J2EE

Ease of useFreedom

Page 26: Future of Serverless

History of ServerlessM

anag

ed S

olut

ion

1995 1999 2006 2008 2012 2014 2017

Hosted PHP

J2EEEC2

Ease of useFreedom

Page 27: Future of Serverless

History of ServerlessM

anag

ed S

olut

ion

1995 1999 2006 2008 2012 2014 2017

Hosted PHP

J2EEEC2

AppEngine

Ease of useFreedom

Page 28: Future of Serverless

History of ServerlessM

anag

ed S

olut

ion

1995 1999 2006 2008 2012 2014 2017

Hosted PHP

J2EEEC2

AppEngine

Parse.com

Ease of useFreedom

Page 29: Future of Serverless

History of ServerlessM

anag

ed S

olut

ion

1995 1999 2006 2008 2012 2014 2017

Hosted PHP

J2EEEC2

AppEngine

Parse.com

Managed Containers

Amazon Lambda

Ease of useFreedom

Page 30: Future of Serverless

History of ServerlessM

anag

ed S

olut

ion

1995 1999 2006 2008 2012 2014 2017

Hosted PHP

J2EEEC2

AppEngine

Parse.com

Managed Containers

Amazon Lambda

Wix CodeEase of useFreedom

Page 31: Future of Serverless

Predictions

Page 32: Future of Serverless

More Serverless Freedom ● Expanding for full support of HTTP, including

● WebSockets

● Streaming / chunked

● Additional protocols - TCP, UDP

● Memoise as a Service - For stateless, side-effect-free functions

● Native serverless options - Go, Rust, C, etc.

Page 33: Future of Serverless

Consolidation● Vendors will start to offer similar offerings

● Cross-vendor libraries to ease vendor lockPartial adoption, vendor ‘added value’ features.import futureLibrary from 'FUTURE_LIBRARY';

futureLibrary.initMagic(exports, 'AWS');

futureLibrary.eventFunction = function handleEvent(event) {

event.respond(...);

}

● Standards will ariseAll vendors will join, never to fully support. ‘added value’ extras

Page 34: Future of Serverless

Containers

Page 35: Future of Serverless

Future of ContainersContainers and Kubernetes have a hard choice to make

● Serverless over Kubernetes - Kubernetes will evolve into runtime for serverlessMove to deploy functions directly, not containers

● Kubernetes and Containers will be abstracted outBecome less and less relevant over time

Page 36: Future of Serverless

Containers vs Serverless● Containers and Kubernetes are a system product built by developers

○ Building Docker images

○ Managing running instances

● Serverless are developer facing products

○ Trivial packaging

○ Instances are no longer a concern

● Serverless is a higher level of abstraction

Page 37: Future of Serverless

Serverless Orchestration● A serverless runtime will emerge for serverless application Orchestration

● Will run on premise or on cloud

● Based on containers or not

Photo: https://www.secsign.com/cloud-vs-premise-file-sharing-business-4-practical-issues-consider/

Page 38: Future of Serverless

The Cold Start Problem

Page 39: Future of Serverless

What is Cold Start?Have you ever seen this message?

Page 40: Future of Serverless

Solving the Cold Start ProblemNew technology will emerge, taking Cold Start time to under 100 mSec

● Start a VM / Container / Unikernels / Sandbox in under 100 mSec.

If your applications starts in 10 mSec

● Do you need an application instance running 24x7?● Do you need a fallback instance running 24x7?● Do you need your database running 24x7?

Page 41: Future of Serverless

Solving the Cold Start ProblemSolving cold start Changes Cloud Economy

● Imaging a server

0.8% Utilized

84% Idle

Latency: 10 ms / request

Can handle 20 concurrent requests

Traffic: 1000 RPM

Page 42: Future of Serverless

Solving the Cold Start ProblemSolving cold start Changes Cloud Economy

● Imaging a server

0.8% Utilized

84% Idle

Latency: 10 ms / request

Can handle 20 concurrent requests

Traffic: 1000 RPMIt takes 150,000 daily users, 10 requests each, to generate 1000 RPM

Page 43: Future of Serverless

Solving the Cold Start ProblemSolving cold start Changes Cloud Economy

● Imaging a server

0.8% Utilized

84% Idle

Latency: 10 ms / request

Can handle 20 concurrent requests

Traffic: 1000 RPMIt takes 150,000 daily users, 10 requests each, to generate 1000 RPM

At Wix - with over 100,000,000 users...of 2,500 running processesOnly 10% are over 1000 RPM

Page 44: Future of Serverless

Pay only for what you use● Functions - You only pay when your function is running

● Interesting fact - the marketing pitch of VMs 10 years ago was “only pay for what you use”

● Interesting fact - the marketing pitch of App Engine 8 years ago was “only pay for what you use”

● What went wrong?

Cold Start Latency

Page 45: Future of Serverless

Cold Start Latency ExplainedThe time it takes for a process that is not running to respond to the first user

Functions Cold Start time - about 600ms - 2 seconds

~10 mSec

Request Handler

~100-1000 mSec

Start process

First Browser HTTP request

First response

Scheduler Overhead

2-120 Sec

Start instance

● VMs - about 2 minutes● Containers - about 2 seconds

Page 46: Future of Serverless

Cold Start LatencyWhat it means?

● Functions are great for offline events

● Functions are ok for web apps APIs / REST / AJAX

● Functions are fine for high traffic websites - HTML

● Functions are not usable for websites - HTML

Page 47: Future of Serverless

Website Latency requirementFunctions are not usable for websites - HTML

● Must meet a strict SLA - time to first byte

● Fast websites aim for under 100 mSec (measured on server)

● 200-500 mSec is standard

● Over 2 Sec is considered slow and can harm a website ranking

Page 48: Future of Serverless

Cold Start LatencyWhat it means?

● Functions are great for offline events

● Functions are ok for web apps APIs / REST / AJAX

● Functions are fine for high traffic websites - HTML

● Functions are not usable for websites - HTMLNote: In terms of latency, VMs and Containers are just as good for offline events, web apps and high traffic websites.

Page 49: Future of Serverless

How we Solved Cold Start

<100 mSec Minutes to hours

Cold start time

Working process

Start process

First Browser HTTP request

stopping process

Inject & Load user code

Page 50: Future of Serverless

Tailored Serverless

Page 51: Future of Serverless

Tailored ServerlessSolves a specific business problem

● Twilio - serverless reaction to phone or SMS events

● CloudFlare - serverless proxy logic

● Wix Code - serverless platform for the frontend

● We will see more examples like Data Processing, Edge logic or Real-time Video processing

Page 52: Future of Serverless

Serverless replacing Configuration● Fact - the #1 configuration representation is Javascript

● Fact - the #2 configuration representation is JVM Bytecode

export function newEmailHook(email) {

If (email.from ===

'[email protected]')

email.labels.push('J2XB');

}

Page 53: Future of Serverless

Let’s take Serverless for Frontend as another example(Wix Code is such a platform)

Page 54: Future of Serverless

Why Serverless for the Frontend?

Page 55: Future of Serverless

What it means, Serverless for Web Apps?Websites?

Page 56: Future of Serverless

What is the difference between Web Apps and Websites?

SEO

Page 58: Future of Serverless

Web Apps ↔ Websites?Actually, it is Search Engine Compatibility

Website Search Engines

Social Networks Bots

Server Side Rendering

Found By

Found By Indexed by

read by

expects

Page 59: Future of Serverless

Web Apps ↔ Websites?Actually, it is Search Engine Compatibility

Website Search Engines

Social Networks Bots

Server Side Rendering

Found By

Found By Indexed by

read by

expects

Challenging

Page 60: Future of Serverless

Traditional model - server side language (Ruby, PHP, Java) client built with React, Angular, Vue, etc.

● Double development, traditionally done by different people

Emerging model - server and client side using javascriptrendering using React, Angular, Meteor, etc.

● Challenging as server rendering time is easily in the 200-600 mSec for a simple website

● Challenging to setup and configure

Server Side Rendering - Challenging to Develop

Page 61: Future of Serverless

Lets to the trade againGoing Serverless for frontend

You trade your Freedom for a Managed Service

Sign here to use my Serverless

Page 62: Future of Serverless

Solving Server Side RenderingServer Side Rendering with time to first byte under 100 mSec

~10 mSec 200-600 mSec

Router Function

Rendering Function

100-1000 mSec

Headreceived

Browser Loading Scripts

DOMContentLoaded

Rendering Function on client

<100 mSec

Cold Start Time

Browser makes HTTP request

Page 63: Future of Serverless

Rethink the Web Server● Controller Functions

Server functions, handle HTTP request and render HTML, Json, etc.

● Router FunctionsServer function, handles HTTP request and selects a page

● Rendering FunctionsIsomorphic function that renders the page HTML / DOM.

Page 64: Future of Serverless

Serverless for FrontendWhat you gain

● Cold Start Solution

● Server side rendering

● HTTP Streaming

● Router & Rendering functions

● REST / AJAX functions

● CDN, Domain, Assets, etc.

What you lose

● Choice of a frontend framework

● Choice of a server framework

● Choice of FE build processMinification, Aggregation, ES6 compile, etc.

Page 65: Future of Serverless

Takeaway

Page 66: Future of Serverless

Serverless

Serverless Orchestration

Disrupts Containers

Cold Start

Disrupt Clouds

Tailored Serverless

Disrupt Frontend Dev

Disrupt Configuration

Page 67: Future of Serverless

Stickers


Recommended