patterns&antipatternsof soa

53
Patterns and anti- patterns of SOA Presented by: Mohamed R. Samy Technical Architect, MVP

Upload: mohamed-samy

Post on 17-May-2015

1.110 views

Category:

Technology


0 download

DESCRIPTION

This is a talk I gave on patterns and antipatterns of SOA, based on my understandings and practices and inspired by Ron Jacobs famous webcast by the same name.

TRANSCRIPT

Page 1: Patterns&Antipatternsof SOA

Patterns and anti-patterns of SOA

Presented by:Mohamed R. Samy

Technical Architect, MVP

Page 2: Patterns&Antipatternsof SOA

What is Architecture anyway? The software architecture of a program

or computing system is the structure or structures of the system, which comprise software components, the externally visible properties of those components, and the relationships between them. The term also refers to documentation of a system's software architecture. Reference: Wikipedia

What is an architectural style?

Introduction

Page 3: Patterns&Antipatternsof SOA

Architectural Styles

Page 4: Patterns&Antipatternsof SOA

What is an architectures’ goal? So what is SOA?

◦ A style of architecture that emphasizes standards based integration.

Is it the best way? Is success guaranteed?

Introduction contd.

Page 5: Patterns&Antipatternsof SOA

Standards based integration

Friction free interaction/Integration

Communication between system components

The Goal of SOA

Page 6: Patterns&Antipatternsof SOA

Should loose coupling be everywhere?

Implicit behaviour vs. Explicit behaviour

Services as an interface to business processes.

(That is how we should think about a service when we design it)

The Hype

Page 7: Patterns&Antipatternsof SOA

Boundaries are explicit

Services are autonomous

Services share contract and policy not class

Service compatibility is determined by policy

The four Tenets of SOA

Page 8: Patterns&Antipatternsof SOA

Borders are Explicit

Page 9: Patterns&Antipatternsof SOA

2 Tier (VB4-5-6) vs 3-Tier Com+ (Client in Egypt, Service in Mexico) In the architecture you have to know where

the boundaries are. Practical Example:

◦ Egypt/ Libyan Border vs. Cairo/ Alex◦ Their system vs Our system (A boundary)

Lessons learned:◦ Authentication, Authorization◦ Communication overhead

TENET I :Boundaries are Explicit

Page 10: Patterns&Antipatternsof SOA

Services are Autonomous

Page 11: Patterns&Antipatternsof SOA

Able to choose Self Governing Self sufficient Fax /Telephone between ministries When the computer is down, I can still get

my license (Send it later by the mail)

TENET II: Services are Autonomous

Page 12: Patterns&Antipatternsof SOA

Services Share Schema and Contract not Class

Page 13: Patterns&Antipatternsof SOA

XML not objects, specially not platform specific objects e.g. datasets

We need to agree on 2 things:◦ The protocol◦ The policy

Just what is required for the service to perform it’s function (Just enough validation)

TENET III:Services Share Contract and Policy not Class

Page 14: Patterns&Antipatternsof SOA

IT department Policy like language of the system (Arabic –

Russian – English) Policy like http/XML/SSL ports The requirements for the way the

conversation is to be held E.g. WS- standards (Message encryption,

which parts are encrypted, what algorithm we will use to encrypt)

TENET IV: Service Compatibility is determined by Policy

Page 15: Patterns&Antipatternsof SOA

To understand the patterns we must take a look at the most common anti-patterns

Patterns/Antipatterns of SOA

Page 16: Patterns&Antipatternsof SOA

Customer. ADD/Update/ Delete Why not?

◦ Is updating the address just an update or is it a business process?

CRUDY interface

Page 17: Patterns&Antipatternsof SOA

CustomersList.MoveNext◦ Who holds the list?◦ Who controls the memory?

Enumeration

Page 18: Patterns&Antipatternsof SOA

1.CustomerObject.Setflagfordelete2.CustomerObject. Delete

