In the context of
software engineering
Software engineering is a systematic engineering approach to software development.
A software engineer is a person who applies the principles of software engineering to design, develop, maintain, test, and evaluate computer software. The term ' ...
and
software architecture
Software architecture is the fundamental structure of a software system and the discipline of creating such structures and systems. Each structure comprises software elements, relations among them, and properties of both elements and relations.
...
, service granularity is a key design concern when applying the paradigm of
service-orientation Service-orientation is a design paradigm for computer software in the form of services. The principles of service-oriented design stress the separation of concerns in the software. Applying service-orientation results in units of software partiti ...
for instance during
service-oriented modeling
Service-oriented modeling is the discipline of modeling business and software systems, for the purpose of designing and specifying Service-orientation, service-oriented business systems within a variety of architectural styles and paradigms, such ...
. Service granularity specifies the scope of business functionality and the structure of the message payload in a service operation that is provided within a
service-oriented architecture (SOA).
Definition
Service granularity is both an application domain concern (''business granularity''), as well as a
software interface design issue (''technical granularity''); it is a property of the service
contract
A contract is a legally enforceable agreement between two or more parties that creates, defines, and governs mutual rights and obligations between them. A contract typically involves the transfer of goods, services, money, or a promise to ...
exposed by a service provider. It pertains to the semantics and syntax of the in (request) and out (response) message content, which can be viewed as instances of two general
Enterprise Integration PatternsCommand Messagean
By definition a coarse-grained service operation has broader scope than a fine-grained service, although the terms are relative. The former typically requires increased design complexity but can reduce the number of calls required to complete a task.
Criteria
Due to the
fallacies of distributed computing, finding an adequate granularity is hard. There is no single simple answer but a number of criteria exist (see below). A primary goal of service modeling and granularity design is to achieve
loose coupling
In computing and systems design, a loosely coupled system is one
# in which components are weakly associated (have breakable relationships) with each other, and thus changes in one component least affect existence or performance of another comp ...
and
modularity
Broadly speaking, modularity is the degree to which a system's components may be separated and recombined, often with the benefit of flexibility and variety in use. The concept of modularity is used primarily to reduce complexity by breaking a s ...
, which are two of the essential SOA principles, and to address other
architecturally significant requirements.
Many forces influence the service granularity; four particularly relevant factors to consider when designing for an adequate granularity are performance, message size, transactionality and business function:
Business function
Ideally, each service operation maps to a single business function, although if a single operation can provide multiple functions without adding design complexity or increasing message sizes, this generality can reduce implementation and usage costs.
Performance
Web services are accessed remotely and calls to web service operation create more network overhead. Reducing the number of service requests reduces that overhead.
Message size
Coarse-grained services may pass more data than fine-grained services, including data that is not specifically required for the task. This complicates message processing in the endpoint and might in turn harm performance. Reducing message size may require adding a more fine-grained operation.
Quality-of-service characteristics including transactionality
For conceptual clarity each service operation should perform a single system-level transaction and leave data integrity across service boundaries to the business logic in the service consumer. This also simplifies error recovery, and typically eases design.
Many more decision criteria for finding an appropriate granularity exist; there is no global optimum. Sixteen such coupling criteria are compiled from the literature in.
[Service Cutter: A Systematic Approach to Service Decomposition, M Gysel, L Kölbener, et al.. European Conference on Service-Oriented and Cloud Computing, 185-200,]
PDF
Patterns
As one size does not fit all, the design of service granularities can benefit from many existing pattern works on various kinds of distributed systems, especially those related to services, as well as pattern works related to API design (e.g., API design in object-oriented programming) and enterprise integration. An overview of such languages is give
here
References
{{Reflist
External links
Conceptual Service Granularity FrameworkService granularity entry in a service glossaryCooking EA - Service GranularityIEEE Case Study on The Role of Service Granularity in A Successful SOA RealizationArchitectural Knowledge in a SOA Infrastructure Reference Architecture(SOA case study)
provides information about Service Granularity Principle and useful advice about how to get it right.
Solving the Service Granularity ChallengeCoarse-grained interfacesA Metrics Framework for Evaluating SOA Service GranularityService Cutter tool and coupling criteria catalog on GitHub
Service-oriented (business computing)