Service Granularity Principle
Encyclopedia
Service Granularity is a design principle to provide optimal scope
Scope
The word scope may refer to many different devices or viewing instruments, constructed for many different purposes. It may refer to a telescopic sight, an optical device commonly used on firearms. Other uses of scope or Scopes may refer to:...

 of the business functionality in a service operation
Web service
A Web service is a method of communication between two electronic devices over the web.The W3C defines a "Web service" as "a software system designed to support interoperable machine-to-machine interaction over a network". It has an interface described in a machine-processable format...

. It is important to design the service operation with right granularity.

Interpretation

A coarse-grained service operation is defined to address broader scope in functionality and in more situations it have increased design complexity associated with it. But, it have the benefit of reduced number of calls to various service operations as it is provides a bunch of related functionality in a single service operation.

Similarly, a fine-grained service operation is defined to address a narrow scope in functionality and in more situations it have decreased design complexity associated with it. But, it increases the number of calls to various service operations as it creates more number of service operations for each individual functionality even if its related.

The terms coarse-grained and fine-grained are relative terms. It is important to strike right balance of functionality addressed between coarse-grained and fine-grained service operations and should be at an optimal level.

There are four key factors to consider when you are designing for optimal granularity:
  • Performance
  • Size of the Message
  • Transaction
  • Business function


While there may be no perfect granularity for each situation, these four factors guides your decision making.

Performance

Web services are accessed remotely and calls to web service operation create more network overhead. So, try to minimize the calls to service operations by opting for the more coarse-grained service operation. But if the service is more coarse grained, it may reduce reusability.

Size of the Message

If the size of the message exchanged in a service operation call increases, then it in turn increases the memory load on the server (since it need to hold the message in the memory for processing) and decreases the number of parallel processing performed at a time which decreases the overall slowdown in effective performance. So, the emphasis should be on reducing the size of a message. To achieve it, try to split a service operation processing a larger size of message into multiple service operations by opting for the more fine-grained service operation which processes a smaller size of message.

In some situations where same smaller dataset getting repeated multiple times without limitation (like an unbounded array or list), will tend to create a bigger size message some times as its not restricted. In such cases try to split it into multiple service calls by opting for the more fine grained service operation calls using dataset filters to reduce the size of message getting bigger.

Transaction

To achieve better transactionability, the recommendation is to design the service in a way to have one transaction per service operation. This helps in better error recovery, simpler design, better service autonomy and the choice can be a fine-grained service operation.

Business Function

  • Simplicity and generality of a business task/function greatly influence the granularity.
  • Strive for a single service to fulfill a complete business task, and only add extra service operations as if it is absolutely necessary.

CheckStock service is an example (by passing type of stock to check, this single service can serve multiple consumers to check different types of stock availability)
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK