Monday, April 27, 2009

Domain driven design in SOA application stack

Typical application design stack consists of the following
  • User Interface Controllers / Integration Layer / Process Layer
  • High Level Services Layer (Facades, Composite Services, etc)
  • Low Level Services Layer
  • Application Persistence Layer (custom DAOs or ORM framework)
  • Database Server

The domain layer cuts across all the above layers, domain objects are passed across interfaces spanning the layers
Cross cutting concerns like security and transactionality are ideally applied at the high level services layer

Ideally, where should the business logic related to an application reside?

The domain driven design camp seems to be perfectly convinced it should reside in the domain classes. They even go on to critisize applications that do not have business logic in the domain classes. Such a domain model which does not contain business logic but only contains data members and getters/ setters is often called an anaemic domain model.

The service driven design camp seems to think the best place for the business logic to reside is in the services, especially, the low level services. One argument in there favour stems from increasing usage of ORM frameworks like hibernate and JPA, which require persistent classes getting mapped to relational tables.In such cases, having a light domain model that can easily be recreated again and again from a tunable underlying database, seems to be advantageous

One of the reasons why domain driven camp, seems to want business logic in domain objects is that often in earlier frameworks like EJB 1.x and 2.x, the service layer had a coupling to technology, but with POJO based frameworks like Spring, EJB 3.1 etc, whether business logic resides in the service layer or the domain layer it is very much easily reusable due to it being in POJOs

The more important principle that is getting obscured in this domain-driven and service-driven business logic debate is that the design "needs to be able to capture business requirements, in appropriately designed Object Oriented abstractions". When going down the path of service based business logic, there is much more danger of falling into the procedural trap and designing business logic in terms of sequence of linearly executing steps. Low level service layer should have OO abstractions that deal with domain specific concepts, entities and operations

Conclusion:

Business logic can reside in domain layer and alternatively in the service layer as well. But special care needs to be taken in design for either case to ensure that business logic gets modelled keeping sound object oriented principles and best practices in mind.

Tuesday, April 14, 2009

Cloud Computing - relevance to enterprise applications

Some considerations for moving applications to the cloud:
  • Different applications in the enterprise have different scalability and load requirements
  • From a ROI perspective cloud based computing offers huge cost advantage only to applications which exhibit characteristics of extremely variable loads.
  • Specifically, applications for which the difference between peak load and average load or difference between average load and minimum load is very large, offer best ROI, when considered for cloud computing.
  • With cloud computing, pay-as-you-use economics, you don’t end up incurring huge up-front capital costs, nor do you have to buy hardware and software capacities that have to contend with rare peak loads say holiday season/year-end processing peaks
  • Also cloud computing is suitable for applications with requirements of extreme scalability
  • Cloud computing applications should be ready to contend with less than perfect reliability, say 99.5 % reliability, which may not be an option in some mission critical applications

Conclusion:

  • Not every enterprise application should be considered for being moved to the external cloud. For some applications, good old virtualization, within the realms of the organization, should give great enough value. This type of infrastructure is refered to by some vendors as internal cloud
  • New or existing enterprise applications can be architected for cloud computing depending on the application's suitability
  • Cloud computing can be used very effectively to complement existing intranet based enterprise applications

For a more graphical explanation please view the slide share presentation hosted on linked-in Cloud computing relevance to enterprise applications

Thursday, March 19, 2009

Desktop Virtualization Adoption issues

I think there is one major hurdle in the adoption of desktop virtualization on a massive scale. Even with desktop virtualization, thin clients will be needed for connecting to the virtual machines. Hardware cost of thin clients is far from negligible.

Consider what contemporary hardware could fit in as an affordable thin client. best I can come up with is either netbooks which are starting to cost under 400$ or maybe the most scaled down of desktops having say 512 MB RAM, 60 GB harddisks, but even these are not very cheap. Add to that full-blown operating systems like windows vista, which cost a bundle. The thin client cost can easily baloon upto 500$+ a piece. This can eat into the benefits of desktop virtualization. The OS problem is easily solved with linux, but hopefully in near future industry will make serious effort to provide scaled down thin client hardware which is very affordable (say under 100$)

If the thin client cost can be brought down, then the adoption of desktop virtualization will proportionally sky rocket.

The near future: Towards reducing the cost of thin client hardware most reports tell us that RAM, storage and chips are getting cheaper by the day and increasingly, the bottleneck in reducing cost for the thin client is the display technology. I dream of the day when, my laptop is as thin as can be and its LCD screen has been replaced by an small outlet for optical projection so that any flat surface can make do as a screen. Ah, but thats just wishful thinking for now...

Wednesday, January 14, 2009

Service Coupling - Service Interface evolution impact

Service providers should consider potential service consumer needs when coming up with service interfaces. However evolution of service interfaces is a fact of life we all have to contend with eventually. In an enterprise SOA, service providers and consumers are very much under enterprise SOA goverance and there are specific things which can be done, to minimize the pain of service consumers having to change with evolving service interfaces. Let us consider this problem through the example of the following Employee Information Service which has the following interface
public interface EmployeeInformationService {
    List getEmployeeInformation(Employee request);
}

class Employee {
    private long id;
    private String name;
    ...
    ...
}


1. A key thing in above interface is that the employee service's domain class Employee is exposed to consumers. To avoid this it would be desirable to wrap up the class in service integration abstractions like EmployeeInformationRequest and EmployeeInformationResponse

public interface EmployeeInformationService {
    EmployeeInformationResponse getEmployeeInformation(EmployeeInformationRequest r);
}

class EmployeeInformationRequest {
    private long requestId
    private String requestStatus;
    private Employee employee;
    ....
}

class EmployeeInformationResponse {
    private long responseId
    private String responseStatus;
    private List employee;
}



2. Even on the service consumer end, coupling between the service interface and the consumer's application logic can be greatly minimized using a consumer specific ServiceClient interface. In addition a object mapping tool such as dozer can be used to map attributes between consumer classes and service classes, declaratively. More about dozer


3. A key thing about reducing coupling is not the mere use of above abstractions but rather a conscious use of only the bare minimum, functionally necessary service interface attributes in the consumer. This judicious neglect of unrequired service object attributes by a consumer is what increases the consumers resilence to changes in service interface

For example if the Employee class in service interface contains 20 atttributes but our consumer needs to know only about 4 attributes then the consumer side classes should be aware of only 4 Employee attributes and mappings to translate to and from equivalent Employee attributes

The whole idea being that if Employee existing attributes were changed or deleted in the provider, unless the same were being used by our consumer, our consumer would be unaffected by the change.

Summary: Often in SOA implementation, providers communicate through XML messages and expose XSD schemas for message structures. This is equally applicable for SOAP based or Plain Old XML(POX) message exchanges. Here consumers often imnport the entire XSDs exposed by the provider and also do XSD based validations.

These consumers needlessly couple themselves to provider interface, instead consumers should do "just enough" validations and also "be aware of" minimum information being sent by the provider.This will go a long way in promoting reduced coupling between providers and consumers, and will allow provider interfaces to evolve with minimal impact on consumers