Benefit to multiple workers for different routes?

Say I have two routes that will be served by workers, /routeA and /routeB. I could have them both be served by the same worker which checks the path and performs the appropriate action or I could have two separate workers that each handle a separate endpoint.

Is there a throughput advantage (or any other advantage/disadvantage) to having two separate workers? E.g., if they’re both in the same worker, could a surge in requests to /routeA impact request latencies to /routeB and would this be resolved by splitting them up?

As far as I know having fewer Workers incurs less latency as you would have less cold starts. These are minuscule, so it’s not really noticeable, but it’s technically faster to have less. This changes if you can’t fit the worker or if one of the routes is a lot of code and the other it’s not, since the execution of a ton of JS takes some time.

2 Likes

@matteo Makes sense, but does this change if both endpoints are receiving approximately the same volume of traffic?

It’s not really about traffic (excluding the cold starts), it’s more about code size and computation time. If you can reduce them (relatively significantly for at least one, not a few lines) it’s better to have them split.