SlideShare uma empresa Scribd logo
1 de 50
PROGRAMAÇÃO DE 
SISTEMAS 
DISTRIBUIDOS 
Paulo Gandra de Sousa 
pag@isep.ipp.pt
Disclaimer 
1 
ISEP/IPP 
 Parts of this presentation are from: 
 Paulo Sousa (PARS) 
 Ron Jacobs (ARC01) 
 Greg Young 
 Udi Dahn
Today’s lesson 
2 
 Design Patterns 
 Patterns for distributed Systems 
 Service Orientation patterns 
 CQRS
Design patterns
What is a Pattern? 
4 
ISEP/IPP 
Each pattern describes a problem that occurs 
over and over again in our environment and 
then describes the core of the solution to that 
problem in such a way that you can use this 
solution a million times over without ever 
doing it the same way twice. 
Christopher Alexander
What is a design Pattern? 
5 
ISEP/IPP 
A design pattern names, abstracts, and identifies 
the key aspects of a common design structure 
that make it useful for creating a reusable 
object-oriented design. 
Design Patterns-Elements of Reusable Object-oriented 
Software, Gamma et al. (Gang of 
Four)
What a pattern is not 
6 
ISEP/IPP 
 A miracleous receipt 
source: British Medical Journal
What is a pattern 
7 
ISEP/IPP 
 A set of best-practices 
 A typified solution for a common problem in a giving 
context 
 Creates a common vocabulary 
 Patterns are discovered not invented 
 “Patterns are half-baked” 
 Martin Fowler
Anti-pattern 
8 
ISEP/IPP 
 An example of what not to do 
 Proven techniques that have shown bad 
results
Patterns for distributed 
applications
Architecture 
15 
ISEP/IPP 
“client” application 
Service 
Gateway 
“server” application 
Remote 
Façade 
Service 
Layer 
Business 
logic 
Data 
Transfer 
Object 
Service 
Locator 
contract
Service Gateway 
16 
ISEP/IPP 
 An object that encapsulate the code that implements the 
consumer portion of a contract. They act as proxies to other 
services, encapsulating the details of connecting to the 
source and performing any necessary translation. 
fonte: Enterprise Solution Patterns Using .NET 
Pattern
Service Gateway 
17 
ISEP/IPP 
 Hides the details of accessing the service (ex., 
network protocol) 
 May be considered a data access component 
 Native support from most tools (e.g., Visual Studio, 
Netbeans, Rational software Architect) by web 
service proxies 
 See also Proxy and Broker pattern 
Pattern
Service locator 
18 
ISEP/IPP 
 Hides the complexity of finding and creating 
service gateways 
fonte: Core J2EE Patterns
Remote Façade 
19 
ISEP/IPP 
 Provides a coarse-grained façade on fine-grained 
objects to improve efficiency over a 
network 
fonte: Patterns of Enterprise Application Architecture 
Pattern
Remote Facade 
20 
ISEP/IPP 
 Domain object interfaces are tipically fine grained 
 Inadequeate for remote operations 
 Create a surronding layer above domain objects 
 Local clients use the local interface 
 The facade may encapsulate the interface of one or more 
business objects 
 Domain objects: 
 Address.New 
 Address.Set 
 Person.AddAddress 
 Person.Update 
 Remote Facade: 
 AddressFacade.AddNewAddressToPerson 
Pattern
Data Transport Object 
21 
ISEP/IPP 
 An object that carries data between 
processes in order to reduce the number of 
method calls. 
fonte: Patterns of Enterprise Application Architecture 
Pattern
Data Transport Object 
22 
ISEP/IPP 
 Since XML is the de facto standard DTO should support serialization 
to/from XML 
 Should be independent of the underlying domain object 
 Should be implemented in accordance with the requiremnts of the 
remote application 
 CompleteCustomerInfoDTO 
 BasicCustomerInfoDTO 
 Should be independent of the underlying platform (e.g., programming 
language) 
 DataSet/DataTable .net 
 ResultSet JDBC 
 DateTime .net 
Pattern
Service Layer 
23 
ISEP/IPP 
 Defines an application's boundary with a layer of 
services that establishes a set of available operations 
and coordinates the application's response in each 
operation 
fonte: Patterns of Enterprise Application Architecture 
Pattern
Service Layer 
24 
ISEP/IPP 
Pattern 
 Domain logic pattern in the context of service 
