Workers as single server and remote DB

Just kinda looking at workers and thinking of getting started… can someone shed some light on a few initial questions?

Single Server

Let’s say I want to structure things more like a traditional server with routing as opposed to one-project-per-endpoint… what exactly are the limits I need to be concerned about in this scenario? Specifically, is memory usage a problem?

Remote DB

Kinda building on the above, let’s say I want to use a relational db like google cloud sql… is there a way I can take advantage of connection pooling somehow? Are there articles on how to best set this up?

Here’s the popular node API that I’d like to use: https://github.com/mysqljs/mysql#pooling-connections

If this is not possible or beneficial, what is the recommended approach?

Benefit vs. Server

Assuming the above - does the latency of going from the workers at the edge to the db and back ruin the benefit I get by distributing the workers in the first place?

In other words, there are two scenarios to compare:

  1. Client <-> cloudflare (edge/server) <-> google (db)
  2. Client <-> google (server) <-> google (db)

On the one hand I’d imagine route 1 is faster since it’s hitting the edge and cloudflare has better connectivity to google than the client, but maybe not faster in the end since the db/server traffic is all in geographic proximity with route 2?

This would be the optimal way: https://github.com/cloudflare/db-connect
(You currently need Argon Tunnel, but soon you won’t need it)

Keep in mind that compared to the built in distributed KV, you will have to scale your DB and since it’s contained in a single datacenter, you’ll have a single-point of failure.

Doesn’t seem like Argo Tunnel works with Google SQL, since it requires running some serverside daemon?

That is probably the case while they require Argon Tunnel, yes.

OK cool, thanks. I opened up an issue to track it here: https://github.com/cloudflare/db-connect/issues/9

1 Like

Btw in case anyone else lands here, my questions about limits are spelled out very clearly in the docs (which I missed before): https://developers.cloudflare.com/workers/about/limits/

Specifically the 128MB memory limit, execution time vs. real runtime, and tips for streaming and global variables.