jeudi 18 août 2022

Runtime performance vs. independent components

I usually face a situation where I need to use N components, each of which needs to query something. For example, read a value from the DB.

Now there are two ways to do this:

  1. Each component will query the data independently
  2. Parent/container will do a batch query for all components and feed the part of the data as input to each component

With 1, you have a nice independent reusable component but N queries to the DB which is not efficient.

With 2, you have a good performance (Just need to make 1 DB query) but in terms of design, your components have more dependencies now. You need to provide them with that piece of data they need from DB.

Is there a 3rd way or a trade-off to having an independent, but performant system?

Aucun commentaire:

Enregistrer un commentaire