orientation 
 May be implemented as a Remote Facade or 
may be called by a Remote Facade
Business Logic 
28 
ISEP/IPP 
 Outside of the scope 
 Excellent reference: Patterns of Enterprise 
Application Architecture 
 Table Module 
 Table Data Gateway 
 Domain Model 
 Active Record 
 Data Mapper 
 Optimistic Offline Lock 
 …
Service Orientation
CRUDy interface: Service Anti-pattern! 
30 
interface CustomerService { 
int createCustomer(string name, …); 
CustomerDTO readCustomer(int id); 
bool updateCustomer(CustomerDTO c); 
bool deleteCustomer(int id); 
} 
interface CustomerService { 
int createCustomer(string name, …); 
CustomerDTO readCustomer(int id); 
bool changeAddress(int id, AddressDTO c); 
bool makePrefered(int id) 
bool deactivateCustomer(int id, string reason); 
}
Loosey-Goosey : Service Anti-pattern! 
31 
 Design highly flexible interface 
 E.g., Expose direct SQL access 
 In the intent to provide flexibility, there is no 
service contract 
interface CustomerService { 
CustomerDTO[] readCustomer(string where); 
}
Document Processor 
32 
 Provide a document centric contract, not an 
RPC-like contract
Idempotent operation 
33 
 Executing once or many times has the exact 
same side effects 
 Allows for repeated request 
 Ensures same outcome and only one end-state 
change 
 E.g., 
 setBalance() vs. addBalance() 
 delete() 
 read()
Reservation 
34 
 Allows for long running transactions without 
locking 
 Must have compensation procedure 
 ACID transactions are for databases not for 
distributed systems! 
 Look at the world around you, e.g., travel 
arrangements 
 Rent a car 
 Book the hotel 
 Buy the plane ticket
Compensating Transaction 
35 
Source: http://msdn.microsoft.com/en-us/library/dn589783.aspx
Queue-based load leveling 
36 
Source: http://msdn.microsoft.com/en-us/library/dn589783.aspx
Web/Worker roles 
37 
 Separate acepting requests from handling the 
requests 
Web role Queue Worker role 
 Both roles can scale independently
Scaling out 
38 
Web role Queue Worker role 
Thousands of 
instances 
Dozens or 
hundreds of 
instances 
 Queue must ensure reliability, transactionality 
and (possibly) single reader
Competing consumers 
39
Exercise 
 Remember the 
example DS you 
provided in the last 
session. 
 Define an 
hypothetical SOA for 
that system 
 Define contract 
 Identify where you 
would use the 
presented patterns 
40 
ISEP/IPP
41 CQRS
Stereotypical distributed system 
42 
Source: http://martinfowler.com/bliki/CQRS.html
Typical data flow 
43 
1. request data 
2. DTO is sent from the 
server 
UI Backend 
3. do some change to the 
data 
4. send updated DTO to the 
server 
5. ack/nack
Typical API & UI 
44 
interface CustomerService { 
int createCustomer(string name, …); 
CustomerDTO readCustomer(int id); 
bool updateCustomer(CustomerDTO c); 
bool deleteCustomer(int id); 
}
Problems with Stereotypical 
distributed system 
 Read vs Write frequency 
 Read model vs Write model 
 Does not capture user intent 
Does not scale well
CQRS 
46 
 Command 
 Query 
 Responsibility 
 Segregation
Separating Commands from 
Queries 
47 
Source: http://martinfowler.com/bliki/CQRS.html
Two APIs 
48 
interface CustomerQueryService { 
CustomerDTO readCustomer(int id); 
} 
interface CustomerCommandService { 
int createCustomer(string name, …); 
bool updateCustomer(CustomerDTO c); 
bool deleteCustomer(int id); 
}
Separating Query model from 
Transaction model 
49 
Adapted from: http://martinfowler.com/bliki/CQRS.html 
Periodically 
sync query 
model
Two models 
50 
 Command = Transactional 
 Optimized for transactions 
 Highly normalized in case of relational data 
 Query 
 Highly denormalized 
 Read-only 
 Safely redundant
