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:


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 the server is offline". It's an amazing feature, suppose that a client makes a request, what will happen if the server is inaccessible? With nServiceBus and its asynchronous fire & forget the 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, the package will take care of the configuration for you. Your App.config should be something like this:


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


   public class Messaging : IMessage
        public string Message { get; set; }


Now create the SendMessage class with like this:


   public class SendingMessage
        public IBus Bus { get; set; }
        public void Run()
            Bus.SendLocal<Messaging>(m => m.Message = "nServiceBus message");


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:


    public class CommandHandler : IHandleMessages<Messaging>
        private readonly IBus _bus;

        public CommandHandler(IBus bus)
            _bus = bus;

        public void Handle(Messaging message)
            throw new NotImplementedException();


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 the 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 the 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 run independently of any specific technologies. SOA is directly built upon the principle of service-orientation, which talks about services with a simple interface that can be accessed independently by users without worrying about the actual platform implementation of the 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 another service, Not affect other services, secure, communicate with each other synchronously.



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 the 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 makes a service request and in response gets the Service Response. it's better to separate the messaging and interfaces of service to separate layers.




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. 





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

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


  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 the 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 services.
  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 and I'm spending a lot of my time on architecture subject. Since 2008, I've been as a developer for companies and organizations and I've been focusing on Microsoft ecosystem all the time. During the&nb Read More

Post Tags
Pending Blog Posts
Strategic design
Factory Pattern
time out pattern in ajax
Selectors in Jquery
Peridic pattern
How to query over Icollection<> of a type with linq
How to use PagedList In MVC
Domain driven design VS model driven architecture
What's the DDD-lite?
Using Generic type for type casting in F#