Are Workers suited for handling HTTP webhooks and making http requests that may be slower?

Hello!

For context: I’m new to Workers but have used AWS Lambda / Azure Functions in the past for the use case I’m describing.

I need to expose a number of endpoints, e.g. /order-created-event or /customer-created-event so that an external system can send webhooks to us (via POST). When we receive these webhook events / data, we need to do some processing and more than likely make HTTP requests to third party vendors (e.g. payment gateway).

I have read https://developers.cloudflare.com/workers/platform/limits which seems to indicate that longer running tasks (as an example I’d expect MOST http requests to complete within a second or two, but it wouldn’t be impossible for a request to take as long as 10 seconds), but while reading through various posts here I’ve sort of gotten the impression that the intended use of Workers is for very short lived tasks (e.g. <100ms).

I am wondering if I’m going down the wrong path here thinking about using Workers? I am NOT a “serverless” architecture expert by any means, but at a high level in my mind I’ve been treating Workers as a reasonable analogue for Lambda / Functions.

FWIW, although I’m testing with free accounts and evaluating by myself, customers would likely have Enterprise accounts / SLAs / etc.

Thanks for any guidance / recommendations!

That is correct. Actually, it is <10ms on the free plan and <50ms on the paid one. However there are two things to mention, these limits are currently not hard limits and occasional requests can exceed these timings, but Workers will be aborted if you regularly exceed the limit. Also, Cloudflare does plan to introduce it as hard limit in the future.

The second thing would be that IO wait times do not count towards the allotted time. So if your Worker is waiting for two seconds for an HTTP response, these two seconds won’t be counted but only the actual CPU time.

What you might be more interested in could be Introducing Workers Unbound though this is still in a closed beta and you’d need to sign up for it.

While Workers themselves are not plan dependent, you’ll still get a lot more flexibility with an Enterprise plan. In that case you might want to contact sales and enquire about the available options. I am sure they’ll be able to come up with something in that context.

I am not sure I’d say Cloudflare is fully there yet, but they at least want to go in that direction.

Thanks a ton for taking the time to response - super helpful.

My high level takeaway from your response is “your use case is probably ok” - does that seem fair?

In my situation, there is very little actual processing to happen by the CPU - get some JSON in the POST body, do some simple transformation / error checking, etc. The vast majority of the time required would be waiting for HTTP responses.

I was / am slightly confused still to some extent about how the documentation talks about calling external logging services. Their docs talk about using Sentry for logging, which means HTTP requests as far as I know. Again based on what yuo’re saying though, this might make sense if the only thing that “counts” is the CPU time.

One follow up: is there some way of measuring / making sure whatever network / http requests we’re making are being done “properly” in a way to make sure we are not hitting these CPU time limits?

Also, I will ask about seeing if we can get access to this “Workers Unbound” service. Thank you!

With “probably” yes, I would say so.

In that case you should be pretty much on the safe side. The current issues really are mostly related to CPU time. For example, encryption.

Logging via HTTP requests should not be an issue either, as these will be regular HTTP requests. Anything else would be a problem as regular TCP connections are not yet supported.

Though, there is a limit as to how many HTTP requests you can place during a Worker invocation. Please refer to the search for the exact number.

https://developers.cloudflare.com/workers/learning/debugging-workers has some details on debugging and related topics. Bottom line, try to avoid CPU intensive tasks. As long as you shift a few variables around and are mostly IO centric, there shouldn’t be an issue. If you start doing a lot of computations (e.g. cryptography, compression) you might hit limits.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.