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

A presentation at Nebraska JavaScript in August 2019 in Nebraska, USA 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? Nebraska JS, 2019 @philhawksworth

Slide 3

Slide 3

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 4

Slide 4

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 5

Slide 5

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 6

Slide 6

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 7

Slide 7

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 8

Slide 8

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth WIRELESS

Slide 9

Slide 9

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth SERVERLESS

Slide 10

Slide 10

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth FOCUSSING ON THE THINGS YOU CARE ABOUT

Slide 11

Slide 11

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

Slide 12

Slide 12

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

Slide 13

Slide 13

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

Slide 14

Slide 14

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth UNDERSTANDING CONSTRAINTS IS CRITICAL TO WRITING GOOD SOFTWARE JEREMY WAGNER

Slide 15

Slide 15

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth A FORRRRRRRM, SHOULD ALWAYS USE A FORRRRRRRRM TAG!!!!!!1!! JEREMY WAGNER

Slide 16

Slide 16

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth WHERE TO FOCUS OUR EFFORTS?

Slide 17

Slide 17

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

Slide 18

Slide 18

netlify Are you being servered? LINES AND BOXES Nebraska JS, 2019 @philhawksworth

Slide 19

Slide 19

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth @ PHIL HAWKSWORTH DEVELOPER EXPERIENCE, NETLIFY

Slide 20

Slide 20

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth FINDTHAT.AT/JAMSTACK-BOOK

Slide 21

Slide 21

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth FINDTHAT.AT/SOMETHINGSOMETHING FINDTHAT.AT/NEJS

Slide 22

Slide 22

ARE YOU BEING SERVERED? EXPLORING A SERVERLESS WEB PHIL HAWKSWORTH

Slide 23

Slide 23

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 24

Slide 24

Slide 25

Slide 25

Slide 26

Slide 26

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth ON BEHALF OF THE PEOPLE OF BRITAIN, I APOLOGIZE

Slide 27

Slide 27

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth ON BEHALF OF THE PEOPLE OF BRITAIN, I APOLOGISE

Slide 28

Slide 28

ARE YOU BEING SERVERED? EXPLORING A SERVERLESS WEB PHIL HAWKSWORTH

Slide 29

Slide 29

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth FUNCTIONS AS A SERVICE

Slide 30

Slide 30

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth SERVING WEBSITES WITHOUT WEBSERVERS

Slide 31

Slide 31

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 32

Slide 32

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

Slide 33

Slide 33

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

Slide 34

Slide 34

netlify Are you being servered? Nebraska JS, 2019 @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 35

Slide 35

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

Slide 36

Slide 36

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

Slide 37

Slide 37

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth TOOLS AND ECOSYSTEM

Slide 38

Slide 38

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

Slide 39

Slide 39

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth REACTJS.ORG REACTJS.ORG STATIC

Slide 40

Slide 40

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth YARNPKG.COM REACTJS.ORG STATIC

Slide 41

Slide 41

netlify Are you being servered? Nebraska JS, 2019 VUEJS.ORG REACTJS.ORG @philhawksworth

Slide 42

Slide 42

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth A LITTLE MORE “DYNAMIC”

Slide 43

Slide 43

netlify Are you being servered? Nebraska JS, 2019 SMASHINGMAGAZINE.COM SMASHINGMAGAZINE.COM @philhawksworth

Slide 44

Slide 44

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 45

Slide 45

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 46

Slide 46

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth PHILIP GOT COCKY

Slide 47

Slide 47

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth SOME PEOPLE ON THE INTERNET NOTICED

Slide 48

Slide 48

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth !

Slide 49

Slide 49

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 50

Slide 50

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 51

Slide 51

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 52

Slide 52

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

Slide 53

Slide 53

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

Slide 54

Slide 54

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

Slide 55

Slide 55

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

Slide 56

Slide 56

netlify Are you being servered? WEBSTASK.IO Nebraska JS, 2019 @philhawksworth

Slide 57

Slide 57

netlify Are you being servered? WEBSTASK.IO Nebraska JS, 2019 @philhawksworth

Slide 58

Slide 58

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth ( DON’T DO THIS )

Slide 59

Slide 59

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

Slide 60

Slide 60

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth PRE-RENDERING

Slide 61

Slide 61

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth PRE-RENDERING SERVERLESS ON-DEMAND

Slide 62

Slide 62

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

Slide 63

Slide 63

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

Slide 64

Slide 64

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth PUTTING DISTANCE BETWEEN THE COMPLEXITY AND THE USER

Slide 65

Slide 65

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

