This document discusses programming at the edge using Fastly's edge cloud platform. It provides an overview of Fastly's fiddle tool which allows users to test edge configurations by writing VCL code without affecting production configurations. The document outlines several exercises that can be completed in the fiddle tool, including adding GeoIP headers, logging to third party services, redirects, routing and A/B testing, and edge caching techniques like shielding. It encourages exploration of more advanced solutions and provides resources for learning more about programming at the edge with Fastly.
6. NYC
presents
Geo-IP API at the Edge
Redirects
Decoding auth cookies at the edge
Relative date insertion
Overriding TTLs based on content-type
Streaming server-sent-events
RUM logging and aggregation
Routing for microservices
CORS OPTIONS preflights at the edge
Serve robots.txt from the edge
Serve stale on origin failure
Getting creative at the edge
Partial content 'Range' requests
Time-limited URL tokens
Image optimization
Modern web security headers
GZip compression at the edge
Client public IP API at the edge
Google Cloud storage / AWS S3 origin
CAPTCHA challenge
Logging to Google BigQuery
Blocking obsolete TLS
Replace origin errors with 'safe' responses
12. NYC
presents
● Everything you enter into fiddle is public
● Pushing new config usually <10s but occasionally
longer if there’s a huge compilation job in the batch.
● Prefer that you use Chrome today, but should work in
all modern browsers
● We suggest you do each fiddle in a different tab, so
you still have them all to refer to at the end.
● Some instrumentation is asynchronously collected,
please allow a few seconds for it all to arrive.
● Ask Fastly helpers if you get stuck
15. NYC
presents
➔ Create a fiddle
➔ Set a fiddle title
➔ Configure a backend
➔ Execute the fiddle
➔ Understand the result
➔ Understand caching in fiddles
➔ Understand about fiddle insights
fiddle/5f263e69
Basics
1
18. NYC
presents
➔ Create a fiddle
➔ Set a title
➔ Write VCL in RECV to add GeoIP data
➔ Learn about real time linting and autocompletion
➔ Run the fiddle
➔ Learn about header highlighting
fiddle/7a6cbc28
GeoIP headers
2
19. NYC
presents
fiddle/7a6cbc28
RECV:
set req.http.client-geo-continent = client.geo.continent_code;
set req.http.client-geo-country = client.geo.country_code;
set req.http.client-geo-city = client.geo.city;
set req.http.client-geo-lat = client.geo.latitude;
set req.http.client-geo-lng = client.geo.longitude;
set req.http.edge-geo-datacenter = server.datacenter;
GeoIP headers
2
22. NYC
presents
➔ Create a fiddle
➔ Set a title
➔ Write RECV code to detect relevant requests and trigger error
➔ Write ERROR code to log the data
➔ Update the request URL to give it some data to log
➔ Run the fiddle
➔ Learn about real time log streaming and fiddle log capture
➔ For more info on RUM beacons see
fastly.com/blog/beacon-termination-edge
fiddle/b62fa9ee
RUM Logging
3
28. NYC
presents
➔ Create a fiddle
➔ Set a title
➔ Learn about edge dictionaries
➔ Write a dictionary in INIT
➔ Write RECV code to detect relevant requests and trigger error
➔ Write ERROR code to output a redirect response
➔ Update the request URL to one of the source paths
➔ Run the fiddle
➔ For a more complex solution try fiddle/36470bb6
fiddle/7fc13ab0
Redirects
4
35. NYC
presents
➔ Create a fiddle and set a title
➔ Configure three backends - A, B, and preflight API
➔ Write RECV code to choose backend
➔ Write DELIVER code to restart after preflight request
➔ Learn about specifying backends in fiddle
➔ Learn about randomness functions
➔ Understand how fiddle displays restarts
fiddle/2df6df84
Routing and AB testing
5
41. NYC
presents
fiddle/2df6df84
DELIVER:
if (resp.http.Test-Status && req.restarts == 0) {
set req.http.Test-Status = resp.http.Test-Status;
set req.url = req.http.Orig-URL;
unset req.http.Orig-URL;
restart;
}
set resp.http.Vary = regsub(resp.http.Vary, "(,s+)?Backend", "");
Routing and AB testing
5
42. NYC
presents
★ Add a Test-Status: ENABLED header to skip the preflight
★ See what happens when your preflight request hits cache
fiddle/2df6df84
Routing and AB testing
5
45. NYC
presents
➔ Create a fiddle and set a title
➔ Write RECV code to prevent caching at the edge
➔ Enable shielding and clustering
➔ Learn about shielding
➔ Run the fiddle twice
➔ Learn about targeting VCL at edge or shield POPs
fiddle/32f9f345
Shielding
6
47. NYC
presents
★ Try inverting the Fastly-FF test to move the pass to the Shield,
instead of the Edge
★ Try doing hash_always_miss instead of pass
fiddle/32f9f345
Shielding
6
49. NYC
presents
● Explore more solutions at fastly.com/demos
● Try fiddle yourself at fiddle.fastlydemo.net
● Got something good? Let us know in community.fastly.com or
email me: abetts@fastly.com.
● Remember all fiddle content is public
Programming the edge