title: SOA: Libraries vs Services: Can a library be a better option?
body: <p>I work with WCF 4.0 and have a good idea of how to build services from a technical standpoint. I have been working now with WCF for 3 years now.</p>
  
  <p>Despite this I and others I talk to have different ideas about what should be the unit of software that makes up a service and what should not. Many people I talk to believe that services should be granular. Indeed my previous company has spent alot of time turning some of their Assemblys into Services (so I have been told).</p>
  
  <p>In many instances I can't see how a service is better...and maybe it's not always supposed to be. I'll give you an example: In our system we have a large service that really has grown to perform two different independant jobs. I am going to split it into two services for two reasons: performance and fault isolation (we self host in a Windows Service, no IIS). The thing is, despite serving two independant business processes (one service can be down without affecting the other), both have a fair chunk of common business logic.</p>
  
  <p>Now some advise me that this common logic should be seperated into a 3rd service under SOA principals and be consumed by the two newly split services. As I see it, this just partially undoes the benefit of spliting the big service in the first place: we have introduced a performance bottleneck and single point of failure. If the host process of the 3rd service goes down, 1 and 2 can no longer do their work. This happens to us now where we have a "deep" structure of many services. One goes out and any dependant services up the chain timeout as their calls are never answered.</p>
  
  <p>Now if the common logic was just a library rather than a service we get the benefit of code reuse, no performance bottleneck and fault isolation as each service is executing its own copy of the assembly in its own memory. Also there is no serialisation overhead.</p>
  
  <p>What are peoples thoughts on this? Is there a rule or general guideline when it comes to deciding when something should be a service or a library? Any other advice?</p>
  
  <p>Thanks
  Michael</p>