Speech Title Here

Speech Title Here

Patterns for Service-Oriented Architecture Ramkumar Kothandaraman Architect Advisor Microsoft Corporation Agenda Introduction to SOA Four Tenets Review Anti-Patterns CRUDy Interface Loosey-Goosey Patterns Document Processor Extensible Schema

Idempotent Messages Reservation Summary Patterns and Practices Proven practices for predictable results Available online: Books available: http://www.microsoft.com/practices http://www.amazon.com/practices Architecture & Design Guides

Patterns Application Blocks & Libraries Baseline Architectures System-Level System-Level Architectures Architectures Known Known solutions solutions

to to recurring recurring problems problems Code Code abstractions abstractions with with guidance guidance Durable Durable starting starting points

points to to begin begin development development D D A D I A D I

A D I A D I D A D

I D A A D D I I E

Engineering Practices Guidance Guidance for for tasks tasks such such as as security, security, performance, performance, test, test, deployment deployment and and operations operations A

D I Service-Oriented Architecture 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 Made Easy out b a t Wha hing cac nce re refe a? dat I do data w r

Ho e fo cy? id ten v s o pr onsi c atterns p t a h W ild my u b

o t help SOA? Billing I do e w Ho anag cies m den n n e pe twe s? e d be ice rv

se Repair Service ut o b at a ate h W plic ? du ages ss me t

ou b t a ty? a Wh curi se Business Processes How d han o I dl exc epti e ons ?

H int ow d C erfa o I oa ce de rse s t sig Gr hat n ain areCustomer ed ? How do I loc achie Ho ve tran atio

wd spa n o ac ren cy? per cept I get for able ma n ce ? What about Reliable Messaging? Payments

Four Tenets of Service Orientation Boundaries Are Explicit Services Are Autonomous Services Share Schema and Contract, not Class Service Compatibility Is Determined by Policy Anti-Pattern: CRUDy interface How do you design SOA services with .NET? Anti-Pattern:

CRUDy interface (contd) Context You have now been asked to design Web services for your new company SOA project Problem How do you design SOA services with .NET? Forces You have been a developer since the 80s and you know how to create components This is your first SOA project Your organization expects that other platform applications will consume your project Anti-Pattern: CRUDy interface (contd) Solution

You design your service interface just like you designed previous component interfaces You create a service which implements the C.R.U.D. operations Symptoms & Consequences Your interface design tends to encourage RPC-like behavior Your interface may imply stateful interactions, like enumeration Interface is likely to be overly chatty Anti-Pattern: CRUDy interface (contd) _ Public Sub Create( ByVal CompanyName As String, ByVal ContactName As String, ByVal ContactTitle As

String, ByVal Address As String, ByVal City As String, ByVal State As String, ByVal Zip As String, ByVal Country As String, ByVal Telephone As String, ByVal Fax As String) End Sub Using a sub means that the sender will have no idea if the operation succeeds or fails Ask: What does the sender need to know? This method encourages an RPC centric style of development The schema is implied from the method signature including an empty response CRUD operations may be the wrong factoring Anti-Pattern:

CRUDy interface (contd) _ Public Function MoveNext() As Boolean End Function _ Public Function Current() As Object End Function Enumeration over a list held at the server implies a stateful conversation Using abstract types weakens the contract Anti-Pattern: CRUDy interface (contd)

_ Public Sub UpdateContactName( ByVal NewName as String) End Sub _ Public Function CommitChanges() End Function Methods which leave data in an inconsistent state Operations which require multiple messages to complete are dangerous Anti-Pattern: Loosey-goosey How do I factor my service so that it is

flexible and highly adaptable? Anti-Pattern: Loosey-goosey (contd) Context You are building a service-based application You are designing your service interfaces Problem How do you factor your service interfaces so that the interface is flexible and extensible? Forces You are planning to provide integration points at all levels of the app Other teams are asking for access to your database

Anti-Pattern: Loosey goosey (contd) _ Public Function QueryDatabase( ByVal Database as String, SQLQuery as string) As DataSet _ Public Function Execute( ByVal Command as Integer, Arguments as string) As Boolean Solution Provide Data Tier interfaces Provide Extensible late bound interfaces What is the contract here? Anti-Pattern:

Loosey goosey (contd) Symptoms & Consequences Consumers build implicit dependencies on the semantic implementation of your service Results in a tight coupling The contract does not give you enough information to use the service Hint: If you have to read something else to consume the code your service factoring may be incorrect Performance suffers as you cross many boundaries between tiers within the same app

