Common Principles of Service-Orientation: Services Are Reusable
Common Principles of Service-Orientation: Services Are Reusable
1
Common Principles of Service-Orientation
2
Common Principles of Service-Orientation
• Services are autonomous
– The logic governed by a service resides within an explicit
boundary.
– The service has control within this boundary and is not
dependent on other services for it to execute its
governance.
• Services are stateless
– Services should not be required to manage state
information, as that can impede their ability to remain
loosely coupled.
– Services should be designed to maximize statelessness
even if that means deferring state management
elsewhere.
3
Common Principles of Service-Orientation
4
Services are Reusable
• Service-orientation encourages reuse in all services,
regardless if immediate requirements for reuse exist.
• Application of design standards is required so that
future requirements can be easily accommodated
• No need to create wrapper services if the services
are reusable
• This principle facilitates all forms of reuse, including
inter-application interoperability, composition and
the creation of utility services.
5
Services are Reusable
…
As we established earlier in this chapter, a service is simply a collection of related
operations. It is therefore the logic encapsulated by the individual operations that
must be deemed reusable to warrant representation as a reusable service (Figure
8.13).
Figure 8.13. A reusable service exposes reusable operations.
6
Services are Reusable
• “Messaging indirectly supports service reusability
through the use of SOAP headers.“
– The processing-specific logic embedded in a message
alleviates the need for a service to contain this logic.
– More importantly, it imposes a requirement that
service operations become less activity-specific.
Messaging also indirectly supports service reusability through the use of SOAP
headers. These allow for messages to become increasingly self-reliant by grouping
metadata details with message content into a single package (the SOAP envelope).
Messages can be equipped with processing instructions and business rules that allow
them to dictate to recipient services how they should be processed.
The processing-specific logic embedded in a message alleviates the need for a service
to contain this logic. More importantly, it imposes a requirement that service
operations become less activity-specificin other words, more generic. The more
generic a service's operations are, the more reusable the service.
7
Services share a Formal Contract
• Service contracts provide a formal definition of:
– The service endpoint
– Each service operation
– Every input and output message supported by
each operation
– Rules and characteristics of the service and its
operations
8
Services share a Formal Contract
Service contracts therefore define almost all of the primary parts of an SOA (Figure
8.15). Good service contracts also may provide semantic information that explains
how a service may go about accomplishing a particular task. Either way, this
information establishes the agreement made by a service provider and its service
requestors.
Figure 8.15. Service contracts formally define the service, operation, and message
components of a service-oriented architecture.
9
Services share a Formal Contract
• “Contract design is extremely important.”
Because this contract is shared among services, its design is extremely important.
Service requestors that agree to this contract can become dependent on its
definition. Therefore, contracts need to be carefully maintained and versioned after
their initial release.
As explained in Chapter 5, service description documents, such as the WSDL
definition, XSD schemas, and policies, can be viewed collectively as a
communications contract that expresses exactly how a service can be
programmatically accessed.
10
Services are Loosely Coupled
• “No one can predict how an IT environment will
evolve.”
• Loose Coupling:
– “Having knowledge of other services still remain
independent”
11
Realizing this form of agility is directly supported by establishing a loosely coupled
relationship between services (Figure 8.16).
Figure 8.16. Services limit dependencies to the service contract, allowing underlying
provider and requestor logic to remain loosely coupled.
12
Services are Loosely Coupled
• Loose coupling is achieved through the use of service
contracts that allow services to interact within
predefined parameters.
13
Services Abstract underlying logic
• Also referred to as service interface-level abstraction,
it is this principle that allows services to act as black
boxes, hiding their details from the outside world.
14
Figure 8.17. Service operations abstract the underlying details of the functionality
they expose.
There is no limit to the amount of logic a service can represent. A service may be
designed to perform a simple task, or it may be positioned as a gateway to an entire
automation solution. There is also no restriction as to the source of application logic a
service can draw upon. For example, a single service can, technically, expose
application logic from two different systems (Figure 8.17).
15
Services Abstract underlying logic
• “Operation granularity is a primary design
consideration”
– It is the individual operations that collectively
abstract the underlying logic.
– Services simply act as containers for these
operations.
• The loosely coupled communications structure
requires that the only piece of knowledge services
need to interact is each others' service descriptions.
16
Because both RailCo and TLS employ Web services to communicate, each
environment successfully implements service interface-level abstraction. On RailCo's
end, this abstraction hides the legacy systems involved with generating electronic
invoice documents and processing incoming purchase orders. On the TLS side,
services hide service compositions wherein processing duties are delegated to
specialized services as part of single activities (Figure 8.18).
Figure 8.18. Neither of RailCo's or TLS's service requestors require any knowledge of
what lies behind the other's service providers.
17
Services are Composable
• Services should be able to take part in compositions
as and when required
18
Figure 8.19. The UpdateEverything operation encapsulating a service composition.
19
Services are Composable
• “Composability is simply another form of reuse”
– Therefore operations need to be designed in a
standardized manner
– and with an appropriate level of granularity to
maximize composition opportunities.
20
Case Study
21
Services are Autonomous
• Autonomy requires that the range of logic exposed by a
service exist within an explicit boundary.
22
Figure 8.22. Autonomous services have control over underlying resources.
23
Services are Autonomous
• “Deferring the location of business rules is one way to
strengthen autonomy and keep services more generic.”
– Orchestration helps to achieve this aspect
24
Services are Autonomous
1. Service-level Autonomy
– Service boundaries are distinct from each other,
but the service may share underlying resources.
2. Pure Autonomy
– The underlying logic is under complete control
and ownership of the service.
– Used when a new service is being built
Service-level autonomy Service boundaries are distinct from each other, but the
service may share underlying resources. For example, a wrapper service that
encapsulates a legacy environment that also is used independently from the service
has service-level autonomy. It governs the legacy system but also shares resources
with other legacy clients.
Pure autonomy The underlying logic is under complete control and ownership of the
service. This is typically the case when the underlying logic is built from the ground
up in support of the service.
25
Services are Stateless
• Services should minimize the amount of state
information they manage and the duration for which
they hold it.
26
Figure 8.24. Stateless and stateful stages a service passes through while processing a
message.
27
Services are Stateless
• “Statelessness is a preferred condition for services and
one that promotes reusability and scalability”.
28
Services are Discoverable
• Discovery helps avoid the accidental creation of
redundant services or services that implement
redundant logic.
Note that this service-orientation principle is related to but distinct from the
contemporary SOA characteristic of discoverability. On an SOA level, discoverability
refers to the architecture's ability to provide a discovery mechanism, such as a service
registry or directory. This effectively becomes part of the IT infrastructure and can
support numerous implementations of SOA. On a service level, the principle of
discoverability refers to the design of an individual service so that it can be as
discoverable as possible.
29
So far,
• Different organizations have published their own
versions of service-oriented principles. As a result,
many variations exist.
• The most common principles relate to loose
coupling, autonomy, discoverability, composability,
reuse, service contracts, abstraction, and
statelessness.
30
?
• What's the difference between reusability and
composability?
• What's the difference between autonomy and
statelessness?
• What's the difference between loose coupling and
the use of a service contract?
When reading through the previous descriptions, a number of questions might come
to mind, such as:
What's the difference between reusability and composability? (Aren't you reusing a
service when you compose it?)
What's the difference between autonomy and statelessness? (Aren't both a
representation of service independence?)
What's the difference between loose coupling and the use of a service contract?
(Doesn't a service contract automatically implement loose coupling?)
To answer these and other questions, this section revisits our service-orientation
principles to explore how each relates to, supports, or is affected by others. To
accomplish this, we abbreviate the original names we assigned each principle, as
follows:
31
Service-Orientation Principles
We intentionally prefix each principle with the word "service" to emphasize that the
principle applies to the design of a service only, as opposed to our SOA
characteristics, which apply to the design of SOA as a whole.
Note
Each relationship is essentially described twice within these sections. This
repetitiveness is intentional, as this part of the chapter is provided more for reference
purposes.
32
Service reusability and its relationship with other service-orientation principles.
33
The diagram in Figure 8.27 illustrates how the principle of service contract usage
relates to others.
Figure 8.27. The service contract and its relationship with other service-orientation
principles
34
Figure 8.28 demonstrates these relationships.
Figure 8.28. Service loose coupling and its relationship with other service-orientation
principles.
35
These relationships are shown in Figure 8.29.
Figure 8.29. Service abstraction and its relationship with other service-orientation
principles.
36
Figure 8.30 further illustrates these relationships.
Figure 8.30. Service composability and its relationship with other service-orientation
principles.
37
The diagram in Figure 8.31 shows how service autonomy relates to these other
principles.
Figure 8.31. Service autonomy and its relationship with other service-orientation
principles.
38
Figure 8.32 illustrates how service statelessness relates to the other service-
orientation principles.
Figure 8.32. Service statelessness and its relationship with other service-orientation
principles.
39
The diagram in Figure 8.33 shows how service discoverability fits in with the other
service-orientation principles.
Figure 8.33. Service discoverability and its relationship with other service-orientation
principles.
40
So far,
• Service-orientation principles are not realized in
isolation; principles relate to and support other
principles in different ways.
• Principles, such as service reusability and service
composability, benefit from the support of other
implemented principles.
• Principles, such as service loose coupling, service
contract, and service autonomy, provide significant
support for the realization of other principles.
41
Service-orientation and Object-orientation
Those of you familiar with object-oriented analysis and design probably will have
recognized a similarity between a number of the service-orientation principles
discussed and the more established principles of object-orientation.
Indeed, service-orientation owes much of its existence to object-oriented concepts
and theory.
42
Service-orientation and Object-orientation
43
Service-orientation and Object-orientation
44
Service-orientation and Object-orientation
SO Principle Related Object-Orientation Principles
service The object-orientation principle of abstraction
abstraction requires that a class provide an interface to the
external world and that it be accessible via this
interface.
Encapsulation supports this by establishing the
concept of information hiding.
Service abstraction accomplishes much of the same
as object abstraction and encapsulation. Its purpose
is to hide the underlying details of the service so
that only the service contract is available and of
concern to service requestors.
45
Service-orientation and Object-orientation
SO Principle Related Object-Orientation Principles
service Object-orientation supports association concepts,
composability such as aggregation and composition.
46
Service-orientation and Object-orientation
SO Principle Related Object-Orientation Principles
service The quality of autonomy is more emphasized in
autonomy service-oriented design than it has been with
object-oriented approaches.
Achieving a level of independence between units of
processing logic is possible through service-
orientation, by leveraging the loosely coupled
relationship between services.
Cross-object references and inheritance-related
dependencies within object-oriented designs
support a lower degree of object-level autonomy.
47
Service-orientation and Object-orientation
SO Principle Related Object-Orientation Principles
service Objects consist of a combination of class and data
statelessness and are naturally stateful.
48
Service-orientation and Object-orientation
SO Principle Related Object-Orientation Principles
service Designing class interfaces to be consistent and
discoverability self-descriptive is another object-orientation
best practice.
49
So far,
• Several principles of service-orientation are related
to and derived from object-orientation principles.
• Some object-orientation principles, such as
inheritance, do not fit into the service-oriented
world.
• Some service-orientation principles, such as loose
coupling and autonomy, are not directly promoted by
object-orientation.
50