Slide 66

Slide 66

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

Slide 67

Slide 67

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth JAMSTACK ADVANTAGES SECURITY PERFORMANCE SCALE

Slide 68

Slide 68

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth SECURITY

Slide 69

Slide 69

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth A GREATLY REDUCED SURFACE AREA

Slide 70

Slide 70

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

Slide 71

Slide 71

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth FAR FEWER MOVING PARTS TO ATTACK

Slide 72

Slide 72

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth PERFORMANCE

Slide 73

Slide 73

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

Slide 74

Slide 74

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth CACHING GALORE

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 Nebraska JS, 2019 CDN @philhawksworth LOAD BALANCER WEB SERVERS DB SERVERS

Slide 76

Slide 76

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth SCALE

Slide 77

Slide 77

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

Slide 78

Slide 78

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

Slide 79

Slide 79

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth DECOUPLING

Slide 80

Slide 80

netlify Are you being servered? GET TO THE CHOPPER CDN Nebraska JS, 2019 @philhawksworth

Slide 81

Slide 81

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 82

Slide 82

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth PRE-RENDERING SERVERLESS ON-DEMAND

Slide 83

Slide 83

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth PRE-RENDERING SERVERLESS ON-DEMAND

Slide 84

Slide 84

netlify Are you being servered? Nebraska JS, 2019 @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 85

Slide 85

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

Slide 86

Slide 86

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth SERVERLESS TO THE RESCUE

Slide 87

Slide 87

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

Slide 88

Slide 88

netlify Are you being servered? Nebraska JS, 2019 @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 89

Slide 89

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

Slide 90

Slide 90

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth AUGMENTATION

Slide 91

Slide 91

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth ENHANCEMENT

Slide 92

Slide 92

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

Slide 93

Slide 93

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth AN EXAMPLE

Slide 94

Slide 94

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth AN EXAMPLE

Slide 95

Slide 95

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth AN EXAMPLE

Slide 96

Slide 96

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth AN EXAMPLE

Slide 97

Slide 97

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth VLOLLY.NET/LOLLY/lcc7u_n6a AN EXAMPLE

Slide 98

Slide 98

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

Slide 99

Slide 99

netlify Are you being servered? Nebraska JS, 2019 @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 100

Slide 100

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth s l o to

Slide 101

Slide 101

netlify Are you being servered? Nebraska JS, 2019 @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 102

Slide 102

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 103

Slide 103

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 104

Slide 104

netlify Are you being servered? Nebraska JS, 2019 @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 105

Slide 105

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 106

Slide 106

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 107

Slide 107

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 108

Slide 108

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 109

Slide 109

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 110

Slide 110

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth 404

Slide 111

Slide 111

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth TRIGGERS AND AUTOMATION

Slide 112

Slide 112

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth AN EXAMPLE

Slide 113

Slide 113

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 114

Slide 114

netlify Are you being servered? Nebraska JS, 2019 @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 115

Slide 115

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

Slide 116

Slide 116

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

Slide 117

Slide 117

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 118

Slide 118

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 119

Slide 119

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

Slide 120

Slide 120

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth s r e l b a en

Slide 121

Slide 121

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth CUSTOM 404 ROUTING

Slide 122

Slide 122

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

Slide 123

Slide 123

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

Slide 124

Slide 124

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth FUNCTIONS AS A SERVICE

Slide 125

Slide 125

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth DATABASE AS A SERVICE

Slide 126

Slide 126

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth PRE-RENDERING SERVERLESS ON-DEMAND

Slide 127

Slide 127

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth A SHIFT

Slide 128

Slide 128

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

Slide 129

Slide 129

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth to STATIC FIRST ENHANCING IF REQUIRED

Slide 130

Slide 130

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

Slide 131

Slide 131

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth SIMPLIFYING IS NOT DUMBING DOWN

Slide 132

Slide 132

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

Slide 133

Slide 133

netlify Are you being servered? Nebraska JS, 2019 EASIER TO REASON ABOUT @philhawksworth

Slide 134

Slide 134

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth WHAT SHALL WE MAKE?

Slide 135

Slide 135

netlify Are you being servered? Nebraska JS, 2019 @philhawksworth

Slide 136

Slide 136

netlify Are you being servered? Nebraska JS, 2019 @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 137

Slide 137

netlify Are you being servered? Nebraska JS, 2019 @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 138

Slide 138

netlify Are you being servered? Nebraska JS, 2019 @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 139

Slide 139

FINDTHAT.AT / NEJS THANKS @PHILHAWKSWORTH