Are you being servered? — Exploring a “serverless” web

A presentation at LeedsJS in August 2019 in Leeds, UK by Phil Hawksworth

Slide 1

Slide 1

ARE YOU BEING SERVERED? EXPLORING A SERVERLESS WEB PHIL HAWKSWORTH

Slide 2

Slide 2

netlify Are you being servered? @philhawksworth

Slide 3

Slide 3

netlify Are you being servered? @philhawksworth

Slide 4

Slide 4

netlify Are you being servered? @philhawksworth

Slide 5

Slide 5

netlify Are you being servered? @philhawksworth

Slide 6

Slide 6

netlify Are you being servered? @philhawksworth

Slide 7

Slide 7

netlify Are you being servered? @philhawksworth

Slide 8

Slide 8

netlify Are you being servered? @philhawksworth WIRELESS

Slide 9

Slide 9

netlify Are you being servered? @philhawksworth SERVERLESS

Slide 10

Slide 10

netlify Are you being servered? @philhawksworth FOCUSSING ON THE THINGS YOU CARE ABOUT

Slide 11

Slide 11

netlify Are you being servered? @philhawksworth FOCUSSING ON THE THINGS YOU o t e v ha CARE ABOUT

Slide 12

Slide 12

netlify Are you being servered? @philhawksworth d e t a r e b li TO FOCUS ON WHAT MATTERS

Slide 13

Slide 13

netlify Are you being servered? @philhawksworth h it w m e l b o r p e h t DOING BIG PROJECTS

Slide 14

Slide 14

netlify Are you being servered? @philhawksworth CONSTRAINTS AND COMPLEXITY AND INFRASTRUCTURE ! y m oh

Slide 15

Slide 15

netlify Are you being servered? @philhawksworth WHERE TO FOCUS OUR EFFORTS?

Slide 16

Slide 16

netlify Are you being servered? @philhawksworth http://full-stack.netlify.com

Slide 17

Slide 17

netlify Are you being servered? LINES AND BOXES @philhawksworth

Slide 18

Slide 18

netlify Are you being servered? @philhawksworth @ PHIL HAWKSWORTH HE / HIM DEVELOPER EXPERIENCE, NETLIFY

Slide 19

Slide 19

netlify Are you being servered? @philhawksworth FINDTHAT.AT/JAMSTACK-BOOK

Slide 20

Slide 20

netlify Are you being servered? @philhawksworth FINDTHAT.AT/SOMETHINGSOMETHING FINDTHAT.AT/SERVERED FINDTHAT.AT

Slide 21

Slide 21

ARE YOU BEING SERVERED? EXPLORING A SERVERLESS WEB PHIL HAWKSWORTH

Slide 22

Slide 22

netlify Are you being servered? @philhawksworth

Slide 23

Slide 23

Slide 24

Slide 24

Slide 25

Slide 25

ARE YOU BEING SERVERED? EXPLORING A SERVERLESS WEB PHIL HAWKSWORTH

Slide 26

Slide 26

netlify Are you being servered? @philhawksworth FUNCTIONS AS A SERVICE

Slide 27

Slide 27

netlify Are you being servered? @philhawksworth SERVING WEBSITES WITHOUT WEBSERVERS

Slide 28

Slide 28

netlify Are you being servered? @philhawksworth

Slide 29

Slide 29

netlify Are you being servered? @philhawksworth k c a t s m ja JAVASCRIPT / API / MARKUP

Slide 30

Slide 30

netlify Are you being servered? @philhawksworth STACKS FOR DAYZ AN / LAMP / MAMP / XAMP / ROR / WISA / MEA WISA / MEAN / LAMP / MAMP / XAMP / ROR /

Slide 31

Slide 31

netlify Are you being servered? @philhawksworth k c a t s m a j A modern architecture — Create fast and secure sites and dynamic apps with JavaScript, APIs, and pre-rendered Markup, served without web servers

Slide 32

Slide 32

netlify Are you being servered? @philhawksworth BAKE, DON’T FRY – Aaron Swartz http://www.aaronsw.com/weblog/000404

Slide 33

Slide 33