Objects should not be left in an inconsistent state between message exchanges.

However, this is dangerous but not wrong.

Chatty Interface

Page 19: Patterns&Antipatternsof SOA

The perfect interface for all services:XmlDocument

PerformOperation(XmlDocument input) Why not? Implicit behavior versus explicit

behavior. You need to know what you send specifically

and be generic about what you receive (Just enough validation.)

Loosey Goosey

Page 20: Patterns&Antipatternsof SOA

To avoid this anti pattern ask 3 questions:1.What does the service do? 2. What data does it need to do it?3. What data does the service return?

Loosey Goosey contd.

Page 21: Patterns&Antipatternsof SOA

A flag called “zeft”, “mido” , “soso” A house of cards

Why implicit behavior is bad

Page 22: Patterns&Antipatternsof SOA

What if the service schema changes? What happens to the connected systems?

Versioning contracts in .NET1.1 vs .NET2.0[OptionalField VersionAdded = 2]Nickname

Why is that important?

Just Enough Validation

Page 23: Patterns&Antipatternsof SOA

The patterns

Patterns and Anti Patterns- Part2

Page 24: Patterns&Antipatternsof SOA

Patterns◦ Document Processor◦ Idempotent Message◦ Reservation

Some important SOA patterns

Page 25: Patterns&Antipatternsof SOA

An architectural approach to creating systems built from autonomous services◦ Integration as a fore-thought rather than an after-

thought A service is a program you interact with via

message exchanges◦ Services are built to last◦ Availability and stability are critical

A system is a set of deployed services cooperating in a given task◦ Systems are built to change◦ Adapt to new services after deployment

SOA

Page 26: Patterns&Antipatternsof SOA

How do you create a simple to use, well defined an interface?

Pattern1: Document Processor

Page 27: Patterns&Antipatternsof SOA

Changing your drivers license, Giza Authority for Traffic

Real world examples

Page 28: Patterns&Antipatternsof SOA

1. Start with a process

2. Compose a workflow

3. Start Defining your message contracts, before your objects and entities(try to be atomic- avoid chatty interface)

4.Define operations

Where to start

Page 29: Patterns&Antipatternsof SOA

5. Group your operations into services

Tips: 1. Do not use platform specific types e.g. datasets.

2. Decouple Internal vs. External objects

3. Use TDD so you know you are thinking about the service consumer, now you know how it feels.

Where to start contd.

Page 30: Patterns&Antipatternsof SOA

Context You are building a web service

Problem How do you create a simple to use, well defined an

interface?

ForcesYour interface should Encourage document centric thinking Define a clear semantic in the contract Promote loose coupling through encapsulation of the

implementation Be easy to consume from any platform (WS-I base profile) Represent a business process as a complete unit of work

Pattern1: Document Processor

Page 31: Patterns&Antipatternsof SOA

Solution: Document Processor

-Encourage document centric thinking by defining a schema (XSD) for request and response messages in your project

-Generate objects from your schema to simplify development

-Remember this is a boundary so don’t leak internals

