Slide 1

Slide 1 text

THE EDGE AT YOUR FINGERTIPS, LITERALLY! JSWorld Conference - Amsterdam, June 2022

Slide 2

Slide 2 text

WHAT WE'LL COVER? @lauragift_

Slide 3

Slide 3 text

WHAT WE'LL COVER? •What is the Edge? @lauragift_

Slide 4

Slide 4 text

WHAT WE'LL COVER? •What is the Edge? •How is it different from Serverless Functions? @lauragift_

Slide 5

Slide 5 text

WHAT WE'LL COVER? •What is the Edge? •How is it different from Serverless Functions? •Pros & Cons of Serverless & Edge functions. @lauragift_

Slide 6

Slide 6 text

WHAT WE'LL COVER? •What is the Edge? •How is it different from Serverless Functions? •Pros & Cons of Serverless & Edge functions. •The Cloudflare Developer Ecosystem. @lauragift_

Slide 7

Slide 7 text

WHAT WE'LL COVER? •What is the Edge? •How is it different from Serverless Functions? •Pros & Cons of Serverless & Edge functions. •The Cloudflare Developer Ecosystem. •Use Cases and Examples. @lauragift_

Slide 8

Slide 8 text

GIFT EGWUENU DEVELOPER ADVOCATE @CLOUDFLARE EDUCATOR & YOUTUBER @LAURAGIFT_

Slide 9

Slide 9 text

WHAT IS THE Edge? @lauragift_

Slide 10

Slide 10 text

The edge is a server geographica y located close to your users. @lauragift_

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Where it a started... @lauragift_

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

LIMITATIONS OF TRADITIONAL SERVERS @lauragift_

Slide 17

Slide 17 text

LIMITATIONS OF TRADITIONAL SERVERS •Expensive to maintain. @lauragift_

Slide 18

Slide 18 text

LIMITATIONS OF TRADITIONAL SERVERS •Expensive to maintain. •High latency due to large amount of traffic. @lauragift_

Slide 19

Slide 19 text

LIMITATIONS OF TRADITIONAL SERVERS •Expensive to maintain. •High latency due to large amount of traffic. •Limited opportunity for scaling. @lauragift_

Slide 20

Slide 20 text

SERVERLESS FUNCTIONS @lauragift_

Slide 21

Slide 21 text

Serverless doesn't mean no servers! There's still a server, you just don't manage it. @lauragift_

Slide 22

Slide 22 text

SERVERLESS PROVIDERS @lauragift_

Slide 23

Slide 23 text

ADVANTAGES OF SERVERLESS FUNCTIONS @lauragift_

Slide 24

Slide 24 text

ADVANTAGES OF SERVERLESS FUNCTIONS •Hosted by a provider, no need to manage your servers. @lauragift_

Slide 25

Slide 25 text

ADVANTAGES OF SERVERLESS FUNCTIONS •Hosted by a provider, no need to manage your servers. •Low costs of bandwidth (pay for only what you use). @lauragift_

Slide 26

Slide 26 text

ADVANTAGES OF SERVERLESS FUNCTIONS •Hosted by a provider, no need to manage your servers. •Low costs of bandwidth (pay for only what you use). •Scalibility On Demand. @lauragift_

Slide 27

Slide 27 text

LIMITATION OF SERVERLESS FUNCTIONS @lauragift_

Slide 28

Slide 28 text

LIMITATION OF SERVERLESS FUNCTIONS •All functions are stored in a centralized core location (us-east1). @lauragift_

Slide 29

Slide 29 text

LIMITATION OF SERVERLESS FUNCTIONS •All functions are stored in a centralized core location (us-east1). •Cold start after the function is idle. @lauragift_

Slide 30

Slide 30 text

LIMITATION OF SERVERLESS FUNCTIONS •All functions are stored in a centralized core location (us-east1). •Cold start after the function is idle. •Limited execution time(10ms). @lauragift_

Slide 31

Slide 31 text

EDGE FUNCTIONS @lauragift_

Slide 32

Slide 32 text

EDGE FUNCTIONS = Serverle Functions at The Edge @lauragift_

Slide 33

Slide 33 text

REGION EARTH

Slide 34

Slide 34 text

EDGE PROVIDERS Cloudflare Workers, AWS Lambda@Edge, Deno Deploy, Netlify Edge Functions

Slide 35

Slide 35 text

ADVANTAGES OF EDGE FUNCTIONS @lauragift_