netlify Are you being servered? @philhawksworth I CARE ABOUT NOT HAVING TO MAINTAIN CRANKY AOLSERVER, POSTGRES AND ORACLE INSTALLS AARON SWARTZ, 2002 http://www.aaronsw.com/weblog/000404

Slide 34

Slide 34

netlify Are you being servered? @philhawksworth TOOLS AND ECOSYSTEM

Slide 35

Slide 35

netlify Are you being servered? @philhawksworth SO… WHAT CAN A STATIC SITE EVEN BE?

Slide 36

Slide 36

netlify Are you being servered? @philhawksworth REACTJS.ORG REACTJS.ORG STATIC

Slide 37

Slide 37

netlify Are you being servered? @philhawksworth YARNPKG.COM REACTJS.ORG STATIC

Slide 38

Slide 38

netlify Are you being servered? @philhawksworth VUEJS.ORG REACTJS.ORG

Slide 39

Slide 39

netlify Are you being servered? @philhawksworth A LITTLE MORE “DYNAMIC”

Slide 40

Slide 40

netlify Are you being servered? @philhawksworth SMASHINGMAGAZINE.COM SMASHINGMAGAZINE.COM

Slide 41

Slide 41

Slide 42

Slide 42

netlify Are you being servered? @philhawksworth

Slide 43

Slide 43

netlify Are you being servered? @philhawksworth PHILIP GOT COCKY

Slide 44

Slide 44

netlify Are you being servered? @philhawksworth SOME PEOPLE ON THE INTERNET NOTICED

Slide 45

Slide 45

netlify Are you being servered? @philhawksworth !

Slide 46

Slide 46

netlify Are you being servered? @philhawksworth

Slide 47

Slide 47

netlify Are you being servered? @philhawksworth

Slide 48

Slide 48

netlify Are you being servered? @philhawksworth

Slide 49

Slide 49

netlify Are you being servered? @philhawksworth FINDTHAT.AT/TIME https://setyourwatchby.netlify.com

Slide 50

Slide 50

netlify Are you being servered? @philhawksworth FINDTHAT.AT/TIME https://setyourwatchby.netlify.com

Slide 51

Slide 51

netlify Are you being servered? @philhawksworth FINDTHAT.AT/TIME https://setyourwatchby.netlify.com

Slide 52

Slide 52

netlify Are you being servered? @philhawksworth FINDTHAT.AT/TIME https://setyourwatchby.netlify.com

Slide 53

Slide 53

netlify Are you being servered? WEBSTASK.IO @philhawksworth

Slide 54

Slide 54

netlify Are you being servered? WEBSTASK.IO @philhawksworth

Slide 55

Slide 55

netlify Are you being servered? @philhawksworth ( DON’T DO THIS )

Slide 56

Slide 56

netlify Are you being servered? @philhawksworth a t a k o o l k c i u q TWO PRINCIPLES

Slide 57

Slide 57

netlify Are you being servered? @philhawksworth PRE-RENDERING

Slide 58

Slide 58

netlify Are you being servered? @philhawksworth PRE-RENDERING SERVERLESS ON-DEMAND

Slide 59

Slide 59

netlify Are you being servered? @philhawksworth r o f s e v i t o m PRE-RENDERING

Slide 60

Slide 60

netlify Are you being servered? @philhawksworth DOING THE WORK NOW, SO YOUR SERVERS DON’T HAVE TO LATER

Slide 61

Slide 61

netlify Are you being servered? @philhawksworth PUT DISTANCE BETWEEN THE COMPLEXITY AND THE USER

Slide 62

Slide 62

netlify Are you being servered? l a n o i it d a r t k c a t s m ja @philhawksworth CDN LOAD BALANCER WEB SERVERS DB SERVERS

Slide 63

Slide 63

netlify Are you being servered? @philhawksworth k c a t s m ja REQUEST TIME BULD TIME DEPLOYMENT BUILD

Slide 64

Slide 64

netlify Are you being servered? @philhawksworth JAMSTACK ADVANTAGES SECURITY PERFORMANCE SCALE

Slide 65

Slide 65

netlify Are you being servered? @philhawksworth SECURITY

Slide 66

Slide 66

netlify Are you being servered? @philhawksworth A GREATLY REDUCED SURFACE AREA

Slide 67

Slide 67

