Ehsan Ghanbari

Experience, DotNet, Solutions

Should each service has its own data in SOA?

Recently I'm tackling with a problem which has some dependencies with SOA architecture. It's where a question about SOA architecture comes out: "Does each service has its own data in SOAs?" After searching on the web I found different answers to this question.  It seems that it depends on conditions!

Suppose if something happens in a point everything in the whole system, the process should be back to the earlier point because each task is independent of the others, right? In this case, if every service has its own data, it will be easier to deal with the scenario. There is a solution for that: as in SOA architecture, every service can be hosted on a different machine, so we can dedicate one of the services to data management (Datacenter). 

In other way, Services can cache data of other Services. And any changes in the source of the data should be published so the subscribing Services can update their cache. Although this is the cost-effective solution, it is a good one! It also increases the availability of a Service by preventing it from being dependent on the data of other Services. and if the other Service is not available, it can still do its job by its cache data.



Long running processes in SOA

"In an SOA each functionality is separated as a service. So, a certain application may use many services to provide a defined functionality. The principles of SOA define services as a separate platform- and system-independent entities - each capable of functioning on their own, thus providing reusability and interoperability across disparate platforms."

There are various lifetimes of the transaction in SOA architecture (Transaction lifetime is the minimum of time that a transaction is kept open).  A transaction could end in a few seconds or a couple of days! It depends on the underlying business requirements and implementation. Transactions with a short lifetime are easy to handle since the resources they use can be locked for the time required by maintaining the ACID properties. But the same strategy can't be applied to long-running transactions.

There are various scenarios which make the long-running process possible such as a transaction with lots of database queries, Batch processing and any kind of activity within the transaction. Batch processes run for long periods of time, usually for hours and mostly it only involves reading data. (in some cases it could contain modifying data). A failure during that operation would require an equally long rollback process.

Rather than all of the above notes, A long-running transaction creates a number of problems in an SOA architecture. As long as a transaction is limited to a closed environment, catching faults or exceptions and triggering the appropriate rollback mechanism can easily be defined in the underlying application architecture. in a distributed database environment these things can be taken care of.

 

For more information about the mentioned topic, you can refer these URLs:

  1. http://hydra.infosys.tuwien.ac.at/staff/zdun/publications/eplop06.pdf
  2. http://soa.sys-con.com/node/318438



Getting started with nServiceBus

When I read about nServiceBus or work with that it reminds me that "If it is complicated, you're probably doing it wrong". nServiceBus is really an amazing service platform for distributed systems and messaging. 

 

What is nServiceBus!?

nServiceBus is the most popular service platform for Dot Net. It's a powerful messaging framework for designing distributed .NET enterprise systems. nServiceBus gives you a scalable, and maintainable service-layers and long-running business processes. nServiceBus is structured around a bus which you can put messages and message handlers. It makes communicating with services much easier and incorporates true service oriented architecture. The main communication pattern behind NServiceBus is a pattern called "publish and subscribe".

By using nServiceBus a "Client can send messages if server is offline". It's an amazing feature, suppose that a client makes a request, what will happen if the server be inaccessible? With nServiceBus and its asynchronous fire & forget messaging pattern

 

 

nServiceBus messaging example

let's deep into nServiceBus implementation, create a simple class library and reference the NServiceBus, NServiceBus.Core, NServiceBus.Host.  If you get nServiceBus via Nuget, package will take care of the configuration for you. Your App.config should be something like this:

nServiceBus

I'm just going to implement a simple messaging with nServiceBus, in order to so this create a class with this definition:

  1.    public class Messaging : IMessage
  2.     {
  3.         public string Message { get; set; }
  4.     }

Now create the SendMessage class with like this:

  1.    public class SendingMessage
  2.     {
  3.         public IBus Bus { get; set; }
  4.        
  5.         public void Run()
  6.         {
  7.             Bus.SendLocal<Messaging>(m => m.Message = "nServiceBus message");
  8.         }
  9.     }

In this class by using the Bus property of nServiceBus you send the message locally, now you can create your CommandHandler  class to handle the message:

  1.     public class CommandHandler : IHandleMessages<Messaging>
  2.     {
  3.         private readonly IBus _bus;
  4.  
  5.         public CommandHandler(IBus bus)
  6.         {
  7.             _bus = bus;
  8.         }
  9.  
  10.         public void Handle(Messaging message)
  11.         {
  12.             throw new NotImplementedException();
  13.         }
  14.     }

 

This class will get invoked automatically when the Message(of Messaging class) arrives, you can handle the message and have it in a console output or something else. for more information about nServiceBus I recommend to read this articles.



Understanding basics of Service oriented architecture

