SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignRyan Riley
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#Pascal Laurin
 
Secrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesSecrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesBruno Borges
 
Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design Introductionwojtek_s
 
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Edureka!
 
Service Oriented Architecture
Service Oriented Architecture Service Oriented Architecture
Service Oriented Architecture Prabhat gangwar
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignNader Albert
 
Microservice architecture design principles
Microservice architecture design principlesMicroservice architecture design principles
Microservice architecture design principlesSanjoy Kumar Roy
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architectureAbdelghani Azri
 
Grokking Techtalk #39: How to build an event driven architecture with Kafka ...
 Grokking Techtalk #39: How to build an event driven architecture with Kafka ... Grokking Techtalk #39: How to build an event driven architecture with Kafka ...
Grokking Techtalk #39: How to build an event driven architecture with Kafka ...Grokking VN
 
Microservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and SagaMicroservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and SagaAraf Karsh Hamid
 
Domain driven design
Domain driven designDomain driven design
Domain driven designits_skm
 
software-architecture-patterns
software-architecture-patternssoftware-architecture-patterns
software-architecture-patternsPallav Kumar
 

What's hot (20)

Event Storming and Saga
Event Storming and SagaEvent Storming and Saga
Event Storming and Saga
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Implementing DDD with C#
Implementing DDD with C#Implementing DDD with C#
Implementing DDD with C#
 
Secrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesSecrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on Kubernetes
 
Domain Driven Design Introduction
Domain Driven Design IntroductionDomain Driven Design Introduction
Domain Driven Design Introduction
 
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
 
Service Oriented Architecture
Service Oriented Architecture Service Oriented Architecture
Service Oriented Architecture
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Microservice architecture design principles
Microservice architecture design principlesMicroservice architecture design principles
Microservice architecture design principles
 
Design patterns tutorials
Design patterns tutorialsDesign patterns tutorials
Design patterns tutorials
 
Introduction to DDD
Introduction to DDDIntroduction to DDD
Introduction to DDD
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architecture
 
Grokking Techtalk #39: How to build an event driven architecture with Kafka ...
 Grokking Techtalk #39: How to build an event driven architecture with Kafka ... Grokking Techtalk #39: How to build an event driven architecture with Kafka ...
Grokking Techtalk #39: How to build an event driven architecture with Kafka ...
 
Microservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and SagaMicroservices Architecture Part 2 Event Sourcing and Saga
Microservices Architecture Part 2 Event Sourcing and Saga
 
Domain driven design
Domain driven designDomain driven design
Domain driven design
 
Onion architecture
Onion architectureOnion architecture
Onion architecture
 
Domain Driven Design 101
Domain Driven Design 101Domain Driven Design 101
Domain Driven Design 101
 
software-architecture-patterns
software-architecture-patternssoftware-architecture-patterns
software-architecture-patterns
 
Introduction to microservices
Introduction to microservicesIntroduction to microservices
Introduction to microservices
 
Design patterns
Design patternsDesign patterns
Design patterns
 

Viewers also liked (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)
 

Similar to Patterns for distributed systems

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 FirstEnea Gabriel
 
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 GuideMohammed Fazuluddin
 
05 rpc-case studies
05 rpc-case studies05 rpc-case studies
05 rpc-case studieshushu
 
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
 
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 beyondJon Galloway
 
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 DaliCarl Steinbach
 
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 applicationsJaime Martin Losa
 
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 applicationsAccumulo Summit
 
Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas JellemaModern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas JellemaLucas Jellema
 
Migrating SOA
Migrating SOAMigrating SOA
Migrating SOACoi Xay
 
Cytoscape CI Chapter 2
Cytoscape CI Chapter 2Cytoscape CI Chapter 2
Cytoscape CI Chapter 2bdemchak
 
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.0Bruce Johnson
 
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 EngineeringRafael Ferreira da Silva
 
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...Amit Sheth
 

Similar to 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...
 

More from Paulo Gandra de Sousa

More from Paulo Gandra de Sousa (8)

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

Recently uploaded

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
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
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
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
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 - VDineshKumar4165
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
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 torqueBhangaleSonal
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 

Recently uploaded (20)

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...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
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, ...
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
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
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
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
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 

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

Editor's Notes

  1. Design the same old CRUD interface Verbose