Pattern: Document processor How do you create a simple to use, well defined interface? Document Processor Context You are building a Web service Problem How do you create a simple to use, well defined interface? Forces Your 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 Solution: Document Processor public FindCustomerByCountryResponse FindCustomersByCountry( FindCustomerByCountryRequest request) { // Do something.... } 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 Great new tool XSD Object Code Generator http://apps.gotdotnet.com/xmltools/xsdobjgen/default.htm Remember this is a boundary, so dont leak internals Solution: Document Processor (contd) Your service should encapsulate a complete unit of work Under no circumstances should a failure leave your service in an incomplete state You cannot count on the sender to call another service to fix things What about transactions?

Dont share distributed transactions Compensation is OK, but dont count on the consumer to do it Reservation pattern provides the most autonomous protection Dont Leak Internal Abstractions Start With Schema Generate Data Transfer Objects Transition at the boundary Avoid Implicit Assumptions Resulting Context

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 Document Processor Demo

Pattern: Extensible Schema How do you define extensible schema that can be versioned? DEMO Extensible Schema Pattern: Idempotent Message How do I handle duplicate messages received at my service? Pattern: Idempotent Message 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 Solution: Idempotent Message 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? Option #1 - Return a cached response 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? Service Service Service Consumer

Service caches Consumer Service finds sends invokes response response checks sends message business abefore cache in duplicate

with cache logic -UOW sending not and ID: message components found returns 123 to consumer for it order A

UOW: 123 Order: A Option #2 Process the message again Probably harmless for read operations May be disastrous for write operations What if the message was withdraw $1000 from checking What if the first message resulted in an error of some kind? Processing the message again will likely result in the same error Beware the poison message loop Error! Option #3 Throw an exception

Sender may not have received the original response How can they obtain it if you do this? ServiceService cachesService checks then Consumer sends invokes cache, Consumer Service response retries finds business

sends checks duplicate buta logic original an message cache error request components and prevents returns error transmission Error!

Error! Solution: Idempotent Message 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 Pattern: Idempotent Message Benefits Your service autonomy is increased by not having to rely on consumer to do the right thing You wont 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

Pattern: Reservation How do you maintain data consistency across a long running process? Pattern: Reservation (contd) 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 Solution: Reservation (contd) Messages create tentative operations Each operation is atomic and leaves the database in a consistent state Consider All Possible Outcomes Operation confirmed (by completing message exchange) Operation cancelled (implicitly or explicitly) Timeout (message exchange did not complete on time)

You must define a dialog Dialogs define the expected flow of the conversation You will need state to remember the place you left off in the conversation Solution: Reservation (contd) Reserve part: 49389 Qty: 200 Reservation ID: 14432 Expires: 2004-09-15 02:43:53Z Confirm reservation: 14432

PO #49839 Reservation: 14432 Receipt: 29389 PO #49839 Resulting Context: Reservation Benefits Consistency of data lies entirely with the service and its business rules Deals with failures (timeouts, lost communication) in a predictable way Liabilities You must define business rules for the reservation (will you overbook?) Isolation of work in progress is not

automatic as it is with 2PC transactions Summary The Four Tenets are high-order principles that inform our design thinking Service Factoring Model business processes driven by business documents Dont try to be to extensible or flexible Autonomy Dont count on the consumer for anything Expect consumers will make mistakes when using your service Never leave your service in an inconsistent state Resources

Patterns and Practices: http:// msdn.microsoft.com/practices My home page : http://www.ronjacobs.com Patterns: http://www.patternshare.org Global Bank Community http://workspaces.gotdotnet.com/gbi Your Feedback is Important! Please Fill Out a Survey for This Session on CommNet 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

Recently Viewed Presentations

  • Pierre Bourdieu, Distinction: A Social Critique of the

    Pierre Bourdieu, Distinction: A Social Critique of the

    If the world of action is nothing other than this universe of interchangeable possibles, entirely dependent on the decrees of the consciousness which creates it and hence totally devoid of objectivity, if it is moving because the subject chooses to...
  • Parliamo un po l'italiano

    Parliamo un po l'italiano

    Presentarsiper cortesia. Buongiorno. Sono… E tu comé ti chiami ? Mi chiamo… Ciao ci . vediamo. Arrivederci. Buongiorno. Buona. sera
  • Greece and Rome - White Plains Middle School

    Greece and Rome - White Plains Middle School

    The Empires of Greece, Macedonia, and Rome developed strong navies for the purpose of collecting tariffs, establish their dominance and balancing their budgets to maintain empire. While state-sponsorship of belief systems helped to maintain the status quo, the appeal of...
  • The Natural Base e - Alabama School of Fine Arts

    The Natural Base e - Alabama School of Fine Arts

    The Natural Base e A famous constant (similar to π) is the natural base, e (also known as Euler's number). e ≈ 2.718281828459… e is irrational (non-repeating, not-terminating). A function in the form f(x) = aebx is a natural base...
  • Pwy yw'r ditectif? - Dysgu Cymraeg

    Pwy yw'r ditectif? - Dysgu Cymraeg

    Sherlock a Dr Watson. Dr John Watson. Sherlock Holmes. Nôl. Pa un yw pa un? Ant a Dec. Anthony McPartlin. Declan Donnelly. Nôl. Pa un yw pa un? Mulder & Scully. Fox Mulder. ... Tess a Claudia. ClaudiaWinlkeman. TessDaly. Nôl....
  • Age-grading and vowel systems in Multicultural London English

    Age-grading and vowel systems in Multicultural London English

    Sociohistorical context of Multicultural London English. High in-migration of population originating from countries other than the UK from 1950s onwards. Poverty - Hackney has the . highest rating on indicators of deprivation out of all 355 boroughs .
  • WP _ Barriers, RTD Goals and Jointly Executed Research

    WP _ Barriers, RTD Goals and Jointly Executed Research

    Economic aspects of willow growing in Sweden Håkan Rosenqvist, SLU Sweden Thanks to different EU projects, SLF and Värmeforsk for funding
  • Environmental Data Analysis with MatLab Lecture 18: Cross-correlation

    Environmental Data Analysis with MatLab Lecture 18: Cross-correlation

    Point out that the time series must be stationary for the covariance to depend only on the lag. this defines the cross-correlation. ... for both u and v, you get the rules that we worked out previously for the autocorrelation.