public FindCustomerByCountryResponseFindCustomersByCountry(

FindCustomerByCountryRequest request){

// Do something....}

Page 32: Patterns&Antipatternsof SOA

Do not leak internal abstractions

Page 33: Patterns&Antipatternsof SOA

Generate Data transfer objects

Page 34: Patterns&Antipatternsof SOA

Transition at the boundary

Page 35: Patterns&Antipatternsof SOA

Benefits Consumers think about sending and receiving business

documents which are naturally more granular The boundary of the system involves conversion from

internal structures to external documents The implementation details of the system are encapsulated The service is more consumable from other platforms and

can evolve more easily

Liabilities Performance will suffer with transfers of data from internal

to external structures

Resulting context

Page 36: Patterns&Antipatternsof SOA

Should I use the same schema for multiple services or should each service have its own schema?

Opinion: Give each service its own schema◦ Sharing schema makes it difficult to evolve each

service independently and introduces unnecessary churn for service consumers

Design Question

Page 37: Patterns&Antipatternsof SOA

How do I handle duplicate messages received at my service?

Pattern2: Idempotent Message

Page 38: Patterns&Antipatternsof SOA

Context You are developing a web service for your SOA You heard that messages should be idempotent

Problem How do you insure that messages are idempotent?

Forces You cannot expect anything more from the sender than

what the contract defines for your service You are working with a transactional database system with

frequent updates

Indempotent messages

Page 39: Patterns&Antipatternsof SOA

Sender tags message with a request ID◦ Your contract can specify that this is required◦ Your contract cannot insist that the ID is unique across

time◦ The ID tags a unit of work which will be done only once

Receiver must check to see if the unit of work has already been done before doing it◦ Then what?

Solution

Page 40: Patterns&Antipatternsof SOA

Option1: return a cached response

Option2: Process the message again.

Option3: Throw an exception

Solution Options

Page 41: Patterns&Antipatternsof SOA

You will have to cache responses for some period of time – how long?

What if the current value is different than the cached value?

What if the response was an error?

What if the sender sends duplicate IDs for different units of work?

Option1: Return a cached response

Page 42: Patterns&Antipatternsof SOA

Great for reads, what about writes?

Should we withdraw $1000 from a checking account twice?

Option2: Process the message again

Page 43: Patterns&Antipatternsof SOA

Did the sender get the original response?

How does he get the original response if you are sending him and exception?

Option 3: Throw and exception

Page 44: Patterns&Antipatternsof SOA

UOW ID can be a part of the request schema◦ Implies duplicate handling is part of the business process

UOW ID can be a custom SOAP header◦ Implies duplicate handling is part of the message processing

infrastructure◦ Create a schema for the SOAP header◦ Having a URI for immediate sender can be helpful to detect

reentrancy

Data changes should be traceable to a UOW ID

Your cached responses may need to reflect what the response was at the time when the request was received

Solutions

Page 45: Patterns&Antipatternsof SOA

Benefits Your service autonomy is increased by not having to rely on

consumer to do the right thing You won’t fool yourself into thinking that reliable messaging will

solve this problem

Liabilities Your service will consume potentially large amounts of durable

storage caching responses Your service will take a performance hit for cache management

Pattern3: Indempotent message

Page 46: Patterns&Antipatternsof SOA

How do you maintain data consistency across a long running process?

Pattern3: Reservation Pattern

Page 47: Patterns&Antipatternsof SOA

Context You are building a service oriented application You have a complex business process that you want to

expose to your customers with a web service

Problem How do you maintain data consistency across a long

running process?

Forces You cannot share a distributed transaction The business process requires several messages to

complete The message exchange process could take anywhere from

seconds to hours

Reservation pattern

Page 48: Patterns&Antipatternsof SOA

Reservation pattern illustrated

Reserve part: 49389Qty: 200

Reservation ID: 14432Expires: 2004-09-15 02:43:53Z

Confirm reservation: 14432 PO #49839

Reservation: 14432Receipt: 29389PO #49839

Page 49: Patterns&Antipatternsof SOA

Know the concepts before you write the code

SOA is not web services

SOA is about standards based integration and friction free interaction between systems

SOA is not a silver bullet

Summary

Page 50: Patterns&Antipatternsof SOA

Web services WCF Biztalk ESB

SOA Technologies

Page 51: Patterns&Antipatternsof SOA

www.arcast.tv (Webcasts)

www.geekswithblogs.net/Mohamed (Cool tech blog)

www.msdn.com/Architecture

www.thevstsguy.com (under construction)

www.msdn.microsoft.com/practices (P&P)

References:

Page 52: Patterns&Antipatternsof SOA

Email: [email protected] Facebook @msamy

Contacts

Page 53: Patterns&Antipatternsof SOA

Questions?