We are using layer0 for relatively big next.js
project. Our codebase has grown significantly, same as number of pages in the app. We are seeing increasing number of out-of-memory 540 crashes on prod, which we cannot fix or control. I’ve been digging the reasons for that behaviour, here’s what I’ve found:
- Layer0 uses
serverless
build for next.js(and all other frameworks layer0 supports are built on the same approach). This type of build creates set of pages, which are independent of each other, having all the modules for the app per each page bundle - In ideal serverless world, there should be spawned a worker per page type, to serve only one page type. In the same time, express server should not .listen on some port, instead utilising AWS handler object.
- Layer0 seems to have implemented a “hybrid” approach, where serverless build is used, but in the same time there’s a express server which is listening on a port and dynamically requiring the serverless page module.
- Such hybrid approach consumes enormous amount of RAM, because next serverless is not built for such usage. Each page module has duplicated dependencies and creates a lot of runtime memory cache which cannot be cleared.
Are there any options to get rid of intermediate express server and use “pure” serverless lambdas to serve the requests?
Thanks.