Junior — Middle
What is the difference between lazy (Lazy) and eager (Eager) data loading strategies?
sobes.tech AI
Answer from AI
Strategies for loading related information determine exactly when related data is loaded:
-
Lazy Loading — related data is loaded only upon first access. This conserves resources if related data is not always needed.
-
Eager Loading — related data is loaded immediately along with the main object, usually when executing a database query.
Example: in ORM, if you have a User object with an Orders collection, lazy loading does not load Orders immediately, but only when calling user.getOrders(). Eager loading loads all orders together with the user.
The choice of strategy depends on the use case scenario and performance requirements.