netlify Are you being servered? l a n o i it d a r t k c a t s m ja @philhawksworth CDN LOAD BALANCER WEB SERVERS DB SERVERS

Slide 68

Slide 68

netlify Are you being servered? @philhawksworth FAR FEWER MOVING PARTS TO ATTACK

Slide 69

Slide 69

netlify Are you being servered? @philhawksworth PERFORMANCE

Slide 70

Slide 70

netlify Are you being servered? @philhawksworth TRADITIONAL STACKS ADD STATIC LAYERS IN ORDER TO IMPROVE PERFORMANCE

Slide 71

Slide 71

netlify Are you being servered? @philhawksworth CACHING GALORE

Slide 72

Slide 72

netlify Are you being servered? l a n o i it d a r t k c a t s m ja @philhawksworth CDN LOAD BALANCER WEB SERVERS DB SERVERS

Slide 73

Slide 73

netlify Are you being servered? @philhawksworth SCALE

Slide 74

Slide 74

netlify Are you being servered? @philhawksworth TRADITIONAL STACKS ADD INFRASTRUCTURE IN ORDER TO SCALE

Slide 75

Slide 75

netlify Are you being servered? l a n o i it d a r t k c a t s m ja @philhawksworth CDN LOAD BALANCER WEB SERVERS DB SERVERS

Slide 76

Slide 76

netlify Are you being servered? @philhawksworth DECOUPLING

Slide 77

Slide 77

netlify Are you being servered? GET TO THE CHOPPER CDN @philhawksworth

Slide 78

Slide 78

netlify Are you being servered? @philhawksworth

Slide 79

Slide 79

netlify Are you being servered? @philhawksworth PRE-RENDERING SERVERLESS ON-DEMAND

Slide 80

Slide 80

netlify Are you being servered? @philhawksworth PRE-RENDERING SERVERLESS ON-DEMAND

Slide 81

Slide 81

netlify Are you being servered? @philhawksworth k c a t s m a j A modern architecture — Create fast and secure sites and dynamic apps with JavaScript, APIs, and pre-rendered Markup, served without web servers

Slide 82

Slide 82

netlify Are you being servered? @philhawksworth I ABSOLUTELY POSITIVELY NEED A LITTLE LOGIC ON A SERVER MANY OF US, SOMETIMES

Slide 83

Slide 83

netlify Are you being servered? @philhawksworth SERVERLESS TO THE RESCUE

Slide 84

Slide 84

netlify Are you being servered? @philhawksworth LET’S JUST RECREATE EVERYTHING IN SERVERLESS FUNCTIONS THAT VOICE OF TEMPATION

Slide 85

Slide 85

netlify Are you being servered? @philhawksworth k c a t s m a j A modern architecture — Create fast and secure sites and dynamic apps with JavaScript, APIs, and pre-rendered Markup, served without web servers

Slide 86

Slide 86

netlify Are you being servered? @philhawksworth e e r f FROM INFRASTRUCTURE e e r f t o n t bu FROM DYNAMIC LOGIC

Slide 87

Slide 87

netlify Are you being servered? @philhawksworth AUGMENTATION

Slide 88

Slide 88

netlify Are you being servered? @philhawksworth ENHANCEMENT

Slide 89

Slide 89

netlify Are you being servered? @philhawksworth STATIC FIRST MARKUS SCHORK, UNILEVER

Slide 90

Slide 90

netlify Are you being servered? @philhawksworth AN EXAMPLE

Slide 91

Slide 91

netlify Are you being servered? @philhawksworth AN EXAMPLE

Slide 92

Slide 92

netlify Are you being servered? @philhawksworth AN EXAMPLE

Slide 93

Slide 93

netlify Are you being servered? @philhawksworth VLOLLY.NET/LOLLY/3hmtt2r3b AN EXAMPLE

Slide 94

Slide 94

netlify Are you being servered? @philhawksworth s t n e m e r i u q re

Slide 95

Slide 95

netlify Are you being servered? @philhawksworth PRE-GENERATED PAGES WITH REAL URLS (EVEN FOR THE USER GENERATED CONTENT) DATA STORED IN A DATABASE (BUT DON’T MAKE ME A DBA) INSTANT ACCESS TO NEW CONTENT (WITHOUT WAITING FOR A REBUILD)