Slide 36

Slide 36 text

ADVANTAGES OF EDGE FUNCTIONS •Reduced Latency @lauragift_

Slide 37

Slide 37 text

ADVANTAGES OF EDGE FUNCTIONS •Reduced Latency •Zero Cold Start (0ms) @lauragift_

Slide 38

Slide 38 text

ADVANTAGES OF EDGE FUNCTIONS •Reduced Latency •Zero Cold Start (0ms) •Improved Application Performace @lauragift_

Slide 39

Slide 39 text

LIMITATIONS OF EDGE FUNCTIONS

Slide 40

Slide 40 text

@lauragift_

Slide 41

Slide 41 text

•Limited compute resources (~10 ms). @lauragift_

Slide 42

Slide 42 text

@lauragift_

Slide 43

Slide 43 text

•No support for browser or Node.js specific features(V8 Engine). @lauragift_

Slide 44

Slide 44 text

The best packages and libraries supported by Cloudflare Workers.

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

@lauragift_

Slide 47

Slide 47 text

•High latency due to data storage limitations. @lauragift_

Slide 48

Slide 48 text

CLOUDFLARE DEVELOPER PLATFORM @lauragift_

Slide 49

Slide 49 text

CLOUDFLARE WORKERS @lauragift_

Slide 50

Slide 50 text

Cloudflare Workers is a serverless execution environment that allows you to create new applications or augment existing ones without configuring or maintaining infrastructure.

Slide 51

Slide 51 text

@lauragift_

Slide 52

Slide 52 text

▸ Goodbye to cold starts—support for 0ms worldwide. @lauragift_

Slide 53

Slide 53 text

How is a zero cold start possible?

Slide 54

Slide 54 text

How is a zero cold start possible?

Slide 55

Slide 55 text

@lauragift_

Slide 56

Slide 56 text

▸ Cost Savings - 100,000 request/daily free & affordable plans to scale. @lauragift_

Slide 57

Slide 57 text

@lauragift_

Slide 58

Slide 58 text

▸ Edge Storage with KV, Durable Object, R2 & D1. @lauragift_

Slide 59

Slide 59 text

CLOUDFLARE WORKERS HOW IT WORKS? @lauragift_

Slide 60

Slide 60 text

@lauragift_

Slide 61

Slide 61 text

▸ V8 Isolates Engine @lauragift_

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

VIRTUAL MACHINES V8 ISOLATES A virtual machine (VM) is a software-based computer that exists within another computer’s operating system. Isolates are lightweight contexts that group variables with the code allowed to mutate them. Consumes more memory. Consumes less memory. Start-up time 500ms- 10secs. Start-up time under 5ms.

Slide 64

Slide 64 text

HELLO WORKER EXAMPLE export default { fetch() { return new Response('Hello Worker!'); }, }; @lauragift_

Slide 65

Slide 65 text

PAGES FUNCTIONS @lauragift_

Slide 66

Slide 66 text

Pages enable you build full-stack applications by executing code on the Cloudflare network with help from Cloudflare Workers. @lauragift_

Slide 67

Slide 67 text

