32
DEV387 Layers, Tiers & Services Clemens Vasters ([email protected]) newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp.

DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

Embed Size (px)

DESCRIPTION

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved This Talk Layers Organizing code Tiers Distributing Layers Contracts The only way to talk

Citation preview

Page 1: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

DEV387Layers, Tiers & ServicesClemens Vasters([email protected])newtelligence AG

Co-Author: Steve Swartz, Architect, Microsoft Corp.

Page 2: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

This Talk

LayersOrganizing code

TiersDistributing Layers

ContractsThe only way to talk

Page 3: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Before we begin…

Service: You’ve heard the word too oftenWindows ServicesEnterprise ServicesWeb ServicesSystem Services

No wonder everything’s a service….

Page 4: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

LayersOrganizing code.

Page 5: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Layers: Basic thoughts

"Code is lazy and ticklish"

Just takes up memory when not triggeredThere are things that trigger your code

Presentation Events HTML, GUI, Web Services, Pipes, Queues, RPC, …

System Events Timers, OS Wait Objects, Alerts, …

There are things that your code triggersWeb Services, Databases, Queues, RPC, …

Page 6: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Layers: Considerations

Stuff that triggers your code:Many different incoming channels

Differ by technology, invocation style, etc.

Must scale on time axisExpect frequent changes, expect “more"

Stuff that you doStuff that you trigger

In the end, you need to call some APICan use factories, abstractions, but …… in the end you will do a tightly bound call

Page 7: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

DataData

PresentationPresentation

Layers!

SQLSQL MQMQ WSWS XSDXSD RPCRPC

PublicInterface

Services &ResourceAccess

InternalImplemen-

tation

XMLXMLHTMLHTML GUIGUI EDIEDI COMCOM

DataData

PresentationPresentation

LooserLooserCouplingCoupling

TighterTighterCouplingCoupling

Page 8: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Layers: Rationale

Only (and sufficient) rationale for layers:Resilience against changes in code!

Presentation LayersLots of changes, very frequentlyNew GIFs, new buttons, new schemasEach change has low impact, but work adds up Design to be flexible and to "expect more"

Data LayersFewer changes, rather infrequentlyMassive impact, often wholesale rewrites Design to optimize data access

Page 9: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Business Logic

Do you ever say: “Today I’ll sit down and write Business Logic“ ?

In fact, you usually implement “use-cases”.Public interface, resource access and …all the stuff between stuff that you trigger and stuff that triggers you

“Business logic” is the code that …… will remain valid for any presentation… will remain valid for any data store

Page 10: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Contracts: Promises and Trust

Contracts between layers …Are promises and guarantees to deliver stuff (and how)Are promises and guarantees to accept stuff (and how)

Contract parts in Web ServicesXSD: Data typesWSDL/XSD: MessagesWSDL/BPEL4WS: Message exchange patternsWS-Policy: Quality of service rules and req’s

Contract parts in COM+IDL: Data types, messages, exchange patternsConfig/Negotiation: Quality of service rules and req’s

Page 11: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Resource Access

Dumb Resource AccessPass-through gateway from logic to resources

Queues, Data Stores, Services, Hardware

Smart Resource AccessDealing with data and resources in clever ways

Very Smart Resource AccessHaving others deal with data in clever ways

Page 12: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Layout Basics: Adding some color to data

Categories

PK CategoryID

I1 CategoryNameDescriptionPicture

Employees

PK EmployeeID

I1 LastNameFirstNameTitleTitleOfCourtesyBirthDateHireDateAddressCityRegion

I2 PostalCodeCountryHomePhoneExtensionPhotoNotes

FK1 ReportsToPhotoPath

Territories

PK TerritoryID

TerritoryDescriptionFK1 RegionID

Orders

PK OrderID

FK1,I1,I2 CustomerIDFK2,I4,I3 EmployeeIDI5 OrderDate

RequiredDateI6 ShippedDateFK3,I7 ShipVia

FreightShipNameShipAddressShipCityShipRegion

I8 ShipPostalCodeShipCountry

Suppliers

PK SupplierID

I1 CompanyNameContactNameContactTitleAddressCityRegion

I2 PostalCodeCountryPhoneFaxHomePage

Customers

PK CustomerID

I2 CompanyNameContactNameContactTitleAddress

I1 CityI4 RegionI3 PostalCode

CountryPhoneFax

Shippers

PK ShipperID

CompanyNamePhone

Order Details

PK,FK1,I2,I1 OrderIDPK,FK2,I4,I3 ProductID

UnitPriceQuantityDiscount

Region

PK RegionID

RegionDescription

Products

PK ProductID

I3 ProductNameFK2,I5,I4 SupplierIDFK1,I2,I1 CategoryID

QuantityPerUnitUnitPriceUnitsInStockUnitsOnOrderReorderLevelDiscontinued

EmployeeTerritories

PK,FK1 EmployeeIDPK,FK2 TerritoryID

almost never hardly ever time to time pretty often

Static Near Static Dynamic Hot

Updating Northwind …

Page 13: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Dealing with data in semi-smart ways

Static dataKeep a local copy, hang on to it in memory, don’t worry about ACID and never JOIN.

Near static dataKeep a local copy, hang on to it in memory, lazily check for updates and never JOIN.

Dynamic dataWork on local copy, cache carefully, use optimistic locking and JOIN.

Hot dataInsert is better than update. No touch without ACID. Transactions are your friend.

Page 14: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Consequences …

Data “character” influences resource accessTreating all data alike isn’t goodCaching data is the smarter choiceHanding this work off to a service is very smart

This leads us to the “macro layer” model … Presentation Services Business Services and Process Choreography Data Services

Page 15: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Orderly Chaos and Macro Layers

