My Honest Attempt At Building The Same App on Cloudflare Workers, Fastly [email protected] and Akamai EdgeWorkers
Building serverless applications on the “edge” is becoming a reality. The promise of fast execution and seamless deployment is near, but is it here?
The goal: Use an edge platform to build a proof of concept clone of linkz.ai, a tooltip generator for external links (among other things).
I want to create a self-contained application, all serverless, without any external tools like a managed Postgres or lambda.
I want to write my code and deploy it to the edge. No-fuss. What are my options for deploying wicked-fast applications to the edge?
To build my linkz.ai clone, here’s how I would structure my application—starting with a list of URLs sent from the website and ending with the data needed to make my preview.
There are a few key points here that disqualify a lot of serverless providers:
- I need a built-in persistent data store
- I need to be able to fetch and parse an arbitrary URL
Right off the bat, a lack of a native storage layer disqualifies the following:
To get around the limitations, I could use an external database like Upstash, but that is beyond the scope of this article.
Building with Fastly [email protected]
Fastly offers four ways to build their Wasm bundles:
- AssemblyScript (a subset of typescript that compiles to Wasm)
- A custom/community SDK (for compiling something like Zig to Wasm)
Rust seems to get the most love from the Fastly team, with items like fast reload launching with support only for Rust (with the other platforms coming later).
However, after writing some code, I found that Fastly doesn’t allow for fetch requests to URLs not pre-defined in the application’s config.
While [email protected] feels like a great add-on to Fastly, it doesn’t quite fit the requirements for this full-stack application.
The developer experience for using Akamai’s edge workers is dramatically different than Fastly or Cloudflare.
To start, to even enable them on my account, I had to head to a Slack channel to ask for access.
Trying to set up the “Hello World” example they had, I had to jump through the hoops of enabling their “advanced TLS” and creating a certificate. This process is much more involved than with Cloudflare or Fastly.
The developer experience was lacking:
- To use their workers, I needed to compress and upload the folder as a .tar.gz file. Although they do have IDE extensions that can make this easier
- Their local development workflow relies on Jest or Mocha, rather than creating a test server
For someone just looking to use a workers platform, I would not recommend Akamai as a solution.
Note: My experience may not be typical. Maybe something went wrong during onboarding. However, the point remains that Akamai’s developer experience is currently not up to par with that of Fastly or Cloudflare, and I prefer not to develop an application on their platform.
Building on Cloudflare Workers
While the developer experience on Cloudflare Workers isn’t perfect, it does get the job done without much fuss.
Setting up workers, creating a KV store for dev and prod environments, and deploying all happen without any challenges.
Here’s a sample of the final product.
Youtube link (opens an embed window when clicked)
Here’s a link to the repo. I was able to build the back end with under 200 lines of code!
Fetching and parsing URLs
Cloudflare knows that a huge use-case for workers is working with HTML files. Their built-in HTML rewriter made it easy to read and pull out the information I needed from the links needing a tooltip.
Storing persistent data with Edge KV
Edge KV is a globally distributed and eventually consistent database built for “write-once” or “write-rarely” data. For our purposes, this is great.
They also have a handy feature for Cache TTL, alleviating my worry that I’ll store old data that never gets accessed.
The only real “workers” option for building a tool like linkz.ai is Cloudflare Workers.
Other tools, like Fastly’s [email protected], Akamai’s Edge Workers, and more, are positioned to be excellent in tandem with an existing application.
As a self-contained application, Cloudflare Workers is the only contender.