If you are not familiar with Cloudflare or what it does, it’s mainly DNS that allows you to setup more security on the domain level, DDoS protection, and increases your site performance through its CDN.

In a basic use case, you change your domain nameserver to Cloudflare’s and ask them to handle any requests coming to your domain, so they will receive each request and based on your configuration, they will decide how and where to route the request or if it needs to be blocked or rejected if red flags raised from suspicious attacks.

In a normal scenario, you will configure a subdomain with CNAME record to be pointed to your server IP.

What if you need to route to different servers based on a URL query string value for an example:
- mydomain.com/profile?my_team=BostonTeam -> traffic should go to NY Server IP
- mydomain.com/profile?my_team=TokyoTeam -> traffic should go to HongKong Server IP

Here where CloudFlare Worker comes, it a middleware layer feature provided by Cloudflare to intercept incoming traffic and add a programmatic function to change the workflow.

Let’s create a Worker and see this example in practice.

Achieve Cloud Elasticity with Iron

Speak to us to find how you can achieve cloud elasticity with a serverless messaging queue and background task solution with free handheld support.

1. Create a Worker

Sign in to your Cloudflare account and click on “Workers”, then click on “Create Worker”

IronWorker CaaS Worker: Cloudflare Worker Setup
IronWorker CaaS Worker: Cloudflare Worker Setup

Your work will be created automatically and assigned a random name within your account namespace, a subdomain with public access will be generated for testing the worker

IronWorker CaaS Worker: Cloudflare Worker Setup

Click on “Send” to test the current Worker function and, this feature comes with a very good testing console.

IronWorker CaaS Worker: Cloudflare Worker Setup

2. Write worker code

Now we will update the Worker script on the left side editor, will add logic to intercept the URL Query “my_team” and take out its value.

IronWorker CaaS Worker: Cloudflare Worker Setup

Now let’s click on “Save and Deploy”, then will test by clicking on “Send” our worker works, and more logic can be added to change your application workflow.

IronWorker CaaS Worker: Cloudflare Worker Setup

3. Limits

Worker memory: 128 MB
CPU runtime: 10 ms -50ms (plan-based) Script size: 1MB
Number of scripts: 30

More Details: https://developers.cloudflare.com/workers/platform/limits

Iron.io Serverless Tools

Speak to us to learn how IronWorker and IronMQ are essential products for your application to become cloud elastic.

4. Cloudflare workers Costs

Cloudflare Workers are free with limits, and to avoid the limits you can subscribe to a monthly Bundled plan for $5.

With the Workers Bundled plan, requests beyond the included quota will be charged at $0.50/million requests.

Cloudflare workers pricing:

https://developers.cloudflare.com/workers/platform/pricing

5. Notes

Cloudflare Worker provides a night way to intercept your application traffic before it hits your server or serverless function, but I’m not sure if the naming here is proper as it doesn’t imply a worker system features; maybe it describes how they implement the same concept with network flow considering incoming traffic messages to be queued, and the interception function is the worker.

You may use it in scenarios where your application has a ton of published URLs shared over other apps or social networks, and something happened that prevent serving a portion of these routes properly, writing a worker to intercept and decode URL then decide where to route will be a good solution.

6. Security

Cloudflare worker is compliant with ISO 27001, SOC 2 Type II, SOC 3, PCI DSS, GDPR, and HIPAA. https://www.cloudflare.com/privacy-and-compliance/certifications/

7. Pro & Cons

As a domain-specific worker solution, it can be very handy when working at the application routing level for running taka at the edge. It supports multiple runtimes and easy to use the web, inline editor.

Scheduling works using Cloudflare “Cron Trigger” feature, and it supports 12 runtime languages, including JavaScript, Python, C, Cobol, Kotlin, Perl, and PHP.

On the other side, it has a limited worker memory and a max of 50 seconds runtime. Comparing to IronWorker, both provide serverless task processing. IronWorker is CaaS, CloudFlare is FaaS limited to specific use-cases for domains intercepting.

Unlock the Cloud with Iron.io

Find out how IronWorker and IronMQ can help your application obtain the cloud with fanatical customer support, reliable performance, and competitive pricing.

Leave a Comment





This site uses Akismet to reduce spam. Learn how your comment data is processed.