“The galaxy is on Orion’s belt”

How chaos theory and “self-similarity”

are relevant to layers …

DataServices

BusinessServices

Presentation

Services

Layering is a recursive pattern

• Layers may be layered Services are layers

• Data Services• Presentation Services• Business Services

Layers aggregate services

Page 16: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

TiersDistributing layers and dealing with boundaries.

Page 17: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Tiers: Basic Thoughts

Layers are about organizing code and dataTiers are about distributing code and data

Tier boundary most often is a process boundaryOn same machine, across machinesIn same organization, across organizationsIn trusted environment, across trust boundaries

Tier boundaries almost always cut layersCuts typically separate “yours” and “theirs”Ex: “Your” ASP.NET code and “their” browserEx: “Your” ADO.NET code and “their” DB2

Page 18: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Shape: Fat vs. Thin

“Thin” TiersTypically implement only parts of layers

Web Browser provides client portion of an interactive Web user-interface layerWindows Forms may provide client portion of a GUI/Web services user-interface layer

“Fat” TiersImplement full or even multiple layers

“Classic” Client/Server typically implements desktop application with tier boundary through data layer – connecting to remote RDBMS

Page 19: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Locality: Far vs. Near vs. Local

Local TiersSeparated by logical or actual (process) boundary on local machine.

Logical means: InProc/OutProc via config / no recompileMandates dynamic loading, factories and activators

Local Tiers never become “Near” or “Far”Near Tiers

Separated by actual process boundary across machines, inside trust domain and “local network”Never become “Far”

Far TiersSeparated by trust, ownership and (possibly) oceansMay be “connected” or “disconnected”

Page 20: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Boundaries

MSDEMSDE

GUIGUI

SQLSQL

GUIGUI

SQLSQL

HTMLHTML

IIS

SQLSQL

HTMLHTML

IIS

GUIGUI

“Client App” with DBTier boundary typically through data layer

“Web App” with ASPTier boundary through presentation layer

“Distributed App”Tier boundaries through pres. & data layers

“Desktop App”: Monolithic

No tier boundaries, but still layered

Page 21: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Boundaries through layers ..… result in more layers

You need to design cut points inside layersDesign choices are – above everything else – influenced by tier shape and locality

Local: “OO”-style; Classes and ObjectsGroup Ownership, Inheritance, Synchronous

Near: RPC-style; Components and InterfacesOrg. Ownership, Aggregation, Sync/Async

Far: Message-style; Services and EndpointsDistrib. Ownership, Aggregation, Asynch

Page 22: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

“Middle Tier” and BoundariesSo… what’s the so-called “Middle Tier” ?

It’s simply your code! Stuff that does work between the boundariesNow, your stuff is already difficult enough to do!

It’s even more difficult to … Build boundariesShield boundariesCross boundariesMaintain context across boundariesManage resources across boundaries

A layer thing, really!

Page 23: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Ways of crossing boundaries

Request/Response

One-Way

Dialog

Page 24: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Workflow-style interaction

Dialog

Dialog

Request/Response

Dialog

Windows J2EE

WindowsCICS

Page 25: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Ways of crossing boundaries

One Way:Events, Notifications, Batch JobsNo reply expected or no way to handle them“Peace of mind” through reliable messaging

Request/ResponseWeb-style interaction, RPCVery rapid response expected (< 3 sec)Client can’t proceed in any way without reply

DialogRelaxed 2-way conversation between endpointsThe good of “One Way” paired with backchannel

Page 26: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Contract StylesRPC Contract Schema Contract

Dialog Contract

•“Method Calls”•Request/Response•Typically synchronous•Typically map 1:1

•Interface ↔ Impl.

•“Messages”•Messaging•Synchronous & asynchronous•Multiple schema variants

one endpoint

•“Messages”•Messaging Conversations•Asynchronous•Multiple schema variants

one endpoint

“Come back when you’re ready” instead of request/response

Page 27: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

The Endgame: Service Orientation

Services as “Yellow APIs”Contracts everywhere

Metadata contractsAddressing contractsQuality of service contractsSecurity contractsMessage exchange contractsMessage contracts (or explicit absence <any/>)

Common understanding of metadataWell understood and agreed behaviorCode, platform, location become irrelevant

Page 28: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Infrastructure PiecesRegistry(UDDI)

CustomerModule

Router

OrdersModule

EndpointAddress

ServicePolicy

XSDWSDLMEP

ShippingModule

EndpointAddress

ServicePolicy

XSDWSDLMEP

Taxo-nomy

ShippingModule

EndpointAddress

ServicePolicy

XSDWSDLMEP

ShippingModule

EndpointAddress

ServicePolicy

XSDWSDLMEP

EndpointAddress

ServicePolicy

XSDWSDLMEP

XSDWSDLMEP

Page 29: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Summary

Lots about layersLots about tiersLots about contracts

Bottom line: Cutting big things into small pieces is a very good thing!

Page 30: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

Community Resources

Community Resourceshttp://www.microsoft.com/communities/default.mspx

Most Valuable Professional (MVP)http://www.mvp.support.microsoft.com/

NewsgroupsConverse online with Microsoft Newsgroups, including Worldwidehttp://www.microsoft.com/communities/newsgroups/default.mspx

User GroupsMeet and learn with your peershttp://www.microsoft.com/communities/usergroups/default.mspx

Page 31: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 newtelligence Aktiengesellschaft, Microsoft Corporation – No unauthorized reproduction or distribution permitted. All rights reserved

evaluationsevaluations

Page 32: DEV387 Layers, Tiers & Services Clemens Vasters ( newtelligence AG Co-Author: Steve Swartz, Architect, Microsoft Corp

© 2003 Microsoft Corporation. All rights reserved.© 2003 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.