Capturing user intent 
51 
1. request data 
2. DTO is sent from the 
server 
UI Backend 
3. choose a task & fill in the 
task s data 
4. send command to the 
server 
5. ack/nack
Task-based UI 
52 
CRUD interface Task-based UI
Task-based UI => Intentional 
API 
53 
interface CustomerQueryService { 
CustomerDTO readCustomer(int id); 
} 
interface CustomerCommandService { 
int createCustomer(string name, …); 
bool changeAddress(int id, Address a); 
bool makePrefered(int id); 
bool deactivateCustomer(int id, string reason); 
}
Exercise 
 Think about the 
system we have 
been discussing in 
the class and 
discuss if and how 
CQRS would be 
applicable and why. 
54
Patterns Bibliography 
55 
ISEP/IPP 
 Buschmann, F.; Henney, K. And Schmidt, D. (2007) Pattern- 
Oriented Software Architecture: A Pattern Language for Distributed 
Computing, Volume 4. Willey. 
 Patterns of Enterprise Application Architecture. Martin Fowler. 
Adisson-Wesley. 
 Core J2EE Patterns: Best Practices and Design Strategies. Deepak 
Alur, John Crupi and Dan Malks. Prentice Hall / Sun Microsystems 
Press. http://java.sun.com/blueprints/corej2eepatterns/index.html 
 Enterprise Solution Patterns Using Microsoft .NET. Microsoft Press. 
http://msdn.microsoft.com/architecture/patterns/default.aspx?pull=/li 
brary/en-us/dnpatterns/html/Esp.asp
Patterns Suggested readings 
56 
ISEP/IPP 
 Design patterns : elements of reusable object-oriented software. Erich 
Gamma, Richard Helm, Ralph Johnson, John Vissides. 
 Pattern-oriented Software Architecture: System of Patterns. Frank 
Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, 
Michael Stal 
 Principles of Service design: service patterns and anti-patterns. John 
Evdemon (2005) http://msdn.microsoft.com/en-us/ 
library/ms954638.aspx 
 Cloud Design Patterns. Microsoft Patterns & Practices. 
http://msdn.microsoft.com/en-us/library/dn568099.aspx 
 Designing Data Tier Components and Passing Data Through Tiers. 
Microsoft Patterns & Practices. 
http://msdn.microsoft.com/library/?url=/library/en-us/ 
dnbda/html/BOAGag.asp?frame=true
CQRS Bibliography 
57 
 Martin Fowler (2011) CQRS, 
http://martinfowler.com/bliki/CQRS.html 
 Greg Young, CQRS documents, 
http://cqrs.files.wordpress.com/2010/11/cqrs_documents.pdf 
 Microsoft Patterns & Practices (2012) Exploring CQRS and Event 
Sourcing, Microsoft Patterns & Practices. Available at 
http://msdn.microsoft.com/en-us/library/jj554200.aspx

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Node.js BFFs: our way to better/micro frontends
Node.js BFFs: our way to better/micro frontendsNode.js BFFs: our way to better/micro frontends
Node.js BFFs: our way to better/micro frontends
 
Microservices Decomposition Patterns
Microservices Decomposition PatternsMicroservices Decomposition Patterns
Microservices Decomposition Patterns
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architecture
 
The Evolution of Integration
The Evolution of IntegrationThe Evolution of Integration
The Evolution of Integration
 
Domain driven design and model driven development
Domain driven design and model driven developmentDomain driven design and model driven development
Domain driven design and model driven development
 
Event Driven Architecture
Event Driven ArchitectureEvent Driven Architecture
Event Driven Architecture
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
Microservices Architecture
Microservices ArchitectureMicroservices Architecture
Microservices Architecture
 
Domain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationDomain Driven Design(DDD) Presentation
Domain Driven Design(DDD) Presentation
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Kong Summit 2018 - Microservices: decomposing applications for testability an...
Kong Summit 2018 - Microservices: decomposing applications for testability an...Kong Summit 2018 - Microservices: decomposing applications for testability an...
Kong Summit 2018 - Microservices: decomposing applications for testability an...
 
Big Data Redis Mongodb Dynamodb Sharding
Big Data Redis Mongodb Dynamodb ShardingBig Data Redis Mongodb Dynamodb Sharding
Big Data Redis Mongodb Dynamodb Sharding
 
Why to Cloud Native
Why to Cloud NativeWhy to Cloud Native
Why to Cloud Native
 
Hands-On With Reactive Web Design
Hands-On With Reactive Web DesignHands-On With Reactive Web Design
Hands-On With Reactive Web Design
 