Slide 96

Slide 96

netlify Are you being servered? @philhawksworth s l o to

Slide 97

Slide 97

netlify Are you being servered? @philhawksworth PRE-GENERATED PAGES WITH REAL URLS ELEVENTY (EVEN FOR THE USER GENERATED CONTENT) DATA STORED IN A DATABASE FAUNADB (BUT DON’T MAKE ME A DBA) INSTANT ACCESS TO NEW CONTENT NETLIFY FUNCTIONS (WITHOUT WAITING FOR A REBUILD)

Slide 98

Slide 98

netlify Are you being servered? @philhawksworth

Slide 99

Slide 99

netlify Are you being servered? @philhawksworth

Slide 100

Slide 100

netlify Are you being servered? @philhawksworth const faunadb = require(‘faunadb’); const q = faunadb.query; const client = new faunadb.Client({ secret: process.env.FAUNADB_SERVER_SECRET }); module.exports = () !=> { return new Promise((resolve, reject) !=> { client.query( q.Paginate(q.Match(q.Ref(“indexes/all_lollies”))) ).then((response) !=> { const lollies = response.data; const getAllDataQuery = lollies.map((ref) !=> { return q.Get(ref); }); return client.query(getAllDataQuery).then((ret) !=> { resolve(ret); }); }).catch((error) !=> { reject(error); }); }) } Authenticate with the DB query for all d n a . .. s ie l l o l e h t their data resolve the s ie l l o l f o e is prom s r o r r e y n a h c cat

Slide 101

Slide 101

netlify Are you being servered? @philhawksworth

Slide 102

Slide 102

netlify Are you being servered? @philhawksworth

Slide 103

Slide 103

netlify Are you being servered? @philhawksworth

Slide 104

Slide 104

netlify Are you being servered? @philhawksworth

Slide 105

Slide 105

netlify Are you being servered? @philhawksworth

Slide 106

Slide 106

netlify Are you being servered? @philhawksworth 404

Slide 107

Slide 107

netlify Are you being servered? @philhawksworth TRIGGERS AND AUTOMATION

Slide 108

Slide 108

netlify Are you being servered? @philhawksworth AN EXAMPLE

Slide 109

Slide 109

netlify Are you being servered? @philhawksworth

Slide 110

Slide 110

