Slides 02
Slides 02
(3rd Edition)
Architectural styles
Basic idea
A style is formulated in terms of
► (replaceable) components with well-defined interfaces
► the way that components are connected to each other
► the data exchanged between components
► how these components and connectors are jointly configured
into a system.
Connector
A mechanism that mediates communication, coordination, or
cooperation among components. Example: facilities for (remote)
procedure call, messaging, or streaming.
2 / 36
Architectures: Architectural styles Layered architectures
Layered architecture
Different layered
organizations
downcall One-way call
Request/Response
Handle
Upcall
Layer N-2
Layer N-2
Layer 2
Layer N-3
Layer 1
3 / 36
Architectures: Architectural styles Layered architectures
Layer N Layer N
Interface Service
Two-party communication
Server
1 from socket import
*
2 s = socket(AF_INET, SOCK_STREAM)
3 (conn, addr) = s.accept() # returns new socket and addr. client
45 True:
data
while # forever
= conn.recv(1024) # receive data from client
6 if not data: break # stop if client stopped
7 conn.send(str(data)+"
conn.close() ") # return sent data plus an " "
# close the *connection
8 *
Client
1 from socket import
*
2 s = socket(AF_INET, SOCK_STREAM)
43 s.connect((HOST,
s.send(’Hello, PORT)) # connect
world’) # send to server
some data(block until accepted)
5 data = s.recv(1024) # receive the response #
6 print data print the result
7 s.close() # close the connection
Application Layering
Application layering 6 / 36
Architectures: Architectural styles Layered architectures
Application Layering
Observation
This layering is found in many distributed information systems,
using traditional database technology and accompanying
applications.
Application layering 6 / 36
Architectures: Architectural styles Layered architectures
Application Layering
HTML page
Keyword expression containing list
HTML
generator Processing
Query Ranked list level
generator of page titles
Ranking
Database queries algorithm
Application layering 7 / 36
Architectures: Architectural styles Object-based and service-oriented architectures
Object-based style
Essence
Components are objects, connected to each other through
procedure calls. Objects may be placed on different machines; calls
can thus execute across a network.
State
Object Object
Method
Method call
Object
Object
Object
Interface
Encapsulation
Objects are said to encapsulate data and offer methods on that
data without revealing the internal implementation.
8 / 36
Architectures: Architectural styles Resource-based architectures
RESTful architectures
Essence
View a distributed system as a collection of resources,
individually managed by components. Resources may be added,
removed, retrieved, and modified by (remote) applications.
1. Resources are identified through a single naming scheme
2. All services offer the same interface
3. Messages sent to or from a service are fully self-described
4. After executing an operation at a service, that component
forgets everything about the caller
Basic Operation
operationsDescription
PUT Create a new resource
GET Retrieve the state of a resource in some representation
DELETE Delete a resource
POST Modify a resource by transferring a new state
9 / 36
Architectures: Architectural styles Resource-based architectures
Essence
Objects (i.e., files) are placed into buckets (i.e., directories).
Buckets cannot be placed into buckets. Operations on ObjectName
in bucket BucketName require the following identifier.
Typical operations
All operations are carried out by sending HTTP requests:
► Create a bucket/object: PUT, along with the URI
► Listing objects: GET on a bucket name
► Reading an object: GET on a full URI
10 / 36
Architectures: Architectural styles Resource-based architectures
On interfaces
Issue
Many people like RESTful approaches because the interface to a
service is so simple. The catch is that much needs to be done in the
parameter space.
11 / 36
Architectures: Architectural styles Resource-based architectures
On interfaces
Simplifications
Assume an interface bucket offering an operation create, requiring
an input string such as mybucket, for creating a bucket “mybucket.”
12 / 36
Architectures: Architectural styles Resource-based architectures
On interfaces
Simplifications
Assume an interface bucket offering an operation create, requiring
an input string such as mybucket, for creating a bucket “mybucket.”
SOAP
import bucket
bucket.create("mybucket")
12 / 36
Architectures: Architectural styles Resource-based architectures
On interfaces
Simplifications
Assume an interface bucket offering an operation create, requiring
an input string such as mybucket, for creating a bucket “mybucket.”
SOAP
import bucket
bucket.create("mybucket")
RESTful
PUT "http://mybucket.s3.amazonsws.com/"
12 / 36
Architectures: Architectural styles Resource-based architectures
On interfaces
Simplifications
Assume an interface bucket offering an operation create, requiring
an input string such as mybucket, for creating a bucket “mybucket.”
SOAP
import bucket
bucket.create("mybucket")
RESTful
PUT "http://mybucket.s3.amazonsws.com/"
Conclusions
Are there any to draw?
12 / 36
Architectures: Architectural styles Publish-subscribe architectures
Coordination
Temporal and referential
coupling
Temporally Temporally
coupled decoupled
Referentially Direct Mailbox
coupled
Referentially Event- Shared
decoupled based data space
Subscribe Notification
Publish Subscribe Data
delivery
delivery
Event bus
Publis h
Component
Shared (persistent) data space
13 / 36
Architectures: Architectural styles Publish-subscribe architectures
More details
► Calling out(t) twice in a row, leads to storing two copies of tuple
► t ⇒ a tuple space is modeled as a multiset.
Both in and rd are blocking operations: the caller will be blocked
until a matching tuple is found, or has become available.
14 / 36
Architectures: Architectural styles Publish-subscribe architectures
Bob
1 blog = linda.universe._rd(("MicroBlog",linda.TupleSpace))[1]
2
3 blog._out(("bob","distsys","I am studying chap 2"))
4 blog._out(("bob","distsys","The linda example’s pretty simple"))
5 blog._out(("bob","gtcn","Cool book!"))
Alice
1 blog = linda.universe._rd(("MicroBlog",linda.TupleSpace))[1]
2
3 blog._out(("alice","gtcn","This graph theory stuff is not easy"))
4 blog._out(("alice","distsys","I like systems more than graphs"))
Chuck
1 blog = linda.universe._rd(("MicroBlog",linda.TupleSpace))[1]
2
3 t1 = blog._rd(("bob","distsys",str))
4 t2 = blog._rd(("alice","gtcn",str))
5 t3 = blog._rd(("bob","gtcn",str))
15 / 36
Architectures: Middleware organization Wrappers
Problem
The interfaces offered by a legacy component are most likely
not suitable for all applications.
Solution
A wrapper or adapter offers an interface acceptable to a client
application. Its functions are transformed into those available at
the component.
16 / 36
Architectures: Middleware organization Wrappers
Organizing wrappers
Application Broker
17 / 36
Architectures: Middleware organization Interceptors
Problem
Middleware contains solutions that are good for most applications
⇒
you may want to adapt its behavior for specific applications.
18 / 36
Architectures: Middleware organization Interceptors
Client application
Intercepted call
B.doit(val)
Application stub
Object middleware
Message-level interceptor
Local OS
To object B
19 / 36
Architectures: System architecture Centralized organizations
Client Server
Request
Wait Provide service
Reply
User interface
Server machine
(a) (b) (c) (d) (e)
Multitiered Architectures 21 / 36
Architectures: System architecture Centralized organizations
Three-tiered architecture
Client Application Database
server server
Request
operation
Request
data
Wait for Wait for
reply data
Return
data
Return
reply
Multitiered Architectures 22 / 36
Architectures: System architecture Decentralized organizations: peer-to-peer systems
Alternative organizations
Vertical distribution
Comes from dividing distributed applications into three logical
layers, and running the components from each layer on a different
server (machine).
Horizontal distribution
A client or server may be physically split up into logically equivalent
parts, but each part is operating on its own share of the complete
data set.
Peer-to-peer architectures
Processes are all equal: the functions that need to be carried out are
represented by every process ⇒ each process will act as a client
and a server at the same time (i.e., acting as a servant).
23 / 36
Architectures: System architecture Decentralized organizations: peer-to-peer systems
Structured P2P
Essence
Make use of a semantic-free index: each data item is uniquely
associated with a key, in turn used as an index. Common practice:
use a hash function
key(data item) = hash(data item’s value).
P2P system now responsible for storing (key,value) pairs.
0100
0101 1101
1100
0110 0111
1111
1110
4
Looking up d with key k ∈ {0, 1, 2,..., 2 − 1} means routing request
to node with identifier k .
Structured peer-to-peer systems 24 / 36
Architectures: System architecture Decentralized organizations: peer-to-peer systems
Example: Chord
Principle
► Nodes are logically organized in a ring. Each node has an m-bit
identifier.
► Each data item is hashed to an m-bit key.
► Data item with key k is stored at node with smallest identifier
id ≥ k , called the successor of key k .
► The ring is extended with various shortcut links to other nodes.
Example: Chord
31 0 1
30 2
29 3
Actual node Shortcut 4
28
5
27
26 6
Nonexisting 7
node 25
24 8
21 11
20 12
19 13
18 14
17 15
16
lookup(3)@9 : 28 → 1 →
Structured peer-to-peer systems 26 / 36
4
Architectures: System architecture Decentralized organizations: peer-to-peer systems
Unstructured P2P
Essence
Each node maintains an ad hoc list of neighbors. The resulting
resembles a random graph: an edge (u, v) exists only with a certain
overlay
probability P[(u, v)].
Searching
► Flooding: issuing node u passes request for d to all neighbors.
Request is ignored when receiving node had seen it before.
Otherwise, v searches locally for d (recursively). May be limited
by a Time-To-Live: a maximum number of hops.
► Random walk: issuing node u passes request for d to randomly
chosen neighbor, v . If v does not have d , it forwards request
to one of its randomly chosen neighbors, and so on.
Super-peer networks
Essence
It is sometimes sensible to break the symmetry in pure
peer-to-peer networks:
► When searching in unstructured P2P systems, having
index servers improves performance
► Deciding where to store data can often be done more
efficiently through brokers.
Super peer
Overlay network of super peers
Weak peer
Edge-server architecture
Essence
Systems deployed on the Internet where servers are placed at the
edge of the network: the boundary between enterprise networks and
the actual Internet.
ISP
ISP
Core Internet
Edge server
Enterprise network
Edge-server systems 32 / 36
Architectures: System architecture Hybrid Architectures
Client node
K out of N nodes
Lookup(F) Node 1
Exchange blocks
► A file is divided into equally sized pieces (typically each being
256 KB)
► Peers exchange blocks of pieces, typically some 16 KB.
► A can upload a block d of piece D, only if it has piece D.
► Neighbor B belongs to the potential set PA of A, if B has a block
that A needs.
► If B ∈ PA and A ∈ PB : A and B are in a position that they can
Collaborative distributed systems 34 / 36
Architectures: System architecture Hybrid Architectures
BitTorrent phases
Bootstrap phase
A has just received its first piece (through optimistic unchoking: a
node from NA unselfishly provides the blocks of a piece to get a
newly arrived node started).
Trading phase
|PA| > 0: there is (in principle) always a peer with whom A can trade.
BitTorrent phases
0.8
0.6
|P|
|N|
0.4
|N| = 5
0.2 |N| = 10
|N| = 40
0.0
0.2 0.4 0.6
Fraction pieces
0.8 downloaded
1.0