sst / open-next

Open-source Next.js adapter for AWS
https://open-next.js.org
MIT License
3.87k stars 119 forks source link

Consider aws-lambda-web-adapter? #180

Closed bestickley closed 1 year ago

bestickley commented 1 year ago

I'd like to ask the contributors of this project to consider aws-lambda-web-adapter. I think this project could enable open-next to depend up on Next.js at the HTTP interface level (more stable), instead of the build output interface level (less stable). I wonder if utilizing this project would have prevented the middleware issue and if it could prevent future potential breaking changes. Appreciate your thoughts!

cc: @revmischa, @khuezy, @conico974, @fwang

conico974 commented 1 year ago

I've already looked into this, and the main blocking point here is cold starts. Right now next using standalone server or next start is really slow to start. This is due to the way they handled the react resolution issues (App and page dir uses different version of react).

Next in standalone is spawning 3-4 worker threads (Router server, App server, Page server, and incremental cache server) along with some http proxy that each need to be initialized from scratch. Expect at least 6-8 seconds cold starts for a small project.

Also aws-lambda-web-adapter seems to use docker instead of just nodejs which will likely add overhead to the lambda cold starts.

You're right though that this would be more stable and would have prevented the middleware issue, but unless someone manage to reduce the cold start, i don't see a way to use this.

bestickley commented 1 year ago

@conico974, I'm glad to hear you've already considered this. Re: cold starts, I agree 6-8 seconds is a blocker. However, if used with a warmer function, the cold start could be mitigated as the initialization code would run (for free) in the INIT phase, right? Still probably a blocker since eventually you'd hit cold starts.

It supports docker and zip packages (just nodejs) so that's not an issue.

khuezy commented 1 year ago

Yea what Conico said - we discussed this several months back when they announced it. Even w/ the warmer function, it won't catch 100% of requests and 5+ second cold start even for that small % (at large traffic this equates to big numbers) isn't acceptable.