FUNCTIONS (BETA) export async function onRequest(context) { // Contents of context object const { request, // same as existing Worker API env, // same as existing Worker API params, // if filename includes [id] or [[path]] waitUntil, // same as ctx.waitUntil in existing Worker API next, // used for middleware or to fetch assets data, // arbitrary space for passing data between middlewares } = context; return new Response("Hello, world!"); } @lauragift_

Slide 68

Slide 68 text

DATA STORAGE ON THE EDGE @lauragift_

Slide 69

Slide 69 text

@lauragift_

Slide 70

Slide 70 text

WORKERS KV @lauragift_

Slide 71

Slide 71 text

Workers KV is a global, low-latency, key-value data store.

Slide 72

Slide 72 text

await NAMESPACE.put(key, value); @lauragift_

Slide 73

Slide 73 text

await NAMESPACE.get(key); @lauragift_

Slide 74

Slide 74 text

await NAMESPACE.delete(key); @lauragift_

Slide 75

Slide 75 text

await NAMESPACE.list(); @lauragift_

Slide 76

Slide 76 text

DURABLE OBJECTS @lauragift_

Slide 77

Slide 77 text

Durable Objects provide low-latency coordination and consistent storage for the Workers platform through two features - global uniquene and a transactional storage API. @lauragift_

Slide 78

Slide 78 text

export class DurableObject { constructor(state, env) {} async fetch(request) { return Response("Hello World") } } @lauragift_

Slide 79

Slide 79 text

R2 @lauragift_

Slide 80

Slide 80 text

R2 storage allows developers to store large amounts of unstructured data without the costly egre bandwidth f s associated with typical cloud storage services. @lauragift_

Slide 81

Slide 81 text

R2 BINDINGS # wrangler.toml [[r2_buckets]] binding = 'MY_BUCKET' # <~ valid JavaScript variable name bucket_name = '' @lauragift_

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

COMMON USE CASES @lauragift_

Slide 84

Slide 84 text

COMMON USE CASES •Geolocation Based Redirects @lauragift_

Slide 85

Slide 85 text

COMMON USE CASES •Geolocation Based Redirects •A/B Testing @lauragift_

Slide 86

Slide 86 text

COMMON USE CASES •Geolocation Based Redirects •A/B Testing •Custom HTTP Headers & Cookie Management @lauragift_

Slide 87

Slide 87 text

COMMON USE CASES •Geolocation Based Redirects •A/B Testing •Custom HTTP Headers & Cookie Management •User Authentication and Authourization @lauragift_

Slide 88

Slide 88 text

COMMON USE CASES •Geolocation Based Redirects •A/B Testing •Custom HTTP Headers & Cookie Management •User Authentication and Authourization •Localization and Personalization @lauragift_

Slide 89

Slide 89 text

WHEN not TO USE CLOUDFLARE WORKERS

Slide 90

Slide 90 text

@lauragift_

Slide 91

Slide 91 text

USE CASES WONT RECOMMEND Data Latency - Database is not hosted on the Edge! @lauragift_

Slide 92

Slide 92 text

USE CASES WONT RECOMMEND Requires large amount of compute resources to run. @lauragift_

Slide 93

Slide 93 text

Workers Examples @lauragift_

Slide 94

Slide 94 text

GEOLOCATION BASED REDIRECTS export default { async fetch(request: Request): Promise { const { cf } = request if ( cf?.country === "NL") { return Response.redirect("https://asos.com/nl") } }, }; @lauragift_

Slide 95

Slide 95 text

GEOLOCATION BASED REDIRECTS export default { async fetch(request: Request): Promise { const { cf } = request if ( cf?.country === "NL") { return Response.redirect("https://asos.com/nl") } }, }; @lauragift_

Slide 96

Slide 96 text

GEOLOCATION BASED REDIRECTS export default { async fetch(request: Request): Promise { const { cf } = request if ( cf?.country === "NL") { return Response.redirect("https://asos.com/nl") } }, }; @lauragift_

Slide 97

Slide 97 text

GEOLOCATION BASED REDIRECTS export default { async fetch(request: Request): Promise { const { cf } = request if ( cf?.country === "NL") { return Response.redirect("https://asos.com/nl") } }, }; @lauragift_

Slide 98

Slide 98 text

GEOLOCATION BASED REDIRECTS export default { async fetch(request: Request): Promise { const { cf } = request if ( cf?.country === "NL") { return Response.redirect("https://cloudflare.com") } }, };

Slide 99

Slide 99 text

RETRY/LOG FAILED REQUESTS export default { async fetch(request: Request): Promise { const res = await fetch("https://httpstat.us/503?sleep=2000") if (!res.ok) { return await fetch("https://httpstat.us/200") } else { return res } } } @lauragift_

Slide 100

Slide 100 text

RETRY/LOG FAILED REQUESTS export default { async fetch(request: Request): Promise { const res = await fetch("https://httpstat.us/503?sleep=2000") if (!res.ok) { return await fetch("https://httpstat.us/200") } else { return res } } } @lauragift_

Slide 101

Slide 101 text

RETRY/LOG FAILED REQUESTS export default { async fetch(request: Request): Promise { const res = await fetch("https://httpstat.us/503?sleep=2000") if (!res.ok) { return await fetch("https://httpstat.us/200") } else { return res } } } @lauragift_

Slide 102

Slide 102 text

RETRY/LOG FAILED REQUESTS export default { async fetch(request: Request): Promise { const res = await fetch("https://httpstat.us/503?sleep=2000") if (!res.ok) { return await fetch("https://httpstat.us/200") } else { return res } } }

Slide 103

Slide 103 text

A/B TESTING REMOTE ORIGINS export default { async fetch(request: Request): Promise { const origin1 = 'https://cloudflare.com'; const origin2 = 'https://jsworldconference.com'; const randomNumber = Math.floor(Math.random() * 100) + 1; if (randomNumber > 50) { return fetch(origin1); } else { return fetch(origin2); } }, }; @lauragift_

Slide 104

Slide 104 text

A/B TESTING REMOTE ORIGINS export default { async fetch(request: Request): Promise { const origin1 = 'https://cloudflare.com'; const origin2 = 'https://jsworldconference.com'; const randomNumber = Math.floor(Math.random() * 100) + 1; if (randomNumber > 50) { return fetch(origin1); } else { return fetch(origin2); } }, }; @lauragift_

Slide 105

Slide 105 text

A/B TESTING REMOTE ORIGINS export default { async fetch(request: Request): Promise { const origin1 = 'https://cloudflare.com'; const origin2 = 'https://jsworldconference.com'; const randomNumber = Math.floor(Math.random() * 100) + 1; if (randomNumber > 50) { return fetch(origin1); } else { return fetch(origin2); } }, }; @lauragift_

Slide 106

Slide 106 text

A/B TESTING REMOTE ORIGINS export default { async fetch(request: Request): Promise { const origin1 = 'https://cloudflare.com'; const origin2 = 'https://jsworldconference.com'; const randomNumber = Math.floor(Math.random() * 100) + 1; if (randomNumber > 50) { return fetch(origin1); } else { return fetch(origin2); } }, }; @lauragift_

Slide 107

Slide 107 text

A/B TESTING REMOTE ORIGINS export default { async fetch(request: Request): Promise { const origin1 = 'https://cloudflare.com'; const origin2 = 'https://jsworldconference.com'; const randomNumber = Math.floor(Math.random() * 100) + 1; if (randomNumber > 50) { return fetch(origin1); } else { return fetch(origin2); } }, }; @lauragift_

Slide 108

Slide 108 text

A/B TESTING REMOTE ORIGINS export default { async fetch(request: Request): Promise { const origin1 = 'https://cloudflare.com'; const origin2 = 'https://jsworldconference.com'; const randomNumber = Math.floor(Math.random() * 100) + 1; if (randomNumber > 50) { return fetch(origin1); } else { return fetch(origin2); } }, };

Slide 109

Slide 109 text

WHAT WE'VE LEARNED TODAY? @lauragift_

Slide 110

Slide 110 text

WHAT WE'VE LEARNED TODAY? •What is the Edge? @lauragift_

Slide 111

Slide 111 text

WHAT WE'VE LEARNED TODAY? •What is the Edge? •How is it different from Serverless Functions? @lauragift_

Slide 112

Slide 112 text

WHAT WE'VE LEARNED TODAY? •What is the Edge? •How is it different from Serverless Functions? •Pros & Cons of Serverless & Edge functions. @lauragift_

Slide 113

Slide 113 text

WHAT WE'VE LEARNED TODAY? •What is the Edge? •How is it different from Serverless Functions? •Pros & Cons of Serverless & Edge functions. •The Cloudflare Developer Ecosystem (Workers, KV, R2, DO, D1). @lauragift_

Slide 114

Slide 114 text

WHAT WE'VE LEARNED TODAY? •What is the Edge? •How is it different from Serverless Functions? •Pros & Cons of Serverless & Edge functions. •The Cloudflare Developer Ecosystem (Workers, KV, R2, DO, D1). •Use Cases & Examples of Edge Functions. @lauragift_

Slide 115

Slide 115 text

Building applications on the Edge helps bring us close to our end-users, improving their experience and making the web more acce ible to everyone. @lauragift_

Slide 116

Slide 116 text

FURTHER RESOURCES

Slide 117

Slide 117 text

FURTHER RESOURCES • Cloudflare Workers Documentation

Slide 118

Slide 118 text

FURTHER RESOURCES • Cloudflare Workers Documentation • Cloudflare Pages Documentation

Slide 119

Slide 119 text

FURTHER RESOURCES • Cloudflare Workers Documentation • Cloudflare Pages Documentation • Cloudflare Blog - blog.cloudflare.com

Slide 120

Slide 120 text

FURTHER RESOURCES • Cloudflare Workers Documentation • Cloudflare Pages Documentation • Cloudflare Blog - blog.cloudflare.com • Cloudflare Devs Discord

Slide 121

Slide 121 text

THANK YOU! @lauragift_