Chapter 4: Service-Oriented Architecture (SOA)
and Microservices Architecture
What is service-oriented architecture?
Service-oriented architecture (SOA) is a method of software development that
uses software components called services to create business applications. Each service
provides a business capability, and services can also communicate with each other
across platforms and languages. Developers use SOA to reuse services in different
systems or combine several independent services to perform complex tasks.
For example, multiple business processes in an organization require the user
authentication functionality. Instead of rewriting the authentication code for all business
processes, you can create a single authentication service and reuse it for all applications.
Similarly, almost all systems across a healthcare organization, such as patient
management systems and electronic health record (EHR) systems, need to register
patients. These systems can call a single, common service to perform the patient
registration task.
What are the benefits of service-oriented architecture?
Service-oriented architecture (SOA) has several benefits over the traditional monolithic
architectures in which all processes run as a single unit. Some major benefits of SOA
include the following:
Faster time to market
Developers reuse services across different business processes to save time and
costs. They can assemble applications much faster with SOA than by writing code and
performing integrations from scratch.
Efficient maintenance
It’s easier to create, update, and debug small services than large code blocks in
monolithic applications. Modifying any service in SOA does not impact the overall
functionality of the business process.
Greater adaptability
SOA is more adaptable to advances in technology. You can modernize your
applications efficiently and cost effectively. For example, healthcare organizations can
use the functionality of older electronic health record systems in newer cloud-based
applications.
What are the basic principles of service-oriented
architecture?
There are no well-defined standard guidelines for implementing service-oriented
architecture (SOA). However, some basic principles are common across all SOA
implementations.
Interoperability
Each service in SOA includes description documents that specify the functionality
of the service and the related terms and conditions. Any client system can run a service,
regardless of the underlying platform or programming language. For instance, business
processes can use services written in both C# and Python. Since there are no direct
interactions, changes in one service do not affect other components using the service.
Loose coupling
Services in SOA should be loosely coupled, having as little dependency as
possible on external resources such as data models or information systems. They should
also be stateless without retaining any information from past sessions or transactions.
This way, if you modify a service, it won’t significantly impact the client applications and
other services using the service.
Abstraction
Clients or service users in SOA need not know the service's code logic or
implementation details. To them, services should appear like a black box. Clients get the
required information about what the service does and how to use it through service
contracts and other service description documents.
Granularity
Services in SOA should have an appropriate size and scope, ideally packing one
discrete business function per service. Developers can then use multiple services to
create a composite service for performing complex operations.
What are the components in service-oriented architecture?
There are four main components in service-oriented architecture (SOA).
1. Service
Services are the basic building blocks of SOA. They can be private—available only to
internal users of an organization—or public—accessible over the internet to all.
Individually, each service has three main features.
Service implementation
The service implementation is the code that builds the logic for performing the specific
service function, such as user authentication or bill calculation.
Service contract
The service contract defines the nature of the service and its associated terms and
conditions, such as the prerequisites for using the service, service cost, and quality of
service provided.
Service interface
In SOA, other services or systems communicate with a service through its service
interface. The interface defines how you can invoke the service to perform activities or
exchange data. It reduces dependencies between services and the service requester.
For example, even users with little or no understanding of the underlying code logic can
use a service through its interface.
2. Service provider
The service provider creates, maintains, and provides one or more services that others
can use. Organizations can create their own services or purchase them from third-party
service vendors.
3. Service consumer
The service consumer requests the service provider to run a specific service. It can be an
entire system, application, or other service. The service contract specifies the rules that
the service provider and consumer must follow when interacting with each other. Service
providers and consumers can belong to different departments, organizations, and even
industries.
4. Service registry
A service registry, or service repository, is a network-accessible directory of available
services. It stores service description documents from service providers. The description
documents contain information about the service and how to communicate with it. Service
consumers can easily discover the services they need by using the service registry.
How does service-oriented architecture work?
In service-oriented architecture (SOA), services function independently and provide
functionality or data exchanges to their consumers. The consumer requests information
and sends input data to the service. The service processes the data, performs the task,
and sends back a response. For example, if an application uses an authorization service,
it gives the service the username and password. The service verifies the username and
password and returns an appropriate response.
Communication protocols
Services communicate using established rules that determine data transmission over a
network. These rules are called communication protocols. Some standard protocols to
implement SOA include the following:
• Simple Object Access Protocol (SOAP)
• RESTful HTTP
• Apache Thrift
• Apache ActiveMQ
• Java Message Service (JMS)
You can even use more than one protocol in your SOA implementation.
What is an ESB in service-oriented architecture?
An enterprise service bus (ESB) is software that you can use when communicating with
a system that has multiple services. It establishes communication between services and
service consumers no matter what the technology.
Benefits of ESB
An ESB provides communication and transformation capabilities through a reusable
service interface. You can think of an ESB as a centralized service that routes service
requests to the appropriate service. It also transforms the request into a format that is
acceptable for the service’s underlying platform and programing language.
What are the limitations in implementing service-oriented
architecture?
Limited scalability
System scalability is significantly impacted when services share many
resources and need to coordinate to perform their functionality.
Increasing interdependencies
Service-oriented architecture (SOA) systems can become more complex
over time and develop several interdependencies between services. They can be
hard to modify or debug if several services are calling each other in a loop. Shared
resources, such as centralized databases, can also slow down the system.
Single point of failure
For SOA implementations with an ESB, the ESB creates a single point of
failure. It is a centralized service, which goes against the idea of decentralization
that SOA advocates. Clients and services cannot communicate with each other at
all if the ESB goes down.
Challenges and Solutions in Implementing SOA
Implementing a Service-Oriented Architecture (SOA) can bring many benefits, but it also
presents a number of challenges. Here are some common challenges and solutions:
1. Governance
One of the biggest challenges with SOA is managing the lifecycle of services and
ensuring that they are properly governed. A solution to this challenge is to establish
a governance framework that includes policies, processes, and tools for managing
services throughout their lifecycle.
2. Integration
Integrating services can be complex, especially when dealing with legacy systems
and heterogeneous environments. To address this challenge, it is important to have
a well-defined integration strategy that includes standards, protocols, and tools for
integrating services.
3. Service Identification
Identifying the right services to build and reuse can be difficult, especially when
dealing with large and complex systems. To address this challenge, it is important
to have a service-oriented architecture roadmap that identifies key services and their
dependencies.
4. Service Reuse
Reusing services across multiple applications and systems can be a key benefit of
SOA, but it requires careful planning and management. To address this challenge,
it is important to establish a service repository and to encourage service reuse across
the organization.
5. Security
Services can be a potential security vulnerability, especially when exposed to the
internet or other external systems. To address this challenge, it is important to
establish security policies and mechanisms that protect services from unauthorized
access and ensure data privacy and integrity.
6. Performance and Scalability
As the number of services and service consumers grows, performance and
scalability can become a challenge. To address this challenge, it is important to
design services for scalability and to use performance testing and monitoring tools
to identify and address bottlenecks.
7. Organizational Change
Implementing SOA requires changes to the organization's culture, processes, and
technology. To address this challenge, it is important to establish a change
management plan that includes communication, training, and support for the
organization's stakeholders.
What are microservices?
Microservices architecture is made up of very small and completely independent
software components, called microservices, that specialize and focus on one task only.
Microservices communicate through APIs, which are rules that developers create to let
other software systems communicate with their microservice.
The microservices architectural style is best suited to modern cloud computing
environments. They often operate in containers—independent software units that
package code with all its dependencies.
Microservices are an architectural and organizational approach to software
development where software is composed of small independent services that
communicate over well-defined APIs. These services are owned by small, self-
contained teams.
Microservices architectures make applications easier to scale and faster to
develop, enabling innovation and accelerating time-to-market for new features.
Monolithic vs. Microservices Architecture
With monolithic architectures, all processes are tightly coupled and run
as a single service. This means that if one process of the application
experiences a spike in demand, the entire architecture must be scaled. Adding
or improving a monolithic application’s features becomes more complex as the
code base grows. This complexity limits experimentation and makes it difficult
to implement new ideas. Monolithic architectures add risk for application
availability because many dependent and tightly coupled processes increase
the impact of a single process failure.
With a microservices architecture, an application is built as
independent components that run each application process as a service. These
services communicate via a well-defined interface using lightweight APIs.
Services are built for business capabilities and each service performs a single
function. Because they are independently run, each service can be updated,
deployed, and scaled to meet demand for specific functions of an application.
Characteristics of Microservices
Autonomous
Each component service in a microservices architecture can be
developed, deployed, operated, and scaled without affecting the
functioning of other services. Services do not need to share any
of their code or implementation with other services. Any
communication between individual components happens via
well-defined APIs.
Specialized
Each service is designed for a set of capabilities and focuses on
solving a specific problem. If developers contribute more code to
a service over time and the service becomes complex, it can be
broken into smaller services.
Benefits of Microservices
Agility
Microservices foster an organization of small, independent teams that
take ownership of their services. Teams act within a small and well
understood context, and are empowered to work more independently
and more quickly. This shortens development cycle times. You benefit
significantly from the aggregate throughput of the organization.
Flexible Scaling
Microservices allow each service to be independently scaled to
meet demand for the application feature it supports. This enables
teams to right-size infrastructure needs, accurately measure the
cost of a feature, and maintain availability if a service experiences
a spike in demand.
Easy Deployment
Microservices enable continuous integration and continuous
delivery, making it easy to try out new ideas and to roll back if
something doesn’t work. The low cost of failure enables
experimentation, makes it easier to update code, and accelerates
time-to-market for new features.
Technological Freedom
Microservices architectures don’t follow a “one size fits all”
approach. Teams have the freedom to choose the best tool to
solve their specific problems. As a consequence, teams building
microservices can choose the best tool for each job.
Reusable Code
Dividing software into small, well-defined modules enables teams
to use functions for multiple purposes. A service written for a
certain function can be used as a building block for another
feature. This allows an application to bootstrap off itself, as
developers can create new capabilities without writing code from
scratch.
Resilience
Service independence increases an application’s resistance to
failure. In a monolithic architecture, if a single component fails, it
can cause the entire application to fail. With microservices,
applications handle total service failure by degrading functionality
and not crashing the entire application.
Microservices are independently scalable, fast, portable, and platform
agnostic—characteristics native to the cloud. They are also decoupled, which
means they have limited to no dependencies on other microservices. To achieve
this, microservices have local access to all the data they need instead of remote
access to centralized data that other systems also access and use. This creates
data duplication which microservices make up for in performance and agility.
Implementing microservices architecture presents several challenges, including:
1. Increased complexity
Microservices architecture requires a greater level of complexity in terms of design,
development, testing, deployment, and management.
2. Distributed architecture
Microservices architecture involves multiple services that are distributed across
different servers or even different geographical locations, which can lead to issues
with latency, network bandwidth, and data consistency.
3. Integration testing
Testing microservices requires integration testing between different services, which
can be difficult and time-consuming.
4. Monitoring and management
Microservices architecture requires a more sophisticated approach to monitoring
and management, including the use of containerization, load balancing, and service
discovery tools.
5. Deployment automation
Microservices architecture requires automated deployment processes to ensure that
new services are deployed quickly and consistently.
Some solutions to these challenges include:
1. Service design principles
Adopting service design principles, such as separation of concerns, encapsulation,
and loose coupling, can help to reduce complexity and improve scalability.
2. API gateways
Using API gateways can help to simplify the integration of microservices and
improve security.
3. Containerization
Containerization, such as using Docker, can help to simplify deployment and
management of microservices.
4. Automation
Automating the deployment, testing, and management of microservices can help to
reduce complexity and improve consistency.
5. Service mesh
Implementing a service mesh, such as Istio, can help to manage the complexity of
microservices architecture by providing service discovery, load balancing, and other
features.
SOA compared to Microservices
Microservices architecture is an evolution of the SOA architectural style.
Microservices address the shortcomings of SOA to make the software more
compatible with modern cloud-based enterprise environments. They are fine
grained and favor data duplication as opposed to data sharing. This makes them
completely independent with their own communication protocols that are exposed
through lightweight APIs. It’s essentially the consumers' job to use the
microservice through its API, thus removing the need for a centralized ESB.
There are many tools and technologies that can be used to implement Service-Oriented
Architecture (SOA). Here are some examples of the many tools and technologies that can
be used to implement SOA. The specific tools used will depend on the requirements of the
application and the programming languages and frameworks being used:
1. Oracle SOA Suite
Oracle SOA Suite is a comprehensive suite of tools and technologies that can be
used to implement SOA. It includes a wide range of features such as service
orchestration, service bus, adapters, and business process management tools.
2. Apache Axis2
Apache Axis2 is a popular open-source web services engine that can be used to
build and deploy SOA-based applications. It includes support for a wide range of
web services standards and protocols, making it a versatile and flexible tool for
building distributed systems.
3. Microsoft BizTalk Server
Microsoft BizTalk Server is an enterprise-level integration platform that can be used
to implement SOA. It includes a wide range of adapters and connectors that make
it easy to integrate with different systems and applications, as well as a powerful set
of development tools for building and deploying services.
4. MuleSoft Anypoint Platform
MuleSoft Anypoint Platform is a cloud-based integration platform that provides a
range of tools and technologies for implementing SOA. It includes a powerful
service bus, a comprehensive set of connectors and adapters, and a range of
development tools for building and deploying services.
5. IBM WebSphere
IBM WebSphere is a family of middleware products that can be used to implement
SOA-based applications. It includes a wide range of features such as service
orchestration, message routing, and data transformation, making it a powerful and
flexible tool for building distributed systems.
Some examples of Service-Oriented Architecture (SOA) with example codes and the
programming languages used. How different programming languages and frameworks can
be used to implement SOA, depending on the specific requirements of the application.
1. Java API for XML Web Services (JAX-WS): JAX-WS is a Java technology that
allows web services to be developed using the Java programming language. It
supports the SOAP protocol and provides a standardized way of building web
services.
2. Simple Object Access Protocol (SOAP): SOAP is a messaging protocol used to
exchange structured data between web services. It is based on XML and provides a
standardized way of building web services.
xml
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ser="http://www.example.com/service">
<soapenv:Header/>
<soapenv:Body>
<ser:SayHello>
<ser:Name>John</ser:Name>
</ser:SayHello>
</soapenv:Body>
</soapenv:Envelope>
3. Representational State Transfer (REST): REST is a web architecture style that
uses HTTP methods to access and manipulate web resources. It provides a
lightweight and flexible way of building web services.
There are many tools and technologies that can be used to implement microservices. The
specific tools used will depend on the requirements of the application and the programming
languages and frameworks being used. Here are some examples:
1. Docker
Docker is a containerization platform that allows microservices to be packaged and
deployed in a lightweight and efficient way. It provides a standardized way of
building, shipping, and running microservices, making it easier to manage and scale
distributed applications.
2. Kubernetes
Kubernetes is a container orchestration platform that provides a framework for
managing and scaling microservices in a clustered environment. It automates many
of the tasks involved in deploying and managing microservices, such as load
balancing, scaling, and service discovery.
3. Spring Boot
Spring Boot is a Java-based framework that provides a simple and easy-to-use
platform for building microservices. It includes a wide range of libraries and tools
that make it easy to create, deploy, and manage microservices, including support for
RESTful web services, messaging systems, and service discovery.
4. Node.js
Node.js is a popular JavaScript runtime that can be used to build fast and scalable
microservices. It includes a lightweight and event-driven architecture that makes it
well-suited for building distributed systems, and it has a large and active community
of developers that contribute to its ecosystem.
5. Apache Kafka
Apache Kafka is a distributed streaming platform that can be used to build event-
driven microservices. It provides a scalable and fault-tolerant way of processing and
analyzing large streams of data, making it well-suited for real-time applications and
data-intensive workloads.
Here are some examples of microservices with example codes and the programming
languages used and how different programming languages and frameworks can be used to
implement microservices, depending on the specific requirements of the application.
1. Netflix's Eureka
Netflix's Eureka is a service registry that allows microservices to locate and
communicate with each other. It is written in Java and uses the Spring Framework.
2. Amazon's Lambda
Amazon's Lambda is a serverless computing platform that allows microservices to
run code without provisioning or managing servers. It supports multiple
programming languages, including Java, Python, and Node.js.
3. Uber's Cadence
Uber's Cadence is a workflow management system that allows microservices to
coordinate and orchestrate complex business processes. It is written in Go and
supports multiple programming languages.
go
package main
import (
"context"
"go.uber.org/cadence/client"
"go.uber.org/cadence/worker"
)
func main() {
domain := "my-domain"
taskList := "my-tasklist"
clientOptions := client.Options{
Domain: domain,
BatchSize: 10,
}
c, err := client.NewClient(clientOptions)
if err != nil {
// handle error
}
workerOptions := worker.Options{
MaxConcurrentActivityExecutionSize: 10,
}
w := worker.New(c, taskList, workerOptions)
w.RegisterActivity(MyActivity)
w.RegisterWorkflow(MyWorkflow)
err = w.Run(context.Background())
if err != nil {
// handle error
}
}
func MyActivity(ctx context.Context) (string, error) {
// implementation
}
func MyWorkflow(ctx workflow.Context) error {
// implementation
}