Eager loading vs lazy loading

juanpinheirx

Juan Rodrigo de Oliveira Pinheiro

Posted on December 18, 2023

Eager loading vs lazy loading

Basically, do you know when you need to study for a test? You don't have much time: eager loading. Whatever you see in your sight is pretty much enough for you to have. But if you need to study a specific thing: lazy loading. That's when you have time to study specific concepts. Therefore, specific results.

Let's have another example with other things like our solar system.

Image description

Inquiring one about our solar system will get us a general answer. Let's name this concept as macroquery. We have informations about other planets (enough to know what they're made of, for example).

Let's say we want now to get more information on mars. Let's call this inquiry microquery. Mars has its specific details such as earth.

When we want to get from a query nothing in particular: eager loading (macroquery). When we want specifics: lazy loading (microquery).

Think about atoms and how they were discovered pretty much after stars. In terms of mass, both are completely different however, they share the same matter.

Image description

Doesn't it look like a planet with its moons?

Let's talk a bit more about space and get the difference between being on a planet, watch it through a telescope and look up to the sky.

We have more informations now in Mars than before, due to exploration technologies. We can call this action towards knowledge from mankind as microquery. We want to know now details of mars.

Image you wake up in a remote period of ancient time, where all you can do to know about space is to look up. To see little stars with different colors or constellations will give you coordinates or some kind of information such as: the north star, if you're on a western or eastern part of earth, etc. We'll call it macroquery. We have little to work on, and much to do if we want specifics.

Now imagine you woke up with Copernicus looking to the stars through a telescope. You could see with your own eyes his studies to get to our general answer today: the sun does not rotate around earth.

Is this micro or macroquery? The answer for us is: it depends.

If you need specific data from your database: lazy loading. Remember microquery. Else, use eager loading and remember macroquery.

💖 💪 🙅 🚩
juanpinheirx
Juan Rodrigo de Oliveira Pinheiro

Posted on December 18, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

The Accessor Protocol
javascript The Accessor Protocol

August 6, 2024

The Renaissance of Meteor.js
javascript The Renaissance of Meteor.js

July 26, 2024

Eager loading vs lazy loading
javascript Eager loading vs lazy loading

December 18, 2023

Understanding require function (Node.js)
javascript Understanding require function (Node.js)

October 3, 2023