Microservice vs. Monolithic Architecture
Microservice vs. Monolithic ArchitectureMicroservice vs. Monolithic Architecture
Microservice vs. Monolithic Architecture
 
What is Cloud Native Explained?
What is Cloud Native Explained?What is Cloud Native Explained?
What is Cloud Native Explained?
 
Microservices
MicroservicesMicroservices
Microservices
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
12-Factor Apps
12-Factor Apps12-Factor Apps
12-Factor Apps
 

Destaque

Patterns of Enterprise Application Architecture (by example)
Patterns of Enterprise Application Architecture (by example)Patterns of Enterprise Application Architecture (by example)
Patterns of Enterprise Application Architecture (by example)
Paulo Gandra de Sousa
 

Destaque (15)

Software Product Lines
Software Product LinesSoftware Product Lines
Software Product Lines
 
RESTful services Design Lab
RESTful services Design LabRESTful services Design Lab
RESTful services Design Lab
 
Decoupled Communication
Decoupled CommunicationDecoupled Communication
Decoupled Communication
 
Communication
CommunicationCommunication
Communication
 
OO design principles and patterns
OO design principles and patternsOO design principles and patterns
OO design principles and patterns
 
Benefits of Hypermedia API
Benefits of Hypermedia APIBenefits of Hypermedia API
Benefits of Hypermedia API
 
REST beyond CRUD
REST beyond CRUDREST beyond CRUD
REST beyond CRUD
 
Principles of Service Orientation
Principles of Service OrientationPrinciples of Service Orientation
Principles of Service Orientation
 
Enterprise Integration Patterns
Enterprise Integration PatternsEnterprise Integration Patterns
Enterprise Integration Patterns
 
Rest web services
Rest web servicesRest web services
Rest web services
 
Lição prova professor coordenador
Lição prova professor coordenadorLição prova professor coordenador
Lição prova professor coordenador
 
PoEAA by Example
PoEAA by ExamplePoEAA by Example
PoEAA by Example
 
Modern web architectural patterns
Modern web architectural patternsModern web architectural patterns
Modern web architectural patterns
 
Design Patterns: From STUPID to SOLID code
Design Patterns: From STUPID to SOLID codeDesign Patterns: From STUPID to SOLID code
Design Patterns: From STUPID to SOLID code
 
Patterns of Enterprise Application Architecture (by example)
Patterns of Enterprise Application Architecture (by example)Patterns of Enterprise Application Architecture (by example)
Patterns of Enterprise Application Architecture (by example)
 

Semelhante a Patterns for distributed systems

05 rpc-case studies
05 rpc-case studies05 rpc-case studies
05 rpc-case studies
hushu
 
Dynamic Object-Oriented Requirements System (DOORS)
Dynamic Object-Oriented Requirements System (DOORS)Dynamic Object-Oriented Requirements System (DOORS)
Dynamic Object-Oriented Requirements System (DOORS)
David Groff
 
Rpc Case Studies (Distributed computing)
Rpc Case Studies (Distributed computing)Rpc Case Studies (Distributed computing)
Rpc Case Studies (Distributed computing)
Sri Prasanna
 
Performance modeling and simulation for accumulo applications
Performance modeling and simulation for accumulo applicationsPerformance modeling and simulation for accumulo applications
Performance modeling and simulation for accumulo applications
Accumulo Summit
 

Semelhante a Patterns for distributed systems (20)

Application Hosting
Application HostingApplication Hosting
Application Hosting
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
 
Software architectural patterns - A Quick Understanding Guide
Software architectural patterns - A Quick Understanding GuideSoftware architectural patterns - A Quick Understanding Guide
Software architectural patterns - A Quick Understanding Guide
 
Unit 1
Unit  1Unit  1
Unit 1
 
05 rpc-case studies
05 rpc-case studies05 rpc-case studies
05 rpc-case studies
 
Dynamic Object-Oriented Requirements System (DOORS)
Dynamic Object-Oriented Requirements System (DOORS)Dynamic Object-Oriented Requirements System (DOORS)
Dynamic Object-Oriented Requirements System (DOORS)
 
Rpc Case Studies (Distributed computing)
Rpc Case Studies (Distributed computing)Rpc Case Studies (Distributed computing)
Rpc Case Studies (Distributed computing)
 
