Workers vs Page functions

I am developing my first project with CF and I am unsure whether to use workers or page functions.

I need 3 workers:

  • worker 1: will be called by an external service, process that data and write it into a KV store with a key. It will then mail the key like this [worker2 url]/?param=key
  • worker 2 is called with the above genreated url, and will use the key to retrieve the data from the KV store. Worker 2 then presents a HTML page to the client where the client can modify a PDF
  • worker 3 is generating the PDF

Worker 2 and 3 will be very similar to the two workers in this great example: https://workers.cloudflare.com/built-with/projects/lazy-invoice/

In that example, which is a bit older, only workers are used, but not pages. However, worker 2 (the invoice worker in the example) mainly just returns a lot of HTML, so i was wondering if it may not be more suitable today to replace that worker with a page.

Lets assume its example.pages.dev

This page could maybe have some very simple landing page at example.pages.dev, but the main idea use of the page are doing GET requests to example.pages.dev/?param= in which case the user making the request is authentified and the retrieved data is shown on the page.

My question is, does it still make sense to do this with workers as in the invoice example above, or does it make more sense to replace these 3 workers with 3 page functions?

  • by “It will then mail the key like this [worker2 url]/?param=key” I mean that worker 1 will send an email to my client saying “a new task is waiting for you at worker2.workers.dev/?param=a62ef2” or something like that and my client can then click on that link and perform the task

I tried using both for my recent project and after researching, it turns out that they are pretty much the same (from CF’s perspective). The main difference comes to you as a developer. Pages being a more recent addition simplifies things for many cases, like you can develop/deploy the function along with the rest of the code. I also found the request handling etc to be simpler using Pages (so far my use case has been simple, to call the Pages function from a static webpage).

Here’s my understanding so far, if you want to call a worker only from a single application/website, it’s better to go with Page functions, otherwise Workers might be a better choice