Cloudflare recently released Workers, their marketing page says “Run code at the edge, deliver powerful web extensibility”
When I first heard about it I was confused as to why you would need computing at the edge? Surely that happens at the origin server! But then it finally clicked when I realised that Cloudflare could become the origin!
This might sound like a weird concept but let me explain.
Take a web site / web app. What does it do? In essence how does it talk to the browser? Using a request response cycle speaking in text based HTTP protocol (Binary in HTTP/2). The browser asks for www.example.com/about and the server responds with a status code some header info and the body of the response, a HTML page, or some other resource.
Traditionally it’s the job of the origin server to take that request, parse it, and route that to some code to generate the response. A lot of the time the origin will be responsible for combining data with an HTML template, and then passing that response back to the browser, quite simple really.
Serverless (e.g AWS lambda) came along and said right, we’ll take the routing and manage that at gateway / proxy, and then depending on the route we’ll execute a particular function. Exactly the same kind of process as before apart from now the route and each piece of code (controllers in MVC) are separate.
Lets say you have a CMS that provides a JSON API. Usually a request comes in, the CMS parses it and generates the page, then sends that back. But now you can take the templates and store them as part of a Cloudflare worker. Cloudflare parses the request at the edge and sends that to the relevant worker (also at the edge). The worker reads the request, pings the API of the CMS to get the data, and combines the data and templates generating a response. It then caches that within Cloudflare and returns the response to the browser. If images / resources are stored within AWS S3, and that’s on a subdomain going through Cloudfare’s cache, then where is the origin?
Some would say, well the CMS is your origin. Technically true, but what if you had several CMSs or services handling separate parts of a site? You could easily have workers setup for /account* or others to handle /events* hitting completely separate places to retrieve their data.
So you could say with workers being the glue that brings all these systems together Cloudflare has become the origin. But with 151 data centres around the world (probably more now) and workers automatically ready at every one, question is, where’s the origin now?