Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I make more frequent, smaller calls; or less frequent larger calls?

I guess the question is kind of loaded, but I wanted some feedback. Currently I am constructing poco class objects from web services via dtos. I preload all scalar values, and lazy load all collections/arrays, which includes binaries of course.

Obviously, I did this to improve response time, as this library is what drives the web application. But, in order to keep the service reusable, I have normalized out each GET function to a single action (S). So for instance, grabbing user info from active directory is one (scalar values like displayName and department, for instance), and grabbing this person's direct reports is a separate, lazy loaded action. So what happens, is that when you're building an object, there are numerous calls to the service to build this object. Some pages only need the basic info, others will call more of the lazy load methods or even the entire object. I don't see a problem with this, but what I'm wondering (and others at work are already criticizing) is if this going to be a problem?

My questions is, am I doing this wrong? All input is appreciated though. Thanks

like image 504
Sinaesthetic Avatar asked Jul 09 '12 15:07

Sinaesthetic


2 Answers

The balance you need to strike is the overhead of making a HTTP call, versus the overhead of transferring a large request or response.

There isn't a silver-bullet. For example, if the call is being made from one server to another across a LAN then larger payloads aren't much of an issue. If the call is being made from a mobile device then trimming the payload will likely have much benefit.

The best balance to begin with is to look at the methods of your webservice as steps in a workflow. Think about "If I want to achieve X, what data will I need?"; try to scope your requests responses around those thoughts and then analyze the results. It's just a starting point, but it's better than beginning with "one method for every tiny detail" or "one method that allows everything".

like image 167
STW Avatar answered Oct 31 '22 01:10

STW


I don't see a problem with this, but what I'm wondering (and others at work are already criticizing) is if this going to be a problem?

The problem is that each call to the service provides overhead. You'll get better total throughput with fewer, larger calls.

There's always a trade off here, and a balance to reach. Larger calls run the risk of pulling more data than required, which is wasting resources as well.

like image 24
Reed Copsey Avatar answered Oct 31 '22 01:10

Reed Copsey