Serverless computing is used almost everywhere these days and is offered on all major cloud platforms. The basic idea is to outsource the setup of network, hardware and containers to a specialized vendor - the cloud provider. Only the developed application code is executed in a provided runtime environment. Payment is usually made based on the number of calls and runtime complexity of the application.
Cloudflare has particularly established itself in the CDN area. With Cloudflare Workers, the company also offers a serverless platform, which executes code in the data center that is physically closest. This edge computing solution ensures very low latency, making it ideal for middleware of dynamic web applications.
Hello World
While with AWS Lambdas you first have to fight your way through IAM and the required access rights, Creating a Cloudflare Worker is really easy. With just a few clicks, a Hello World application can be created and distributed via the Cloudflare infrastructure. This is what the script looks like that intercepts a request and returns a static response:
export default {
async fetch(request, env, ctx) {
return new Response('Hello World!');
},
};
Alternatively, you can also use the CLI Wrangler:
wrangler generate js-worker worker-template
The result is a workers.dev URL that can be accessed immediately in the browser and shows “Hello World!”. After a short time, the requests also appear in the exportable metrics:
Integrations
In general, Cloudflare Workers can be used independently of other services. Like any other cloud provider, Cloudflare also provides some useful platform integrations. Worth mentioning are:
- Cron Trigger
- Email Trigger
- Queue Trigger
- Key Value Datenbank
- Object Storage
- Datenbank
- Workers AI
Verdict
Cloudflare Workers are an alternative to AWS Lambda or Lambda@Edge in some cases.
They are a useful addition if you already host a website with Cloudflare.
For example, static pages can be made more dynamic using small APIs.
Of course, the Cloudflare and AWS ecosystems are not really comparable.
Nevertheless, there are some interesting services at Cloudflare, too.
In addition, the management interface is tidy and setting up the worker was quick.
The two products are also not far apart in price.
For Cloufdlare customers, Cloudflare Workers are definitely an asset and a clear recommendation.