sst / sst

Build full-stack apps on your own infrastructure.
https://sst.dev
MIT License
23.79k stars 1.83k forks source link

Cloudflare microservices and local `dev` run #5634

Open kleinpetr opened 2 months ago

kleinpetr commented 2 months ago

Hi, I have a few questions, mainly related to Cloudflare, since most of the documentation and videos seem focused on AWS.

1 - Microservices Approach We use a monorepo setup with several services (Cloudflare Workers) and applications, all built using either Nitro or Nuxt. Previously, we maintained a separate wrangler.toml configuration for each service, allowing us to run them individually. Only the Apps have bindings to other services, so to run an App locally, we needed to manually start all required services.

Our CI pipeline deploys all services and apps using Terraform. However, we’re running into some chicken-and-egg problems, so we’re currently exploring better infrastructure-as-code patterns.

My question: Is it a common practice to keep a separate sst.config.ts for each service and app, and then use a root config to orchestrate everything together?

2 - Local Development From what I’ve seen in the docs and AWS-focused videos, the SST multiplexer can emulate most resources locally, supporting features like hot reload.

In our case, however, when we run npx sst dev, it always deploys the current worker to Cloudflare. Why doesn't it use the Wrangler CLI under the hood to run the worker locally instead?

We currently manage around:

10x Workers

5x D1 databases

6x Queues

Multiple KVs

With a team of 5 developers, managing preview deployments and local development this way would quickly become overwhelming.

Any suggestions or best practices are greatly appreciated 🙏

thdxr commented 2 months ago

typically people only have one sst.config.ts for everything - it's rare to break it up and only makes sense if you have completely independent services

sst dev deploys the worker for real because local emulation comes with a bunch of other problems - it's not complete and has quirks

so unfortunately we do need to upload it every time

however i'm not fully seeing why your scale of app would be overwhelming? people manage apps 100x that size in this way

kleinpetr commented 2 months ago

Thanks for your reply.

Regarding one sst config, it make sense for deployment, but at the same time we run services independently, since we respect SRP principles, so I am just wondering if we should kept wrangler toml just for local dev or we will change the local dev workflow 🤔 and the same issue are test which runs against each service standalone

And regarding worker deployment, I can understand it is necessary to be able to connect all bindings such as queues whose are not currently supported by wrangler local dev.

But I am not sure if the promise 'hot reload' is relevant for the cloudflsre in that case 🤔