What you need to know about .NET Core 3.0 and beyond
What you need to know about .NET Core 3.0 and beyondWhat you need to know about .NET Core 3.0 and beyond
What you need to know about .NET Core 3.0 and beyond
 
Tdd,Ioc
Tdd,IocTdd,Ioc
Tdd,Ioc
 
Exploiting the Data / Code Duality with Dali
Exploiting the Data / Code Duality with DaliExploiting the Data / Code Duality with Dali
Exploiting the Data / Code Duality with Dali
 
Chapter 6
Chapter 6Chapter 6
Chapter 6
 
Distributed Systems: How to connect your real-time applications
Distributed Systems: How to connect your real-time applicationsDistributed Systems: How to connect your real-time applications
Distributed Systems: How to connect your real-time applications
 
Performance modeling and simulation for accumulo applications
Performance modeling and simulation for accumulo applicationsPerformance modeling and simulation for accumulo applications
Performance modeling and simulation for accumulo applications
 
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas JellemaModern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
 
Migrating SOA
Migrating SOAMigrating SOA
Migrating SOA
 
Cytoscape CI Chapter 2
Cytoscape CI Chapter 2Cytoscape CI Chapter 2
Cytoscape CI Chapter 2
 
Overview of VS2010 and .NET 4.0
Overview of VS2010 and .NET 4.0Overview of VS2010 and .NET 4.0
Overview of VS2010 and .NET 4.0
 
Middleware
MiddlewareMiddleware
Middleware
 
Bridging Concepts and Practice in eScience via Simulation-driven Engineering
Bridging Concepts and Practice in eScience via Simulation-driven EngineeringBridging Concepts and Practice in eScience via Simulation-driven Engineering
Bridging Concepts and Practice in eScience via Simulation-driven Engineering
 
MobiCloud: Towards Cloud Mobile Hybrid Application Generation using Semantica...
MobiCloud: Towards Cloud Mobile Hybrid Application Generation using Semantica...MobiCloud: Towards Cloud Mobile Hybrid Application Generation using Semantica...
MobiCloud: Towards Cloud Mobile Hybrid Application Generation using Semantica...
 

Mais de Paulo Gandra de Sousa (9)

Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
Minds-on DDD
Minds-on DDDMinds-on DDD
Minds-on DDD
 
Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservices
 
Design Patterns: Back to Basics
Design Patterns: Back to BasicsDesign Patterns: Back to Basics
Design Patterns: Back to Basics
 
Hypermedia APIs
Hypermedia APIsHypermedia APIs
Hypermedia APIs
 
Revision control with Mercurial
Revision control with MercurialRevision control with Mercurial
Revision control with Mercurial
 
Documenting Software Architectures
Documenting Software ArchitecturesDocumenting Software Architectures
Documenting Software Architectures
 
models of distributed computing
models of distributed computingmodels of distributed computing
models of distributed computing
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed Systems
 

Último

UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
rknatarajan
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 

Último (20)

