Nest: Lazy loading strategy

Created on 15 Jul 2019  路  5Comments  路  Source: nestjs/nest

hi

support for lazy loading

needs triage type

Most helpful comment

@kamilmysliwiec I totally agree with you in context of monolith backend app. I though about serverless context and it seems to make sense there. Let me try to explain my idea with an example.

Let's say we are using Firebase Cloud Functions and it's HTTPS trigger (aka REST API).
Some modules of the REST API could have heavy dependencies, like libraries for image manipulations. But others don't.
Endpoints:
/api/users - simple CRUD for users, lightweight.
/api/images - CRUD for images with resize image feature, heavy.

Business specific: /users endpoint is used frequently, /images is used rarely.
In context of Firebase Functions it makes sense to make these two modules lazy loaded to make sure each small instance of a function is loaded fast (without need to load heavy dependencies). If lazy loading would exist in this context - that would save CPU time and "cold start" duration for serverless functions.

What do you think about this case? Would it be useful to have lazy loading here? If not - what could be helpful instead?

I really like Nest and respect all the efforts you put inside 馃槏
Thank you!

All 5 comments

Hey!
Lazy loading doesn't make any sense in the backend development

@kamilmysliwiec I totally agree with you in context of monolith backend app. I though about serverless context and it seems to make sense there. Let me try to explain my idea with an example.

Let's say we are using Firebase Cloud Functions and it's HTTPS trigger (aka REST API).
Some modules of the REST API could have heavy dependencies, like libraries for image manipulations. But others don't.
Endpoints:
/api/users - simple CRUD for users, lightweight.
/api/images - CRUD for images with resize image feature, heavy.

Business specific: /users endpoint is used frequently, /images is used rarely.
In context of Firebase Functions it makes sense to make these two modules lazy loaded to make sure each small instance of a function is loaded fast (without need to load heavy dependencies). If lazy loading would exist in this context - that would save CPU time and "cold start" duration for serverless functions.

What do you think about this case? Would it be useful to have lazy loading here? If not - what could be helpful instead?

I really like Nest and respect all the efforts you put inside 馃槏
Thank you!

@spy4x that's exactly what i want, when nestjs application startup its load all modules at first time, however the clients maybe not use all modules

Definitely a valid feature request in the context of serverless! We are currently discussing using NestJS with Firebase Functions and fear a little running into cold start / bootstrap issues.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yanshuf0 picture yanshuf0  路  3Comments

mishelashala picture mishelashala  路  3Comments

marshall007 picture marshall007  路  3Comments

artaommahe picture artaommahe  路  3Comments

2233322 picture 2233322  路  3Comments