I have a Foo service that, among other things, retrieves data from a table called Widget. This table has about 50 columns. This service is called by a request from a browser.
Now, I have another service, Bar, that wants to call Foo. This is a Windows Service that we can trust because there is no end user. Bar also needs data from the Widget table. However, Bar only needs 3 columns of data. Bar needs this before calling Foo.
My concern is the inefficiency of Bar getting Widget, only for Foo to also do the same thing. I can think of three options:
- Bar makes the same repo call to get all the Widget data.
- Same as #1, but Bar passes Widget data to Foo.
- Bar makes a different repo call to only get the three columns it needs.
Number 1 is inefficient because Bar and Foo will get the same data.
Number 2 works, but Foo has to trust the caller. Foo can't trust the caller in one case, because it's from a web request. But Foo can trust the service call.
Number 3 also works, but it's slightly inefficient because it's getting Widget data, although it's a much slimmer version. And we would need DTO just for this Bar process, and the DTO would just have the three fields.
I'm leaning towards #3, but would love some input, especially if there is another approach that I'm not considering.