Next.js Discord

Discord Forum

Dual deployment

Unanswered
Yacare Caiman posted this in #help-forum
Open in Discord
Avatar
Yacare CaimanOP
Part of my app needs to be deployed to Vercel, and the other part to an AWS EC2 instance. Any idea how I can do that? Both parts are back-end api services.

16 Replies

Avatar
Golden-winged Warbler
There are a large number of ways. This is basically CI/CD or devops. Are you familiar with either of those?
Avatar
Yacare CaimanOP
Since using Vercel, thankfully haven't had to deal with that much. I know of Github actions. On a related note, I copied the .next folder to the EC2 instance and tried running it with npm run start but it fails because package.json must be stripped of values during build process, and it only has one line: {"type": "commonjs"}.
Avatar
Yacare CaimanOP
I should be able to manually copy the bundled and minified files and run them, no? How can I do that?
Either with manual or CI/CD, how would I segregate the code that should run on Vercel vs EC2? Or do I just have a full copy of the application in both places?
Avatar
Golden-winged Warbler
that's application dependent and what you have to figure out (the logical side). CI/CD & devops is about making whatever that process is, automated and reliable (the tools you have been exposed to)
It's hard to guide the logical side and separation and steps needed without understanding the application. It might be easiest to deploy the full thing on both.

When I deployed nextjs self-hosted, I needed to copy more files. I use Dagger to product images and kubernetes to run them, but the makeImage step might be helpful for seeing what files we need for building and running.

(https://github.com/hofstadter-io/hof/blob/docs/updates/next/ci/dagger.mts#L126)
Avatar
Yacare CaimanOP
To clarify the segregate question, let's say I have an api folder that is going to Vercel and an api-long-running folder that goes to EC2. How to segregate those two? I can look into the details, but not sure where to go to find them. Would that be in webpack settings, NextJs settings, a 3rd party tool like Dagger, something else?
Avatar
tafutada777
interesting disucussion. Vercel's new style of microservices is different from the traditional style of k8s.
analogy, where to deploy is hard-coded in codes in Vercel
Edge Runtime(Cloudflare Worker) or Serverless(AWS Lambda)
Avatar
Yacare CaimanOP
On a side note, my architecture was Edge and Lambda (because it can be long(er) running), until I realized Lambda didn't make sense because the Lambda was spending most of its time waiting for ChatGPT to respond; an increasingly common scenario I suspect. So I moved to Vercel and EC2.
Avatar
tafutada777
yeah. i've been playing around with Vercel AI SDK on Edge Runtime these day. i knew it.
in my case, i use both Vercel and GCP k8s. code bases are completely separated.
i use hobby plan, so make is small to reduce cost.
for GCP, i use Rust, Go and Python btw.
or I could use Cloudflare Worker directly
Avatar
Yacare CaimanOP
Maybe Vercel AI SDK is an option. I'm not using LLMs for streaming chat. I just kick off a long running call, do some processing with the result, update db, and likely will stream to client once completed.