netlify Are you being servered? @philhawksworth const faunadb = require(‘faunadb’); const shortid = require(‘shortid’); const querystring = require(‘querystring’); const axios = require(‘axios’); const q = faunadb.query const client = new faunadb.Client({ secret: process.env.FAUNADB_SERVER_SECRET }) exports.handler = (event, context, callback) !=> { const data = querystring.parse(event.body); const uniquePath = shortid.generate(); data.lollyPath = uniquePath; const lolly = { data: data }; client.query(q.Create(q.Ref(‘classes/lollies’), lolly)) .then((response) !=> { axios.post(‘https:!//api.netlify.com/build_hooks/5d46fa20da4a1b70047f2f04’) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }); return callback(null, { body: JSON.stringify(response), statusCode: 302, headers: { Location: /lolly/${uniquePath}, } }); }).catch((error) !=> { return callback(null, { statusCode: 400, body: JSON.stringify(error) }); }); } Authenticate with the DB a t a d e h t t s o P rebuild r e s u e h t d n e S To check the freezer FOR A LOLLY

Slide 111

Slide 111

netlify Are you being servered? @philhawksworth WHAT THE DICKENS DOES “CHECK THE FREEZER FOR A LOLLY” MEAN? ALL OF YOU, POSSIBLY

Slide 112

Slide 112

netlify Are you being servered? CHECK FOR A PRE-GENERATED LOLLY PAGE @philhawksworth 200 SERVE THE STATIC PAGE 404 RENDER A DYNAMIC VIEW

Slide 113

Slide 113

netlify Are you being servered? @philhawksworth

Slide 114

Slide 114

netlify Are you being servered? @philhawksworth

Slide 115

Slide 115

netlify Are you being servered? @philhawksworth const faunadb = require(‘faunadb’); const pageTemplate = require(‘./lollyTemplate.js’); const q = faunadb.query; const client = new faunadb.Client({ secret: process.env.FAUNADB_SERVER_SECRET }); exports.handler = (event, context, callback) !=> { const path = event.queryStringParameters.id.replace(“/”, “”); client.query( q.Get(q.Match(q.Index(“lolly_by_path”), path)) ).then((response) !=> { return callback(null, { statusCode: 200, body: pageTemplate(response.data) }); }).catch((error) !=> { return callback(null, { body: JSON.stringify(error), statusCode: 301, headers: { Location: /melted/index.html, } }); }); } Get page as a javascript l a r e it l e t a l p tem Authenticate with the DB Get the lolly data w ie v y l l o l e v r e S k a e r B . y l l o L o N the bad news

Slide 116

Slide 116

netlify Are you being servered? a @philhawksworth ? o m e d k c i qu

Slide 117

Slide 117

netlify Are you being servered? @philhawksworth s r e l b a en

Slide 118

Slide 118

netlify Are you being servered? @philhawksworth CUSTOM 404 ROUTING

Slide 119

Slide 119

netlify Are you being servered? @philhawksworth [[redirects]] from = “/lolly!/*” to = “/.netlify/functions/showLolly?id=:splat” status = 302 force = “false”

Slide 120

Slide 120

netlify Are you being servered? @philhawksworth EVENTS, TRIGGERS AND AUTOMATION

Slide 121

Slide 121

netlify Are you being servered? @philhawksworth FUNCTIONS AS A SERVICE

Slide 122

Slide 122

netlify Are you being servered? @philhawksworth DATABASE AS A SERVICE

Slide 123

Slide 123

netlify Are you being servered? @philhawksworth PRE-RENDERING SERVERLESS ON-DEMAND

Slide 124

Slide 124

netlify Are you being servered? @philhawksworth A SHIFT

Slide 125

Slide 125

netlify Are you being servered? @philhawksworth m o r f SEEKING TO OPTIMIZE BY ADDING STATIC LAYERS

Slide 126

Slide 126

netlify Are you being servered? @philhawksworth to STATIC FIRST ENHANCING IF REQUIRED

Slide 127

Slide 127

netlify Are you being servered? l a n o i it d a r t k c a t s m ja @philhawksworth CDN LOAD BALANCER WEB SERVERS DB SERVERS

Slide 128

Slide 128

netlify Are you being servered? @philhawksworth SIMPLIFYING IS NOT DUMBING DOWN

Slide 129

Slide 129

netlify Are you being servered? @philhawksworth SIMPLIFYING IS NOT DUMBING DOWN IT LETS US FOCUS ON WHAT REALLY IS IMPORTANT

Slide 130

Slide 130

netlify Are you being servered? @philhawksworth EASIER TO REASON ABOUT

Slide 131

Slide 131

netlify Are you being servered? @philhawksworth WHAT SHALL WE MAKE?

Slide 132

Slide 132

netlify Are you being servered? @philhawksworth

Slide 133

Slide 133

netlify Are you being servered? @philhawksworth STATIC SITE GENERATORS staticgen.com NETLIFY STATIC VARIOUS RELATED RESOURCES FROM CHRIS COYIER www.netlify.com https://serverless.css-tricks.com/ CITRIX PRESENTATION FROM JAMSTACKCONF NYC youtube.com/watch?v=kvS5h5domf0

Slide 134

Slide 134

netlify Are you being servered? @philhawksworth JAMSTACK CONFERENCE jamstackconf.com HEADLESS / DECOUPLED CMS STATIC ABOUT THE JAMSTACK / COMMUNITY headlesscms.org jamstack.org BUILDING A URL SHORTENER WITH NETLIFY REDIRECTS findthat.at

Slide 135

Slide 135

netlify Are you being servered? @philhawksworth SO I GUESS WE’RE FULL STACK NOW? full-stack.netlify.com MODERN WEB DEVELOPMENT ON THE JAMSTACK netlify.com/oreilly-jamstack/ JAMSTACK SLACK jamstack.org/slack JAMSTACK COMMENTS EXAMPLE jamstack-comments.netlify.com STATIC

Slide 136

Slide 136

FINDTHAT.AT / SERVERED THANKS @PHILHAWKSWORTH