Welcome to MSDN Blogs Sign in | Join | Help

Welcome to The Metaverse

Navigating the service-oriented, identity aware metaverse

News

  • Disclaimer:
    The content of this blog are my own personal opinions and do not necessarily represent Microsoft's position, commitments or strategy. In addition, my thoughts and opinions often change, and as a weblog is intended to provide a semi-permanent point in time snapshot you should not consider out of date posts to reflect my current thoughts and opinions.




    Add to Technorati Favorites
How Granular Should My Services Be?

This is a) a very common question, and b) very hard to provide absolute prescriptive guidance on.

In short, this is where the “art” of architecture & design comes into play!

How granular you make your service largely depends on how you’ll use it. Always bear in mind, however, that you should avoid traversing the wire as much as possible. Therefore, if you design your service so that you have to call 10 actions in order to refresh a customer data page, then you’ll likely experience severe perf and scale issues. A better approach is to call one GetCustomerData(…) method once and build the customer data page from the returned data. 

“Ah, but my service has to be used by many callers – some require a great deal of customer data, but many only need the name of the customer”. In which case, your service should expose BOTH fine-grained and large-grained actions:

[ServiceContract]
class Customer
{
  //  Only returns customer name.
  [OperationContract]
  string GetCustomerName(Uuid customerID)
  { /* implementation */ }
  
  //  Only returns customer address.
  [OperationContract]
  CustomerAddress GetCustomerAddress(Uuid customerID)
  { /* implementation */ }
  
  //  Large-grained customer record retrieval.
  [OperationContract]
  CustomerRecord GetCustomer(Uuid customerID)
  { /* implementation */ }
  
  //  Large-grained customer record update – note that this is one-way!!
  [OperationContract(IsoneWay=true)]
  Void UpdateCustomer(Uuid customerID, CustomerRecord customerRec)
  { /* implementation */ }
}

Note that when using newer technologies such as WCF (formerly “Indigo”), anything that returns a void could be marked as OneWay. This means that the sender doesn’t have to hang around and wait for the service to complete processing the action. This can be a massive scalability booster! :)

Posted: Monday, April 10, 2006 2:00 PM by richardt

Comments

Kris said:

If a void is changed to OneWay and the data operation throws an exception - will the exception trickle up and even if it does will there be context information to handle it sufficiently (assuming the OneWay call was made on an async thread)?
# April 11, 2006 12:26 AM

Jeffrey Adkins said:

There is a fundamental direction that this whole SOA movement is going.  What is it that this whole SOA thingy is trying to build.  In a nutshell... A new programing language.

Since the beginning of computing, we have tried to abstract various pieces of the problem domain to make it easier to program.  Originally, you would have to create a bootstrap to start up your computer or build a device driver to actually use a disk drive.  We have built operating systems and device drivers to abstract out these problems.  What these abstrations have caused to happen is the problem of development is getting less and less technical and increase the population who can actually code.

So, what are service then?  Services are the commands of this new programming language.  The more abstract, but general you make them, they more a "programmer" can use them to build his code.  That is why people say that a service should perform some sort of business functionality or encapsulate some enterprise data object or even have a utility.  

To be sure, you can use the traditional IDEs/languages (.Net, Java) to program in this new level of abstraction.  But other tools come into their own.  BPM (Business Process Modeling), Portals are simpler IDEs for the likes of the new "programmer," but again the purpose is to reduce the complexity of programming by absorbing it into the infrastruture.  When you build an SOA, you are adding a layer of abstration to your infrastruture.

So, in answer to the question, how granular should your service be?  My answer is that you should consider the business user who will be programming in this new language.  Be complex enough to be usable, but general enough not to limit.  If it doesn't provide a single specific business functionality or encapsulate a business object nor provide a single definable utility, it is probably not rightsized.
# April 11, 2006 3:11 PM

richardt said:

Sorry - I totally disagree with your premise. Service Orientation does not propose a new programming language. It doesn't dictate a syntax, methodology or many of the other aspects required to define a language.

Services are not commands - they're groupings of related functionality. Services are more akin to classes than commands/methods/actions, but without the baggage of tightly-coupled OO notions such as inheritance and polymorphism.

I'd also propose a modification to your statement about how more granular services are more applicable to given scenarios. I'd argue that more granular services are more QUICKLY applicable, but are not more applicable. Larger grained services are more general but are therefore less flexible and apply to fewer different scenarios. The only way they become MORE applicable is if the general community migrates to a common approach to solve the need and are willing to forego individual specialization in order to generalize their scenario.

You also mention BPM tools. I totally agree with you on this. In fact, so does Microsoft. Hence Windows Workflow Foundation - an in-process, user-oriented, workflow facility for Windows apps, and BizTalk, a process automation and orchestration engine. Workflow/Orchestration enable apps to be composed more than written and will result in dramatic improvements in time to delivery of many forms of app and project.

Your final paragraph is where we come to agreement on the opening statement of this post - architecture is as much art as science. Sometimes, more so!
# April 20, 2006 3:51 PM
Anonymous comments are disabled
Page view tracker