CS07 - Software Architecture
CS07 - Software Architecture
June 6 2020
Software Architecture
Patterns and Tactics
Dr.D.VENKATA SUBRAMANIAN
GUEST FACULTY, BITS, Pilani,WILP
© Len Bass, Paul Clements, Rick Kazman, distributed under Creative Commons Attribution License
Session Outline
• What is a Pattern?
• Pattern Catalogue
• Module patterns
• Component and Connector Patterns
• Allocation Patterns
• A context. A recurring, common situation in the world that gives rise to a problem.
• A problem. The problem, appropriately generalized, that arises in the given context.
• A solution. A successful architectural resolution to the problem, appropriately
abstracted. The solution for a pattern is determined and described by:
• A set of element types (for example, data repositories, processes, and objects)
• A set of interaction mechanisms or connectors (for example, method calls, events,
or message bus)
• A topological layout of the components
• A set of semantic constraints covering topology, element behavior, and
interaction mechanisms
Welcome to Session 7
June 06th 2020
Software Architecture
Patterns and Tactics
TNGK Ranganath
BITS, Pilani,WILP
© Len Bass, Paul Clements, Rick Kazman, distributed under Creative Commons Attribution License
Publish-Subscribe Pattern
Publish-Subscribe Pattern
• Context:
• There are a number of independent producers and consumers of data that must interact.
The precise number and nature of the data producers and consumers are not
predetermined or fixed, nor is the data that they share.
• Problem:
• How can we create integration mechanisms that support the ability to transmit messages
among the producers and consumers so they are unaware of each other’s identity, or
potentially even their existence?
• Solution:
• In the publish-subscribe pattern, components interact via announced messages, or events.
Components may subscribe to a set of events.
• Publisher components place events on the bus by announcing them; the connector then
delivers those events to the subscriber components that have registered an interest in
those events.
Publish-Subscribe Pattern
• Typical examples of systems that employ the publish-subscribe pattern are:
• Graphical user interfaces, in which a user’s low-level input actions are treated as
events that are routed to appropriate input handlers
• MVC-based applications, in which view components are notified when the state of
a model object changes
• Enterprise resource planning (ERP) systems, which integrate many components,
each of which is only interested in a subset of system events
• Extensible programming environments, in which tools are coordinated through
events
• Mailing lists, where a set of subscribers can register interest in specific topics
• Social networks, where “friends” are notified when changes occur to a person’s
website
• The publish-subscribe pattern is used to send events and messages to an unknown
set of recipients.
Publish-Subscribe Pattern
• The publish-subscribe pattern can take several forms:
• List-based publish-subscribe is a realization of the pattern where every publisher maintains a
subscription list—a list of subscribers that have registered an interest in receiving the event.
• Broadcast-based publish-subscribe differs from list-based publish-subscribe in that publishers have less
(or no) knowledge of the subscribers.
• Publishers simply publish events, which are then broadcast.
• Subscribers examine each event as it arrives and determine whether the published event is of interest.
• Content-based publish-subscribe is much more general. Each event is associated with a set of
attributes and is delivered to a subscriber only if those attributes match subscriber-defined patterns.
• Publish-subscribe pattern is typically realized by some form of message-oriented middleware, where
the middleware is realized as a broker, managing the connections and channels of information
between producers and consumers.
• This middleware is often responsible for the transformation of messages in addition to routing and
storing the messages.
• The publish-subscribe pattern inherits the strengths and weaknesses of the broker pattern.
Publish-Subscribe Example
Publish – Subscribe - Example
• Order creation event is subscribed to by Picking module, Transport module,
Loyalty module
Picking
module
New
Order order
Event
Transport
module notifier module
Loyalty
module
Publisher Subscribers
Publish - Subscribe
• Components interested in knowing about events, subscribe to relevant events
• Publisher place events on an Event bus
• Event bus delivers events to subscribers who have registered for those events
Post office
Telephone
Magazine
Company
Publish - Subscribe
• A process may subscribe to more than one topic / channel
• A topic / channel can be subscribed to by more than 1 process
Publish – Subscribe implementations
Content based
• Topic based – Ex. Sports, Business, Politics – One can subscribe
for a topic
• Content Pattern based – Ex. (Stock = Tata Steel & Value > Rs.
3000 per share) – Subscriber is notified when the condition is
met
Publish-Subscribe tools
Tools
When a new employee joins, the HR department creates an employee record in the database, storing various details of the
employee such as employee id, name, address, tel #, department, salary, bank account #, etc.
After this, HR needs to notify other departments such as Finance dept. for initiating PF, Transport dept. for arranging pickup &
drop, IT dept. for issuing laptop & to provision access rights to different systems & applications, etc.
The systems of these different departments are informed by calling the API provided by them.
The HR department finds that they keep getting requests from other departments to inform them whenever a new employee joins
so that they can do their processing.
This results in frequent changes to the HR’s Employee Joining module. So the systems department decided to use a Publish and
Subscribe architecture.
Finance
system
HR API
Employee
joins Transport API Transport
HR system
system
IT API
IT system
Exercise: New architecture
Finance
system
HR API
Employee
joins Transport
API Transport
HR system SNS
system
IT API
IT system
Eliminates polling
Publish-Subscribe Solution – 1
Elements:
Overview:
Components publish • Any C&C Relations: The
and subscribe to component with at attachment relation
events. least one publish or associates components
subscribe port. with the publish-
When an event is subscribe connector by
• The publish-
announced by a prescribing which
component, the subscribe
connector, which components announce
connector events and which
infrastructure will have announce
components are
dispatches the event and listen roles for registered to receive
to all registered components that events.
subscribers. wish to publish and
subscribe to
events.
Publish-Subscribe Solution - 2
Weaknesses:
Constraints: All components are
connected to an event distributor • Typically increases latency and
that may be viewed as either a bus has a negative effect on
—connector—or a component. scalability and predictability of
Publish ports are attached to message delivery time.
announce roles and subscribe • Less control over ordering of
ports are attached to listen roles. messages, and delivery of
messages is not guaranteed.
Shared-Data Pattern
Shared-Data Pattern
Overview: Elements:
• Communication between data • Shared-data store. Concerns
accessors is mediated by a include types of data stored,
shared data store. data performance-oriented
• Control may be initiated by properties, data distribution,
the data accessors or the data and number of accessors
store. Data is made persistent permitted.
by the data store. • Data accessor component.
• Data reading and writing
connector.
Shared Data Solution - 2
Forces
30
Examples
Robot control
Modern
(navigation,
machine Modern
Speech environment
Vehicle learning Adobe OCR compilers tend
recognition learning,
identification algorithms for text to be more
(HEARSAY reasoning,
and tracking complex task recognition Blackboard
project 1980) destination
(Jeopardy oriented
route
challenge)
planning)
31
Examples
32
Blackboard Pattern
35
Benefits
Benefits Liabilities
36
Map-Reduce Pattern
Map-Reduce Pattern
• Businesses have a pressing need • For many applications with ultra- • The map-reduce pattern requires
to quickly analyze enormous large data sets, sorting the data three parts:
volumes of data they generate or and then analyzing the grouped • A specialized infrastructure takes
access, at petabyte scale. data is sufficient. care of allocating software to the
• The problem the map-reduce hardware nodes in a massively
pattern solves is to efficiently parallel computing environment
perform a distributed and and handles sorting the data as
parallel sort of a large data set needed.
and provide a simple means for • A programmer specified
the programmer to specify the component called the map which
analysis to be done. filters the data to retrieve those
items to be combined.
• A programmer specified
component called reduce which
combines the results of the map
Map-Reduce Example
Map-Reduce pattern
• Used to analyse vast amounts of data
• Let us say we want to find out the top 3 web pages visited by users of a website every
month
• We will have to capture data about different pages visited by each user and record the
duration for which they stayed on that page
• Then we need to determine the average time spent by users on every page during the 30
days of the month
• How can we speed up this analysis?
Map-Reduce pattern: Example
DB DB DB
Calculate
weighted average
Map-Reduce pattern
Overview: Elements:
• Deploy on is the relation • The data to be analyzed • If you do not have large
between an instance of must exist as a set of data sets, the overhead
a map or reduce files. of map-reduce is not
function and the • Map functions are justified.
processor onto which it stateless and do not • If you cannot divide your
is installed. communicate with each data set into similar
• Instantiate, monitor, and other. sized subsets, the
control is the relation • The only communication advantages of
between the between map reduce parallelism are lost.
infrastructure and the instances is the data • Operations that require
instances of map and emitted from the map multiple reduces are
reduce. instances as <key, value> complex to orchestrate.
pairs.
Multi-Tier Pattern
Security
Protocol translation
Service composition
Reference: https://microservices.io/patterns/microservices.html
API Gateway
The granularity of APIs provided by microservices is often different than what a
service client needs.
FTGO application
1. Consumers place
food order
2. Restaurants
manage orders
3. FTGO assigns
courier to deliver
food
4. FTGO pays
restaurants and
couriers
Stripe is a
Payment
service
Twilio is a
messaging
service
SES is a
Simple
email
service
Micro-services
pattern
Key benefits & Challenges of Micro-
services architecture
Key Benefits
• Faster delivery,
• Improved scalability, and
• Greater autonomy
Key Challenges
• Resource monitoring and management
• Failure, recovery and self-repair
Micro-services case study
Danske Bank
Micro-services
Danske Bank – Case study
Questions:
Danske Bank – Case study
SOA at Cigna
TripAdvisor
architecture
Case study: TripAdvisor
1. Who is the publisher and who are the subscribers of GPS correction data?
2. How was the network traffic reduced?
3D-P GPS
Publish-Subscribe
Case study: 3D-P Publish Subscribe
1. Who is the publisher and who are the subscribers of GPS correction data?
• Publisher: GPS correction data provider
• Subscribers: Earth Moving Equipment (EME)
2. How was the network traffic reduced?
• Unicast instead of broadcast. That is sending data only to relevant EME and not to all
EMEs. Thus reducing data transmission
• Maintain list of active EME. Send GPS correction data only if the EME is active. Thus
further reducing data transmission
Exercise: Identify the architecture
patterns
For the following situations, identify the arch pattern that can be used:
2. The city traffic control center shows a map of the city roads along with information about the level of congestion on different
roads: Red for heavy congestion, Orange for medium and Green for no congestion. This is enabled by sensors sensing the
traffic density on important roads. The sensor data is stored in a database which is then analysed to display the level of
congestion on the road map
Pipe & Filter, MVC, Shared data
3. A cooking gas company wants to implement a system to provide different services to consumers – services such as booking of
gas cylinder, requesting for a technician visit, ordering a tube, etc.. Users should be able to access this system via browser, smart
phone or SMS. Backend database is Oracle.
Layered, Micro-services
Exercise: Identify the architecture
patterns
Mention the architecture patterns used in the architecture described below of an ERP system:
a. Sending ‘Request for Quote’ to Vendors who have registered for supplying the item
• Publish – Subscribe
b. Instruction to bank at end of month to pay salary to employees by calling a service supported by the
banking IT system
• SoA
c. Automatic tracking of inventory received & dispatched from warehouses using RFID
• Pipe & Filter
Patterns are built from tactics; MVC, for example utilizes the
tactics:
if a pattern is a molecule, • Increase semantic coherence
a tactic is an atom. • Encapsulation
• Use an intermediary
• Use run time binding
Tactics Augment Patterns
System
Ping/Echo
cost:
• increased performance:
A tactic to resources
address the Common side cost more • how to
performance effects of utilize the
side-effect is Increase increase
“Increase Available resources
Available Resources are: efficiently?
Resources”.
Tactics and Interactions - 5
System
Ping/Echo
Increase Available
Resources
Resource
Cost
Utilization
Tactics and Interactions - 6
modifiability:
modifiability: • how to
A tactic to
address the • how to add change the
Common side scheduling
efficient use of the
effects of policy in the
resources side- scheduling
Scheduling future?
effect is policy to the
Policy are:
“Scheduling existing
Policy”. architecture
Tactics and Interactions - 7
System
Ping/Echo
Increase Available
Resources
Resource
Cost
Utilization
Scheduling
Policy
Add to Modify
system policy
Tactics and Interactions - 8
Ping/Echo
Increase Available
Resources
Cost Resource
Utilization
Scheduling
Policy
Add to Modify
system policy
Use an
Intermediary
Ensure
usage
Tactics and Interactions – 10.
No. Eventually the side-effects of each tactic become small enough to ignore.
Summary
Any Questions ?