Software Architecture & Design 6CCS3SAD Dr Kevin Lano Session 10: Clouds, Services, Microservices, SOA March 2022 Learning Outcomes At the end of this session you should be able to: – Explain the purpose and functionalities of clouds, web services, microservices and SOA – Use our UML2 extension to specify SOA 3 Overview • • • • • Cloud Service-oriented Architecture (SOA) Web Services Microservices Containers 4 Cloud • So far – Application servers provide transparency for software components • What if we could also provide transparency of hardware? – – – – Resources as a commodity (rented, not purchased) No need to know what HW your SW runs on No need to know where that HW is Let someone else manage the HW and share it with other users Increased flexibility & economies of scale 5 Cloud software characteristics • Scalability – Increases in load/number of users can be handled by increasing the number of (virtual) servers running new copies of software • Elasticity – Also can scale down resources to match reduced demand • Resilience – Tolerates server failures by dynamic re-allocation of servers to tasks 6 Cloud Services • Types of Cloud services – Infrastructure-as-a-Service (IaaS) – Platform-as-a-Service (PaaS) – Software-as-a-Service (SaaS) – Mobile Backend-as-a-Service (MBaaS) 7 Infrastructure-as-a-Service (IaaS) • Transparent infrastructure (i.e., HW) – Physical machines (PMs) or virtual machines (VMs) • Pay for additional resources as and when needed – Automated commissioning through an API or web front end • “Metered” consumption: – Pay for what you use, so flexible for expansion – No need for capital cost of buying hardware • Examples: AWS, Microsoft Azure 8 Platform-as-a-Service (PaaS) • IaaS plus a set of standardised services – Data management, logging, email API, payment services, … • Build software more efficiently by building on existing services – Truly component-based thinking – Reuse at a large scale • Examples: Heroku, Google App Engine, … 9 Software-as-a-Service (SaaS) • “Rent” your software system – Typically accessed through a web front end or app – Data managed transparently on cloud servers – Implementation shared across different users • Highly efficient delivery model – Provider keeps control of software and operations – Efficient updates rolled out to all clients (or only a selection of clients) • Examples: Microsoft Office 365, Dropbox, … 10 Software-as-a-Service (SaaS) Software Customers Software Provider Software Services Cloud Provider Cloud Infrastructure 11 Software-as-a-Service (SaaS) • Advantages for customers: – – – – Access from any device No up-front costs for software or servers Immediate software updates Reduced software management costs • Disadvantages: – Data held remotely (privacy & security issues) – Loss of control over updates – Service lock-in (need to keep paying to access software even when not used) 12 Overview • • • • • Cloud Service-oriented Architecture (SOA) Web Services Microservices Containers 13 Service-oriented Architecture • • • • • • • • A system structured as set of communicating services Services are self-contained functional units Minimise shared datastores Communicate using standard protocols and data formats (eg., XML, JSON) Loosely-coupled, not aware of internals of other services. Technology and location independent Service discovery mechanisms are required, eg., via registries of services/service brokers Services can be composed, orchestrated, etc Shifts complexity from application into network 14 SOA example Holiday Booking Service Car Rental Service Hotel Booking Service Holiday Package Calculator Flight Booking Service Internal functionality of service External services 15 Web Services • Problem: various systems require integration – written under heterogeneous platforms and languages – Distributed over a network (eg., the internet) • Solutions: – Re-implement systems to operate under a common platform or communication framework (costly) – Implement connection points between systems as web services (cheaper) Java based system Webservice client HTTP SOAP Webservice server .NET based system 16 Web Services • Services published using a description language: – Define name and parameters of service Web service directory Locate a web service Webservice Client application client Register a web service HTTP SOAP Webservice server Server application 17 Web Services • Web services are typically: – Business-to-business or involve access to remote data – Can be a common subtask in several business processes. • Should not: – Be performance-critical – Require fine-grained interchange of data. 18 Web Services • Web service host – Machine on which web service executable resides • Publisher of a web service – Makes web service available for use • Consumer of a web service – Application that uses web service • 2 main approaches: SOAP; REST 19 Web Services • SOAP: Simple object access protocol – XML-based protocol for exchanging messages, including descriptions of remote procedure calls (RPC). – SOAP messages are XML documents (envelopes) describing method call of service. Body can contain request or response data. • WSDL: Web services definition language – XML-based descriptions of services 20 SOAP Web Services • Easy and flexible way of doing RPCs – Components whose interfaces are exposed through HTTP – Client component obtains a proxy reference to the web service and invokes methods on that – Infrastructure transforms method invocations into XML for transmission over the net • Using the Simple Object Access Protocol (SOAP) and HTTP 21 REST & RESTful Web Services • Representational State Transfer (REST): – Data & functionality accessed using Uniform Resource Identifiers (URIs), resources/services are identified by URIs, global addresses – Uses only standard HTTP commands – GET retrieves current state of a resource. – POST transfers a new state onto a resource. – Resources are decoupled from their representation so their content can be accessed in variety of formats, eg. HTML, XML, plain text, PDF, JPEG, JSON, and others. 22 REST & RESTful Web Services – Every interaction with a resource is stateless: request messages are self-contained. – Stateful interactions are based on concept of explicit state transfer, eg., by using URI rewriting, cookies, and hidden form fields. – State can be embedded in response messages to point to valid future states of the interaction. • Compared to SOAP/WSDL approach, REST is simpler (no special languages/formats needed) but less flexible: clients must know precise URI of service. Java API for REST web services: https://github.com/jax-rs 23 SOAP Web Services in .NET using System; using System.Web.Services; using System.Xml.Serialization; WebService attribute to indicate service location [WebService(Namespace="http://localhost/MyWebServices/")] public class ExampleService : WebService { [WebMethod] public int Add(int a, int b) Subclass WebService { return a + b; } [WebMethod] public string SayHello() { return "Hello World"; } WebMethod attribute indicates methods to be exposed } 24 UML2 Specialization • Treat web services like other components – Add <<WebService>> stereotype • Implies use of service through SOAP – Tagged Values • WebServiceNamespace to indicate service location • WebMethod to indicate methods to be exposed – Used on provided interface <<Webservice>> ExampleService {WebserviceNamespace = "http://localhost/ MyWebServices/"} IMsg {Webmethod=[add,sayHello]} <<Interface>> IMsg +add(a:int,b:int):int +sayHello():string 25 SOAP Web Services in Java EE import java.util.*; import javax.jws.WebService; import javax.jws.WebMethod; import javax.jws.WebParam; WebService annotation @WebService( name = “ExampleService", serviceName = “ExampleService" ) public class ExampleService { @WebMethod( operationName = “add" ) public int add(int a, int b) { return a+b; } @WebMethod( operationName = “sayHello" ) public String sayHello() { return “Hello World"; } } WebMethod annotation indicates methods to be exposed JAX-WS specification: https://javaee.github.io/metro-jax-ws/ 26 REST web service example Share price predictor using Monte-Carlo simulation REST web service example • All data supplied as input parameters: – – – – – currentPrice : double timeDays : int – length of period for prediction growthRate : double variation : double – volatility of the share runs : int – number of samples to generate • result parameter gives estimated future price. • For a web service, name of service changed to estimateFuturePrice REST web service example Share price predictor input form REST web service example <jsp:useBean id="bean" scope="request" class="beans.ControllerBean"/> <jsp:setProperty name="bean" property="currentPrice“ param="currentPrice"/> <jsp:setProperty name="bean" property="timeDays" param="timeDays"/> <jsp:setProperty name="bean" property="growthRate" param="growthRate"/> <jsp:setProperty name="bean" property="variation" param="variation"/> <jsp:setProperty name="bean" property="runs" param="runs"/> <html><head><title>estimateFuturePrice</title></head> <body> JSP receives request, copies <h1>estimateFuturePrice</h1> <% bean.estimateFuturePrice(); %> <h2>estimateFuturePrice performed</h2> <strong> Result = </strong> <%= bean.getResult() %> </body> </html> data to ControllerBean, executes bean operation and generates result web page. REST web service example package beans; import java.util.*; public class ControllerBean { Controller cont; ControllerBean wraps implementation class Controller public ControllerBean() { cont = Controller.inst(); } double currentPrice, growthRate, variation; int timeDays, runs; String result; public void setcurrentPrice(String _s) { … convert _s to a double … } public void estimateFuturePrice() { result = "" + cont.estimateFuturePrice(currentPrice, timeDays, growthRate,variation,runs); } public String getResult() { return result; } } REST web service example <<JSP>> estimateFuturePrice ControllerBean Controller Presentation Tier Business Tier 32 REST web service example Response to request estimateFuturePrice.jsp? currentPrice=100 & timeDays=50 & growthRate=0.1 & variation=0.09 Service Pattern Examples • Service Broker – Define a service which locates services which can meet a given request, and links such a service to the requestor • Service Decomposition – Decompose a coarse-grained service into two or more subservices 34 Service Broker Client interface: Service Search Supplier services can register/deregister with Broker. Client issues search for a particular functionality. Broker Broker finds suitable server service & connects requestor and service (eg., by returning URI of service to requestor). <<publish/subscribe>> Service3 Service1 Service2 35 Service Broker Example Client interface: Flight Search FlightBroker Broker finds flight providers which can sell the requested flights & connects requestor to these providers <<publish/subscribe>> FlightProvider3 FlightProvider1 FlightProvider2 36 Microservices • Architectural style – SOA with fine-grained services – Use services for componentisation of applications – Each running in its own process – Potentially developed by separate teams – Communication via web-based protocols http://martinfowler.com/articles/microservices.html Microservice Composition • Orchestration – One master service coordinates others in the correct order • Choreography – Services coordinate with each other, by generating and listening to events Microservice Orchestration • API gateway – Provides access point for clients to possibly a set of services – The gateway selects the correct service and translates service requests into calls to individual services • For example, several related financial services could be managed in this way – Share price estimation; option valuation; trading advice, etc. Orchestration example Financial Services API Presentation Tier Business Tier Option pricing Share price estimator Trading advisor 40 Choreography example <<publish/subscribe>> Requestor BondPriceEstimator YieldCurveService <<publish/subscribe>> To compute price of bond B, estimator requires a yield curve (map of time to interest rates) for time period of B, when this is available, the BondPriceEstimator is notified, this reads any required rates in order to compute the price of B. In turn, this price is delivered by notification to the original requestor. 03/03/2016 41 Microservices: Advantages • Real-world componentisation! – Independent modification Incremental updates of application functionality – Clear boundaries of team responsibility • Organisational impact – Continuous deployment in an agile development process – Microservices enforce cross-functional teams rather than functional silos Microservices: Disadvantages • Deployment – More complex as there are more “moving parts” – More skills and better tools needed • Performance – Need efficient cross-process communication • Flexibility – More difficult to move component boundaries • Failure – Any service can fail at any time – Need more extensive monitoring and defensive programming • Could be seen as a good thing • No explicit required interfaces 43 Microservices: Failure management • Internal service failure – Detected by service & reported to requestor – HTTP error codes can be used (eg., 200 for success, 404 for failure due to an unreachable resource) • External service failure – External cause prevents service from operating – actions needed to restart service • Service performance failure – Degradation of service due to excessive loads, etc – Address by monitoring and reconfiguration – Eg., using a ‘circuit breaker’ which cuts an unresponsive service out of the configuration of services. https://martinfowler.com/bliki/CircuitBreaker.html 44 Overview • • • • • Cloud Service-oriented Architecture (SOA) Web Services Microservices Containers 45 Containers • Use ideas from the Cloud to support microservices – Containers provide all software required for specific microservices – Lightweight virtualisation compared to full VMs – Require less resources and reduced activation time compared to VMs • Example tooling: Docker https://www.docker.com/ Summary • • • • Cloud: IaaS, PaaS, SaaS Service-oriented Architecture (SOA) Web Services: SOAP, REST Microservices: Composition & management • Containers 47