03 - Services and SOA
03 - Services and SOA
Cloud Computing
Chapter 03
2
COMPUTER NETWORK
3
Computer Networks
• Different Types of Networks:
—PAN: Personal Area Networks enable various digital
devices carried by a user are connected by a low-
cost, low-energy network. (e.g. smart home, iPad,
TV)
—LAN (Ethernet): Local Area Networks carry message
at relative high speeds (10/100/1000Mbps) between
computers connected CAT5/CAT6 cables, fibers.
—WAN: Wide Area Networks carry message across
diferent organizations by large distances. Routers are
installed to communicate between networks
4
A game night example:
• Alex wants to host a game night at home with
multiple friends, where everyone brings a
computer:
6
MAC and IP Address
• To join a network, each computer needs to have
a NIC (Network Interface Card), could be a
network card, a WiFi adapter, a mobile network
modem.
• Each NIC has a unique MAC address, like
everyone has a HKID.
• The internet service provider will assign an IP
address to each NIC which act like a mailing
address or a phone number of a person.
—Others can contact this NIC via its IP address.
• Mac : for LAN/Switching ; IP : for WAN/Routing
7
IPv4
• IPv4 is represented by 4 segments of 8bits
decimal string, namely
—xxx . xxx. xxx. xxx where xxx is between 0 to 255
• Total number of IP address = 2^32, < 1
IP/human.
• CIDR : to refer a group of IP address, a notation
<IP>/<Mask Bit> is used.
192.168.0.0/24 =
192.168.0.0 – 192.168.0.255
https://getyouralgorithm.blogspot.com/2016/11/cidr-
classless-inter-domain-routing.html 8
IPv6
• IPv6 is to resolve insufficient IP problems.
• Use 128bits
• All hardware, software are ready, but…
9
Data from Google:https://www.google.com/intl/en/ipv6/statistics.html
A game night example (Cont 2):
• Alex’s home network does not use IPv6. In
addition, all computers are connected via one
public IP. When communicating with the
internet, how do you identify different devices?
10
NAT
• Network Address Translation (NAT): not all devices
can be assigned with a globally unique IP addresses
(not enough in IPv4)
• IPv6 has no such problem but we have not yet fully
migrated to IPv6.
• A NAT-enabled router does the following:
— Give each devices in the LAN/WLAN a “fake” IP.
— Each device attempts to connect to outside will “borrow”
the router IP and a random port.
— Server outside reply to the borrowed IP/port and the
router catches the message.
— Router relay the message to the “borrower”.
11
IP Routing
• IP address is globally managed by IANA and ICANN.
— Allocates IP blocks to the five regional internet registries
(RIRs)
— Each RIR allocates smaller IP blocks to national internet
registries (NIRs) and local internet registries (LIRS) and
eventually to your internet service provider (ISP).
— Using Classless Inter-Domain Routing (CIDR) hierarchical
addressing scheme, a NIC can be reachable through its
ISP.
• Routers based on IP address to route a packet from
a source to a destination
12
A game night example (Cont 3):
• Bob is playing games while watching YouTube
videos; how do the network devices and
applications identify the traffic for games or
videos?
13
IP and Port
• A NIC may have many connections at a time
(e.g. open many web browser tabs), each
connection needs to have a dedicated port.
• Port is a 16-bit unsigned integer ranging from 0
to 65535. Usually ports <1023 are reserved for
system used.
http://www.steves-internet-guide.com/tcpip-ports-sockets/ 14
https://helpdeskgeek.com/networking/determine-open-and-blocked-ports/
DNS Server
• A domain name is composed by different
namespaces in a hierarchical pattern, e.g.
www . domain . com . hk
• A domain name server helps a client to resolve
the IP address of a domain name.
• Anyone can register a domain name from a
TLD Manager, of course, with $.
15
Wireless Network WLAN
• Commonly known as WiFi, specified in IEEE
standard 802.11, evolves since 1999.
• Some protocols specific the physical layer of
communication (e.g. 802.11a/b/g/n/ac/ax)
• Some protocols specific other perspectives like
roaming (802.11v), security (802.11i)
https://www.makeuseof.com/tag/understanding-common-wifi-standards-technology-explained/ 16
A typical WLAN
18
VLAN
• A virtual LAN is a logical partition for devices
although they may be physically connected to
the same switch.
• VLAN can:
—Enable fine grain control
—Improve security
—Enhance broadcast performance
http://www.h3c.com/en/d_201211/761536_294551_0.htm 19
Firewall
• A firewall is a machine
that filters external
attacks.
—An Intrusion Detection
System (IDS) detects
network attacks and
rings alarm.
• Networks attacks:
—Port Scanning
—DoS/DDoS
—Phishing
20
NETWORK TRANSMISSION
21
External Data Representation
and Marshalling
• Different systems may store the same
information in different ways
—Big-endian system vs. little-endian system
—Different formats for floating-point numbers
—ASCII code vs. Unicode
https://chortle.ccsu.edu/AssemblyTutorial/Chapter-15/ass15_3.html
https://aha.betterexplained.com/t/8bit-floating-point-representation/1121
22
External Data Representation
and Marshalling
• External data representation is an agreed
standard for the representation of data
structures and primitive values
—It enables any two systems to exchange binary data
values.
— Marshalling: the process of taking a collection of
data items and assembling them into a form suitable
for transmission in a message
— Unmarshalling: the process of disassembling a
message to produce an equivalent collection of data
items at the destination
23
External Data Representation
and Marshalling
• Some popular data exchange format:
—Binary/raw: save space
—CSV: comma separated values
—XML: eXtensible Markup Language
—JSON: JavaScript Objection Notation
Images from:
https://nodegoat.net/guides/csvfile
https://dimestorerocket.com/read-a-xml-file-fast-with-csharp/ 24
https://cloud.google.com/bigquery/docs/loading-data-cloud-storage-json
Example:
Python Object Serialization
• Default data type like list/dict can be serialized
to JSON, which is more ready for data exchange
—> serialized_data = json.dumps(value)
• For Python Object or better efficiency, use pickle
—> Marshalling: pickle.dump(object, file)
—> Unmarshlling: restored_object = pickle.load(file)
Extended reading:
https://www.journaldev.com/15638/python-pickle-example
26
COMMUNICATION MODEL
27
Interprocess Communication
(IPC)
• Interprocess communication provides low-level
support for communication between processes (or
threads) in distributed systems, such as
— Socket programming
— Message Passing Interface (MPI)
28
Characteristics of IPC
• Synchronous and asynchronous
—In synchronous communication, the sending and
receiving processes synchronize at every message
• Both send and receive are blocking operations.
• Whenever a send is issued, the sending process is blocked
until the corresponding receive is issued.
• Whenever a receive is issued by a process, it blocks until a
message arrives.
—In asynchronous communication, the send operation
is non-blocking, while the receive operation can be
blocking or non-blocking
• The sending process can proceed as soon as the message
has been copied to a local buffer
29
Characteristics of IPC (Cont.)
• Reliability: validity and integrity
—Validity: a message service is reliable if messages are
guaranteed to be delivered, despite some packets
being dropped or lost.
30
Sockets (~1980s)
• Interprocess communication consists of
transmitting a message between a socket in one
process and a socket in another process.
—Specify IP address and Port
—Using a UDP socket: without acknowledgement or
retires; faster.
—Using a TCP socket: with acknowledgement, flow
control, speed control, error detection;
• Still using today, as a primitive level of network
communication implementation
31
Example of Python Socket
Client Server
import socket import socket
34
MPI (~1990s)
• MPI is a widely used standard for writing
message-passing programs
—http://www.mpi-forum.org
—It’s a specification, not an implementation
35
MPI Process and Message Passing
• An MPI program consists of many processes
— These processes are executed on a set of physical processors
which exchange data (by internal bus or a network).
36
Example:
Matrix-Vector Multiplication
37
Rowwise 1-D Partitioning
• Given p processes, Matrix A (m x n) is partitioned into p
smaller matrices, each with dimension ( m/p x n).
— For simplicity, we assume p divides m (or, m is divisible by p).
38
Matrix-Vector Multiplication by MPI
• Assumptions
— A total of p processes
— Matrix A (m x n) and vector x (n x 1) are created at process 0
• called “master process” because it coordinates the work of other
processes (i.e., “slave processes”)
1. Message passing:
— Process 0 will send (p-1) sub-matrices to corresponding
processes
— Process 0 will send vector x to all other p-1 processes
2. Calculations:
— Each process carries out its own matrix-vector multiplication
3. Message passing:
— Processes 1 to (p-1) send the results (i.e., part of vector y) back
to process 0
39
SERVICE-ORIENTED
ARCHITECTURE
40
Service-Oriented Architecture
• SOA is a loosely-coupled architecture that
component works together by service provision.
—Loosely-coupled: replaceable, upgradable
—Service provision: can be internal or external
• This implies open and standards-based
interoperability.
• Popular Implementations:
—SOAP (~2000s)
—RESTful (~2000s)
41
SOA
• Loose coupling and customized C# difficult to
42
Some SOA Principles
• Standardized Service Contract
— Service within the same service inventory are in
compliance with the same contract design standards.
• Service Loose Coupling
— Service contracts impose low consumer coupling
requirements and are themselves decoupled from their
surrounding environments.
• Service Abstraction
— Service contracts only contain essential information and
information about service is limited to what is published in
service contracts
• Service Reusability
— Services contain and express agnostic logic and can be
positioned as reusable enterprise resources.
43
Some SOA Principles (con’t)
• Service Autonomy
— Services exercise a high level of control over their
underlying runtime execution environment
• Service Statelessness
— Service minimize resource consumption by deferring the
management of state information when necessary.
• Service Discoverability
— Services are supplemented with communicative meta data
by which they can be effectively discovered and
interpreted
• Service Composability
— Services are effective composition participants, regardless
of the size and complexity of the composition.
46
Service Discovery
• Universal Description, Discovery, and
Integration (UDDI) is a protocol that enables a
global registry for advertising and discovery of
web services.
—White pages: contain name and general contact
about an entity.
—Yellow pages: contain classification information,
type and location of the services.
—Green pages: contain information about the details
of how to invoke the service (tech data).
47
STANDARD COMMUNICATION
PROTOCOLS
48
SOAP
• Simple Object Access Protocol is a message
exchange protocol that implements SOA.
• Assume the use of WSDL (XML), commonly over
HTTP.
• SOAP allows
—Over internet
—Cross operating systems (Win/Mac/Linux)
—Cross language (C++/Java/Python)
• It is a W3C standard
49
SOAP
50
SOAP Message Structure
<?xml version = "1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV = "http://www.w3.org/2001/12/soap-envelope"
SOAP-ENV:encodingStyle = "http://www.w3.org/2001/12/soap-encoding">
<SOAP-ENV:Header>
...
...
</SOAP-ENV:Header> 3 parts: Envelope, Header, Body
<SOAP-ENV:Body>
...
...
<SOAP-ENV:Fault>
...
...
</SOAP-ENV:Fault>
...
</SOAP-ENV:Body>
</SOAP_ENV:Envelope>
52
A live demo for SOAP
• https://www.crcind.com/csp/samples/SOAP.De
mo.cls
53
Python Implementation on
SOAP
• Using the package zeep
• Read a WSDL document by
—python –mzeep <URL_OF_WSDL>
55
Con’t
56
RESTful API
• REST is an acronym for Representational State
Transfer.
• PhD dissertation of Roy Fielding in 2000
• An architectural style for distributed system in
implementing SOA.
• An API that satisfy REST specification is called a
RESTful API
• May work with different platforms, different
languages, different data format (XML, JSON)
57
RESTful Idea
• The idea of a RESTful service is that usually
service involves operations like CRUD:
—Create Data
—Read Data
—Update Data
—Delete Data
• In HTTP protocol, it defines the functions
—GET
—POST
—PUT
• Add a new command DELETE
58
RESTful Idea
• Access a resource via a URL
—https://resource.pro/devices/list all devices list
—https://resource.pro/devices/1331/ device id 1331
59
RESTful
• Client–server – By separating the user interface concerns from the data storage
concerns, we improve the portability of the user interface across multiple platforms and
improve scalability by simplifying the server components.
• Stateless – Each request from client to server must contain all of the information
necessary to understand the request, and cannot take advantage of any stored context on
the server. Session state is therefore kept entirely on the client.
• Cacheable – Cache constraints require that the data within a response to a request be
implicitly or explicitly labeled as cacheable or non-cacheable. If a response is cacheable,
then a client cache is given the right to reuse that response data for later, equivalent
requests.
• Uniform interface – By applying the software engineering principle of generality to the
component interface, the overall system architecture is simplified and the visibility of
interactions is improved. In order to obtain a uniform interface, multiple architectural
constraints are needed to guide the behavior of components. REST is defined by four
interface constraints: identification of resources; manipulation of resources through
representations; self-descriptive messages; and, hypermedia as the engine of application
state.
• Layered system – The layered system style allows an architecture to be composed of
hierarchical layers by constraining component behavior such that each component cannot
“see” beyond the immediate layer with which they are interacting.
• Code on demand (optional) – REST allows client functionality to be extended by
downloading and executing code in the form of applets or scripts. This simplifies clients by
reducing the number of features required to be pre-implemented.
Ref: restfulapi.net 60
RESTful Example
• An RESTful API example that returns JSON
img; https://uchi.kz/zapis-v-bloge/patch-vs-post-rest-api
61
RESTful Python Implementation
62
Con’t
63
https://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask
Practice
• You can use the following resource to try
RESTful API.
• https://www.postman.com/flight-candidate-
14222983/workspace/workspace-
workshop/folder/22511140-9edb3892-656b-
407e-8b30-1adefd8b59f9
• A video demo:
https://www.youtube.com/watch?v=PfujVETI-
i4&ab_channel=Postman
64
MIDDLEWARE AND
MODELS
65
Remote Invocation
• Remote invocation is the most common
communication paradigm in distributed systems.
— Request-reply protocols: a pattern of two-way message
exchange on top of message passing
• Such as HTTP
— Remote procedure call (RPC): a client program can call
procedures in a server program transparently
• Such as Sun RPC
— Remote method invocation (RMI): extends the concept of
RPC to object-oriented programming model
• Such as Java RMI (~2000s)
— Message-Oriented Middleware (MoM): allow loosely
coupled component to communicate
• Such as EBS
66
Distributed Objects
• In distributed systems, objects can be physically
distributed into different processes or computers.
remote local C
invocation invocation local E
remote
invocation invocation F
B local
A
invocation D
remoteobject
Data
remote
interface
m1 implementation m4
{ m2
m3 of methods
m5
m6
to the stub.
Local Machine
Indirect Communication
• Both IPC and RMI are based on direct
communication.
— Direct coupling between the sender and receiver.
— It may not well handle the scenario that clients or servers
are temporally disconnected from the distributed system.
72
Pros and Cons of
Indirect Communication
• Advantages:
— With space uncoupling, system developer has more
degree of freedom in dealing with system changes such as
failure, replacement, upgrade, migration of system
participants (senders or receivers).
— With time uncoupling, sender and receiver(s) don’t need
to exist at the same time to communicate. This is good for
volatile environments where senders and receivers may
come and go.
• Disadvantages:
— Performance overhead by the added level of indirection
— The system becomes more difficult to manage precisely
73
Enterprise Service Bus (ESB)
• To abstract the communication mechanism so
that services can be defined that communicate
independent of details of the implementation.
—Developer does not need to worry that a port is
blocked by firewalls; or to choose using UDP for low
latency.
• Create a wrapper to allow different messages
can communicate with each other (e.g. SOAP
talk to REST)
74
Enterprise Service Bus (ESB)
With the help of ESB, services do not open a delicated channel to communicate; but rather
injects a message into the bus. This injection is performed by code loaded into each service and
represented by the filled ovals as clients interfaces in Fig 5.6(a).
Fig 5.6(b) shows an example of message bus being implemented in a distributed fashion as a set of brokers.
75
Pros and Cons of ESB
• Pros:
— It is easy to change components or add additional components
to an application.
— Convenient to enforce security and compliance requirements
— Provides load balancing to instantiate multiple copies of a
component
— Support failover
• Cons:
— There is no single accepted standard for features or behavior.
— Slower communication speed (for well coupled components)
— Single point of failure (if the bus fail)
— High configuration and maintenance complexity
77
Publish-subscribe Systems
• A widely used indirect communication technique
— A one-to-many indirect communication paradigm
78
Example:
A Dealing Room System
• A dealing room system: to allow dealers see the
latest information about the market prices of the
stocks they deal in.
—Market prices come from many information providers.
—A dealer is only interested in his own specialist
stocks.
79
Example:
A Dealing Room System
• Information provider process
— Continuously receives new trading information
— Each of the updates is regarded as an event.
— Publishes such events to the publish-subscribe system for
delivery
• Dealer process
— Create a subscription representing each named stock that
the dealer is interested in
— Each subscription expresses an interest in events.
— Receives all the information sent to it and displays it to
the dealer.
80
Programming Model of Publish-
Subscribe Systems
• Publishers disseminate an
event e through a publish(e)
operation. Publisher A Publisher B
Subscriber X Subscriber Y
• When events arrive at a
subscriber, the events are
delivered using notify(e)
operation. 82
More Reading Materials
• MPI:
— https://computing.llnl.gov/tutorials/mpi/
• Java RMI:
— https://docs.oracle.com/javase/tutorial/rmi/
• Publish-Subscribe System:
— Y. Liu and B. Plate, “Survey of Publish Subscribe Event Systems,” TR574, Indiana University.
— ftp://www.cs.indiana.edu/pub/techreports/TR574.pdf
• SOA:
— https://docs.microsoft.com/en-us/dotnet/architecture/microservices/architect-microservice-
container-applications/service-oriented-architecture
— https://patterns.arcitura.com/
• RESTful:
— https://restfulapi.net/
• ESB:
— https://searchapparchitecture.techtarget.com/definition/Enterprise-Service-Bus-ESB
— https://learning.oreilly.com/library/view/enterprise-service-bus/0596006756/ch01.html
84