1

So my front end page requires data from Promotions, Products, Manufactuers, and Retailers services -- each of course wrap a backend API

Should I...

A) Make 4 separate calls in front end (to each service) to get the data from the 4 locations?

Or

B) Make a single call to a backend method that aggregates all data from all 4 services. Of course I'd need to make a new AngularJS service for this as well

Advantage of (a) is that it avoids backend service coupling -- more modular on backend, as the services don't need to talk to each other.

Drawback is network overhead on front end -- four calls instead of one

What is the proper or more angular way to do this?

Ricky
  • 2,850
  • 5
  • 28
  • 41

1 Answers1

1

This isn't an angular question, this is a SOA question. And it's one of the oldest in the book. The answer is of course, it depends.

Service granularity is one of the hardest problems associated with moving to a service oriented architecture (which AngularJS kind of forces your into). It comes down to a balancing act between performance and service reusability.

As always, when considering a performance optimization, always test before you make assumptions about performance. A bit of testing can go a long ways here. You very well may discover you have no issue at all (happens more often than not).

Some things to consider:

  1. AngularJS and modern browsers handle multi-threaded programming quite well. They can have quite a few requests open to the server simultaneously (vary's by browser).
  2. Combining these requests increases the odds that they will not be cacheable (you ARE using cache-headers, right?)
  3. If it turns out you need to combine the services, putting a facade in front of the multiple services means you can still scale them at the back end (and even cache responses at the facade).
Rob Conklin
  • 8,806
  • 1
  • 19
  • 23
  • Thanks for your comments @RobConklin. You're right, I suppose this is more of an SOA question. Basically, I didn't see the point in building a specific back-end service that combines my four services for the sole purpose of this page making a single network request. Performance-wise both will do just fine. I just didn't know if making four calls (versus one) was considered back practice. – Ricky Oct 05 '15 at 17:10
  • Additionally, do you have any resources that address this sort of issue more in-depth? I suppose it wouldn't hurt for me to re-familiarize myself on this a little more. – Ricky Oct 05 '15 at 17:10
  • A couple of links: http://stackoverflow.com/questions/5514046/soa-how-granular-should-services-be-to-maintain-performance http://www.soablueprint.com/whitepapers/SOAPGPart3.htm#_Toc146083917 https://books.google.com/books?id=ed5ml0T3zyIC&pg=PA32&lpg=PA32&dq=how+granular+should+web+services+be&source=bl&ots=57fq1nLNou&sig=A3HnUopsgMLBmJt-Kdg3tXPgbk4&hl=en&sa=X&sqi=2&ved=0CEAQ6AEwB2oVChMIobi5w6WsyAIVhqKACh1aew6h#v=onepage&q=how%20granular%20should%20web%20services%20be&f=false – Rob Conklin Oct 05 '15 at 21:38
  • Thanks @RobConklin. I suppose there is no objective one-size-fits-all answer, however these links definitely point me in the right direction – Ricky Oct 06 '15 at 14:14