DEV Community


Discussion on: Explain Lazy and Eager Loading Like I'm Five

everton profile image
Everton Agner • Edited

You just moved to a new house. You packed all of your belongings inside boxes. The truck just left all of them inside your new home, and you're about to start your new life in there.

Eager loading

You really want to have the house setup with everything in it's right place. Right after the moving truck leaves, you decide you will unpack everything and will put everything in their right place before anything else. It will take you, say, 6 hours in doing that, but after you finish, you know where everything is, and only then can start to live in the house.

Lazy loading

The boxes are everywhere, but you don't want to unpack everything all at once. You just decide that, every time you need something, you will look up on which box is it, remove only that thing from the box, and use it. After using that, you will place that into it's permanent place.

E.g.: You are hungry and wanna cook pasta with tomato sauce. You take the cooking pan from one box, the pasta and tomato sauce from another one and only the utensils that you will need from another one. You cook your pasta, do the dishes and store all of that into the places you will keep them from now. If you decide to have the same meal again later, you don't need to look for them in the boxes, you know they are in your cabinets and in the fridge.

You will notice that, over time, the amount of stuff inside boxes will reduce significantly and, one day, there will be nothing left. If there's still stuff in boxes that you never had to unpack after a while, you may realize you don't need that at all.

Also consider that, if you do not store food that needs to be refrigerated as soon as you move, this food can go bad! (like milk). This kind of food cannot wait, and cannot be looked up only when you need them, therefore cannot be lazy loaded.