Improving Visitor Experience with Edge Computing @AndyDavies, July 2020 https://www.flickr.com/photos/yoyo_hick/2423655297
Slide 2
Where is the Edge?
Device?
Network?
Cloud?
Slide 3
Edge computing isn’t really a new concept
Slide 4
Safely deploying customer code has been a challenge https://www.flickr.com/photos/edenpictures/36796298946
Slide 5
Configuration languages have got us a long way https://www.flickr.com/photos/chrisrandall/6136814248
Slide 6
But what could we do with greater power and flexibility? https://www.flickr.com/photos/qubodup/14750352671
Slide 7
Advantages of processing at the edge •
Faster responses as endpoint is closer to the visitor
•
Reduced load at the origin
•
Orchestrate data from 3rd-parties
Slide 8
Improvements in several areas made it feasible •
ServiceWorker API provided a model for programmable proxies
•
Overhead of isolation between processes reduced
•
Serverless programming became common
Slide 9
Service Workers are in-browser network proxy…
…can intercept and rewrite both requests and responses
Slide 10
Edge Workers are a similar concept…
…it’s just the proxy is in a different place
Slide 11
New isolation techniques reduced resource overhead •
Micro Virtual Machines (VMs)
•
V8 Isolates
•
Web Assembly (WASM)
Slide 12
Resource requirements vary by approach
Virtual Machines
V8 Isolates
Reducing overhead
Web Assembly
Slide 13
Some approaches are faster than others Virtual Machine
V8 Isolates
Web Assembly
High
Low
Low
< 125ms (just for VM)
< 5ms
< 40μs
Runtime Overhead
High
Low
Low
Language(s)
BYO
JavaScript / WASM
C, Rust, Go, AssemblyScript
Resource Consumption
Startup Time
Slide 14
Using JavaScript makes it very familiar // Hello World Example export function onClientRequest(request) { request.respondWith( 200, {}, ‘<html><body><h1>Hello World From Akamai EdgeWorkers</h1></body></html>’); } export function onClientResponse(request, response) { response.setHeader(‘X-Hello-World’, ‘From Akamai EdgeWorkers’); }
Slide 15
Using JavaScript makes it very familiar // Hello World Example addEventListener(‘fetch’, event => { event.respondWith(handleRequest(event.request)) }) /** * Fetch and log a request * @param {Request} request */ async function handleRequest(request) { return new Response(‘Hello worker!’, { status: 200 }) }
Slide 16
YMMV with other languages (Rust for example) #[macro_use] extern crate http_guest; use http_guest::{Request, Response}; pub fn user_entrypoint(_req: &Request<Vec<u8>>) -> Response<Vec<u8>> { Response::builder() .status(200) .body(“Hello, world!”.as_bytes().to_owned()) .unwrap() } guest_app!(user_entrypoint);
Either executed as binary on VM, or compiled to WASM
Slide 17
Text representation of WASM looks something like this
(module (type $t0 (func (param i32) (result i32))) (func $add_one (export “add_one”) (type $t0) (param $p0 i32) (result i32) get_local $p0 i32.const 1 i32.add) (table $T0 1 1 anyfunc) (memory $memory (export “memory”) 17))
Note: this is an example NOT the code from the previous slide
Slide 18
WASI allows WASM to access system functions
Slide 19
Managed and deployed as code
Slide 20
What might we do with these new capabilities?
Slide 21
Many examples… https://github.com/akamai/edgeworkers-examples
Slide 22
What activities can be moved from… …the origin to the edge? …the client to the edge?
Slide 23
Examples •
More responsive user interactions
•
Preserving privacy
•
Proxying 3rd Parties
•
Experiment with Performance Optimisations
Slide 24
Responsive User Interactions
Slide 25
Fast autocomplete
Slide 26
Slide 27
Clientside frameworks rely on fast APIs
Slide 28
3rd Parties as Content
Slide 29
Reviews are essential to the buying experience
Slide 30
Slide 31
How could an edge worker mitigate this issue?
Slide 32
Move client-side experimentation to the edge Most AB / MV Testing services rely on large JavaScript bundles •
Delays while downloading
•
Delays while executing
•
Often use ‘anti-flicker’ scripts to hide the page while it reflows
Moving the experimentation off the client reduces these issues But…
Slide 33
Move client-side experimentation to the edge AB / MV Testing services are not just a large JavaScript bundle! They also provide •
Cohort mangement
•
Experiment creation
•
Analytics
What do we need to solve these challenges with edge workers?
Slide 34
Optimizely supports moving snippet processing at edge
https://man.gl/optimizely-experimenting-at-the-edge
Slide 35
Many other client-side 3rd-parties slow the experience •
Personalisation
•
Faceted search
•
Chat
•
Feedback
Could implementing these at the edge improve that?
Slide 36
Preserving Privacy
Slide 37
How many tags are collecting visitor data? https://man.gl/chiefmartec-supergraphic-2019
Slide 38
And what are they doing with it?
https://requestmap.herokuapp.com
Slide 39
Preserve privacy by proxying analytics
Slide 40
Cookie consent at the edge?
https://www.flickr.com/photos/61287964@N00/5714826863
Slide 41
How do we get 3rd-Party Tags to offer their features via the edge?
Slide 42
Experiment with Performance Optimisations
DevTools give us the ability to experiment with code locally
Slide 43
Create a proxy to rewrite the page https://github.com/pmeenan/cf-workers
Slide 44
Use proxy via overrideHost in WebPageTest script
https://www.slideshare.net/patrickmeenan/getting-the-most-out-of-webpagetest
Slide 45
Where’s the appropriate place to carry out the work? Some workloads may be unsuitable for network edge •
Machine Learning on device may be better for privacy reasons
•
Overhead of uploading client generated data may be prohibitive
•
What needs to remain on the origin?
Slide 46
Challenges Technical •
Debugging, profiling code in environments we don’t control
Mindset •
It’s new, many services are still in beta, need to think about how we architect our services
Slide 47
Closing Thoughts Edge computing gives us new capabilities to improve our site’s reliability, and our visitors experience and privacy
Vendors are adopting slightly different approaches
We haven’t worked out how to make the most of them yet