SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Event Driven Architecture (EDA) Reference Architecture | Anbu Krishnaswamy
Event Driven Architecture (EDA) Reference Architecture | Anbu KrishnaswamyEvent Driven Architecture (EDA) Reference Architecture | Anbu Krishnaswamy
Event Driven Architecture (EDA) Reference Architecture | Anbu Krishnaswamy
Bob Rhubart
 

Tendances (20)

Event Driven Architecture (EDA) Reference Architecture | Anbu Krishnaswamy
Event Driven Architecture (EDA) Reference Architecture | Anbu KrishnaswamyEvent Driven Architecture (EDA) Reference Architecture | Anbu Krishnaswamy
Event Driven Architecture (EDA) Reference Architecture | Anbu Krishnaswamy
 
Design patterns for microservice architecture
Design patterns for microservice architectureDesign patterns for microservice architecture
Design patterns for microservice architecture
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Event-driven microservices
Event-driven microservicesEvent-driven microservices
Event-driven microservices
 
Event Driven Architecture
Event Driven ArchitectureEvent Driven Architecture
Event Driven Architecture
 
Architecture: Microservices
Architecture: MicroservicesArchitecture: Microservices
Architecture: Microservices
 
Software Architecture Patterns
Software Architecture PatternsSoftware Architecture Patterns
Software Architecture Patterns
 
CQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDDCQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDD
 
The Art of Discovering Bounded Contexts
The Art of Discovering Bounded ContextsThe Art of Discovering Bounded Contexts
The Art of Discovering Bounded Contexts
 
Microservices
MicroservicesMicroservices
Microservices
 
Event Driven Software Architecture Pattern
Event Driven Software Architecture PatternEvent Driven Software Architecture Pattern
Event Driven Software Architecture Pattern
 
Unit iii-Architecture in the lifecycle
Unit iii-Architecture in the lifecycleUnit iii-Architecture in the lifecycle
Unit iii-Architecture in the lifecycle
 
Spring Framework Petclinic sample application
Spring Framework Petclinic sample applicationSpring Framework Petclinic sample application
Spring Framework Petclinic sample application
 
DDD Tactical Design with Clean Architecture - Ivan Paulovich
DDD Tactical Design with Clean Architecture - Ivan PaulovichDDD Tactical Design with Clean Architecture - Ivan Paulovich
DDD Tactical Design with Clean Architecture - Ivan Paulovich
 
Documenting Software Architectures
Documenting Software ArchitecturesDocumenting Software Architectures
Documenting Software Architectures
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring Boot
 
Microservices Docker Kubernetes Istio Kanban DevOps SRE
Microservices Docker Kubernetes Istio Kanban DevOps SREMicroservices Docker Kubernetes Istio Kanban DevOps SRE
Microservices Docker Kubernetes Istio Kanban DevOps SRE
 
A visual introduction to Event Sourcing and CQRS
A visual introduction to Event Sourcing and CQRSA visual introduction to Event Sourcing and CQRS
A visual introduction to Event Sourcing and CQRS
 
Introducing Saga Pattern in Microservices with Spring Statemachine
Introducing Saga Pattern in Microservices with Spring StatemachineIntroducing Saga Pattern in Microservices with Spring Statemachine
Introducing Saga Pattern in Microservices with Spring Statemachine
 
Software architecture patterns
Software architecture patternsSoftware architecture patterns
Software architecture patterns
 

En vedette

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
 

En vedette (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)
 

Similaire à 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
 

Similaire à 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...
 

Plus de Paulo Gandra de Sousa (7)

Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
Minds-on DDD
Minds-on DDDMinds-on DDD
Minds-on DDD
 
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
 
models of distributed computing
models of distributed computingmodels of distributed computing
models of distributed computing
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed Systems
 

Dernier

Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
Kamal Acharya
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
chumtiyababu
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Dernier (20)

Hospital management system project report.pdf
Hospital management system project report.pdfHospital management system project report.pdf
Hospital management system project report.pdf
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 

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

Notes de l'éditeur

  1. Design the same old CRUD interface Verbose