(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 

Patterns for distributed systems

  • 1. PROGRAMAÇÃO DE SISTEMAS DISTRIBUIDOS Paulo Gandra de Sousa pag@isep.ipp.pt
  • 2. Disclaimer 1 ISEP/IPP  Parts of this presentation are from:  Paulo Sousa (PARS)  Ron Jacobs (ARC01)  Greg Young  Udi Dahn
  • 3. Today’s lesson 2  Design Patterns  Patterns for distributed Systems  Service Orientation patterns  CQRS
  • 5. What is a Pattern? 4 ISEP/IPP Each pattern describes a problem that occurs over and over again in our environment and then describes the core of the solution to that problem in such a way that you can use this solution a million times over without ever doing it the same way twice. Christopher Alexander
  • 6. What is a design Pattern? 5 ISEP/IPP A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. Design Patterns-Elements of Reusable Object-oriented Software, Gamma et al. (Gang of Four)
  • 7. What a pattern is not 6 ISEP/IPP  A miracleous receipt source: British Medical Journal
  • 8. What is a pattern 7 ISEP/IPP  A set of best-practices  A typified solution for a common problem in a giving context  Creates a common vocabulary  Patterns are discovered not invented  “Patterns are half-baked”  Martin Fowler
  • 9. Anti-pattern 8 ISEP/IPP  An example of what not to do  Proven techniques that have shown bad results
  • 10. Patterns for distributed applications
  • 11. Architecture 15 ISEP/IPP “client” application Service Gateway “server” application Remote Façade Service Layer Business logic Data Transfer Object Service Locator contract
  • 12. Service Gateway 16 ISEP/IPP  An object that encapsulate the code that implements the consumer portion of a contract. They act as proxies to other services, encapsulating the details of connecting to the source and performing any necessary translation. fonte: Enterprise Solution Patterns Using .NET Pattern
  • 13. Service Gateway 17 ISEP/IPP  Hides the details of accessing the service (ex., network protocol)  May be considered a data access component  Native support from most tools (e.g., Visual Studio, Netbeans, Rational software Architect) by web service proxies  See also Proxy and Broker pattern Pattern
  • 14. Service locator 18 ISEP/IPP  Hides the complexity of finding and creating service gateways fonte: Core J2EE Patterns
  • 15. Remote Façade 19 ISEP/IPP  Provides a coarse-grained façade on fine-grained objects to improve efficiency over a network fonte: Patterns of Enterprise Application Architecture Pattern
  • 16. Remote Facade 20 ISEP/IPP  Domain object interfaces are tipically fine grained  Inadequeate for remote operations  Create a surronding layer above domain objects  Local clients use the local interface  The facade may encapsulate the interface of one or more business objects  Domain objects:  Address.New  Address.Set  Person.AddAddress  Person.Update  Remote Facade:  AddressFacade.AddNewAddressToPerson Pattern
  • 17. Data Transport Object 21 ISEP/IPP  An object that carries data between processes in order to reduce the number of method calls. fonte: Patterns of Enterprise Application Architecture Pattern
  • 18. Data Transport Object 22 ISEP/IPP  Since XML is the de facto standard DTO should support serialization to/from XML  Should be independent of the underlying domain object  Should be implemented in accordance with the requiremnts of the remote application  CompleteCustomerInfoDTO  BasicCustomerInfoDTO  Should be independent of the underlying platform (e.g., programming language)  DataSet/DataTable .net  ResultSet JDBC  DateTime .net Pattern
  • 19. Service Layer 23 ISEP/IPP  Defines an application's boundary with a layer of services that establishes a set of available operations and coordinates the application's response in each operation fonte: Patterns of Enterprise Application Architecture Pattern
  • 20. Service Layer 24 ISEP/IPP Pattern  Domain logic pattern in the context of service orientation  May be implemented as a Remote Facade or may be called by a Remote Facade
  • 21. Business Logic 28 ISEP/IPP  Outside of the scope  Excellent reference: Patterns of Enterprise Application Architecture  Table Module  Table Data Gateway  Domain Model  Active Record  Data Mapper  Optimistic Offline Lock  …
  • 23. CRUDy interface: Service Anti-pattern! 30 interface CustomerService { int createCustomer(string name, …); CustomerDTO readCustomer(int id); bool updateCustomer(CustomerDTO c); bool deleteCustomer(int id); } interface CustomerService { int createCustomer(string name, …); CustomerDTO readCustomer(int id); bool changeAddress(int id, AddressDTO c); bool makePrefered(int id) bool deactivateCustomer(int id, string reason); }
  • 24. Loosey-Goosey : Service Anti-pattern! 31  Design highly flexible interface  E.g., Expose direct SQL access  In the intent to provide flexibility, there is no service contract interface CustomerService { CustomerDTO[] readCustomer(string where); }
  • 25. Document Processor 32  Provide a document centric contract, not an RPC-like contract
  • 26. Idempotent operation 33  Executing once or many times has the exact same side effects  Allows for repeated request  Ensures same outcome and only one end-state change  E.g.,  setBalance() vs. addBalance()  delete()  read()
  • 27. Reservation 34  Allows for long running transactions without locking  Must have compensation procedure  ACID transactions are for databases not for distributed systems!  Look at the world around you, e.g., travel arrangements  Rent a car  Book the hotel  Buy the plane ticket
  • 28. Compensating Transaction 35 Source: http://msdn.microsoft.com/en-us/library/dn589783.aspx
  • 29. Queue-based load leveling 36 Source: http://msdn.microsoft.com/en-us/library/dn589783.aspx
  • 30. Web/Worker roles 37  Separate acepting requests from handling the requests Web role Queue Worker role  Both roles can scale independently
  • 31. Scaling out 38 Web role Queue Worker role Thousands of instances Dozens or hundreds of instances  Queue must ensure reliability, transactionality and (possibly) single reader
  • 33. Exercise  Remember the example DS you provided in the last session.  Define an hypothetical SOA for that system  Define contract  Identify where you would use the presented patterns 40 ISEP/IPP
  • 35. Stereotypical distributed system 42 Source: http://martinfowler.com/bliki/CQRS.html
  • 36. Typical data flow 43 1. request data 2. DTO is sent from the server UI Backend 3. do some change to the data 4. send updated DTO to the server 5. ack/nack
  • 37. Typical API & UI 44 interface CustomerService { int createCustomer(string name, …); CustomerDTO readCustomer(int id); bool updateCustomer(CustomerDTO c); bool deleteCustomer(int id); }
  • 38. Problems with Stereotypical distributed system  Read vs Write frequency  Read model vs Write model  Does not capture user intent Does not scale well
  • 39. CQRS 46  Command  Query  Responsibility  Segregation
  • 40. Separating Commands from Queries 47 Source: http://martinfowler.com/bliki/CQRS.html
  • 41. Two APIs 48 interface CustomerQueryService { CustomerDTO readCustomer(int id); } interface CustomerCommandService { int createCustomer(string name, …); bool updateCustomer(CustomerDTO c); bool deleteCustomer(int id); }
  • 42. Separating Query model from Transaction model 49 Adapted from: http://martinfowler.com/bliki/CQRS.html Periodically sync query model
  • 43. Two models 50  Command = Transactional  Optimized for transactions  Highly normalized in case of relational data  Query  Highly denormalized  Read-only  Safely redundant
  • 44. Capturing user intent 51 1. request data 2. DTO is sent from the server UI Backend 3. choose a task & fill in the task s data 4. send command to the server 5. ack/nack
  • 45. Task-based UI 52 CRUD interface Task-based UI
  • 46. Task-based UI => Intentional API 53 interface CustomerQueryService { CustomerDTO readCustomer(int id); } interface CustomerCommandService { int createCustomer(string name, …); bool changeAddress(int id, Address a); bool makePrefered(int id); bool deactivateCustomer(int id, string reason); }
  • 47. Exercise  Think about the system we have been discussing in the class and discuss if and how CQRS would be applicable and why. 54
  • 48. Patterns Bibliography 55 ISEP/IPP  Buschmann, F.; Henney, K. And Schmidt, D. (2007) Pattern- Oriented Software Architecture: A Pattern Language for Distributed Computing, Volume 4. Willey.  Patterns of Enterprise Application Architecture. Martin Fowler. Adisson-Wesley.  Core J2EE Patterns: Best Practices and Design Strategies. Deepak Alur, John Crupi and Dan Malks. Prentice Hall / Sun Microsystems Press. http://java.sun.com/blueprints/corej2eepatterns/index.html  Enterprise Solution Patterns Using Microsoft .NET. Microsoft Press. http://msdn.microsoft.com/architecture/patterns/default.aspx?pull=/li brary/en-us/dnpatterns/html/Esp.asp
  • 49. Patterns Suggested readings 56 ISEP/IPP  Design patterns : elements of reusable object-oriented software. Erich Gamma, Richard Helm, Ralph Johnson, John Vissides.  Pattern-oriented Software Architecture: System of Patterns. Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, Michael Stal  Principles of Service design: service patterns and anti-patterns. John Evdemon (2005) http://msdn.microsoft.com/en-us/ library/ms954638.aspx  Cloud Design Patterns. Microsoft Patterns & Practices. http://msdn.microsoft.com/en-us/library/dn568099.aspx  Designing Data Tier Components and Passing Data Through Tiers. Microsoft Patterns & Practices. http://msdn.microsoft.com/library/?url=/library/en-us/ dnbda/html/BOAGag.asp?frame=true
  • 50. CQRS Bibliography 57  Martin Fowler (2011) CQRS, http://martinfowler.com/bliki/CQRS.html  Greg Young, CQRS documents, http://cqrs.files.wordpress.com/2010/11/cqrs_documents.pdf  Microsoft Patterns & Practices (2012) Exploring CQRS and Event Sourcing, Microsoft Patterns & Practices. Available at http://msdn.microsoft.com/en-us/library/jj554200.aspx

Notas do Editor

  1. Design the same old CRUD interface Verbose