"Service-oriented architecture (SOA) is a software design and software architecture design pattern based on structured collections of discrete software modules, known as services, that collectively provide the complete functionality of a large software application. The purpose of SOA is to allow easy cooperation of a large number of computers that are connected over a network. Every computer can run an arbitrary number of programs - called services in this context - that are built in a way that they can exchange information with any other service within the reach of the network without human interaction and without the need to make changes to the underlying program itself." ~Wikipedia

 

What is SOA?

SOA or Service oriented architecture for development and integration of service based applications. development and integration of services that use different platforms. services should be loosely coupled with operating systems and the technologies of underlying applications ,SOA is all about reducing coupling ,none of efferent and afferent coupling. SOA is not the same as Web services, see here for more information about differences. SOA is more than a set of technologies that runs independent of any specific technologies. SOA is directly built upon the principle of service-orientation, which talks about services with simple interface that can be accessed independently by users without worrying about the actual platform implementation of the service.

 

 

Service

Services are the basic building blocks in a Service Oriented architecture, A service is a self-contained unit of software that performs a specific task. "It has three components: an interface, contract, and implementation. The interface defines how a service provider will perform requests from a service consumer, the contract defines how the service provider and the service consumer should interact, and the implementation is the actual service code itself." Because the interface of a service is separate from its implementation, a service provider can execute a request without the service consumer knowing how it does so; the service consumer only worries about consuming services. Services should be self-contained business functionality, encapsulate one action, independent of other service, Not affect other service ,secure , communicate with each other synchronously.

 

Messaging

Services communicate with each other using messages. Messages are standard formats which every service can read and understand. SOA supports the concept of dynamic service discovery. The service consumer queries the "service registry for a service, and the service registry returns a list of all service providers that support the requested service. The consumer selects the cost-effective service provider from the list, and binds to the provider using a pointer from the service registry entry. The consumer formats a request message based on the contract specifications, and binds the message to a communications channel that the service supports. The service provider executes the service and returns a message that conforms to the message definition in service contract. The only dependency between provider and consumer is the contract, which the third-party service registry provides. The dependency is a runtime dependency and not a compile-time dependency. All the information the consumer needs about the service is obtained and used at runtime. The service interfaces are discovered dynamically, and messages are constructed dynamically. The service consumer does not know the format of the request message or response message or the location of the service until the service is actually needed.

 

Service oriented Programming

We have progressed from functions of traditional procedural programming, to objects of OOP and now to services. In SOA functions and tasks are created as loosely connected independent services communicating via messages. Service provider publishes the service via standard interfaces in a publicly accessible directory called Service Repository and Service consumer make a service request and in response gets the Service Response. it's better to separete the messaging and interfaces of service to separete layers.

 

 

SOA and SOAP

SOA  is a set of guidelines for designing loosely-coupled software systems. but SOAP (Simple Object Access Protocol) is a protocol that allows web services to communicate with one another. 

 

 

References

  1. http://msdn.microsoft.com/en-us/library/aa480021.aspx
  2. http://metallemon.hubpages.com/hub/Building-Service-Orientated-Architecture
  3. http://www.codeproject.com/Articles/515253/Service-Oriented-Architecture-and-WCF
  4. http://searchsoa.techtarget.com/definition/service-oriented-architecture
  5. http://www.indiawebdevelopers.com/resource_center/articles/soa.html



Both SOA and Web Service have same the mission? They Use each other ? Or what !?

once a dude asked me a question about differences between SOA and Web Services, now I list the whole features of them here.

SOA

  1. is a software design principle. 
  2. is an architecture and focuses on making different kinds of web services .
  3. is an architectural model for implementing loosely coupled service based applications.
  4. is used to integration of services.
  5. is often used to integrate multiple applications that use different platforms.

 

Web Service

  1.  define a web technology that can be used to build applications that can send /receive messages using SOAP over HTTP. 
  2.  is one of the ways you can implement SOA , it also used to implement REST and RPC Applications.
  3.  used to connect applications running on different platforms.
  4.  is just a realization of SOA.
  5.  is just a communication between two service.
  6.  is just a technology and implemented using a set of standards.



About Me

Ehsan Ghanbari

Hi! my name is Ehsan. I'm a developer, passionate technologist, and fan of clean code. I'm interested in enterprise and large-scale applications architecture and design patterns. I spend a lot of time on software architecture. Since 2008, I've been as a developer for different companies and organizations and I've been focusing on Microsoft ecosystem all the time. During the past years, Read More

Post Tags
Pending Blog Posts
using Elmah in asp.net MVC4
Using FluentSecurity in MVC
Strategic design
Factory Pattern
time out pattern in ajax
Redis as a cache server
How to use PagedList In asp.net MVC
Multiple submit buttons in asp.net MVC
Domain driven design VS model driven architecture
What's the DDD-lite?