Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Developing Distributed Web Applications, Where does REST fit in?


Published on

Published in: Technology, Sports
  • amazing slide bravo (clap) it cleared up my mind after weeks of researching and i think i found a architectural principle for my self use ROA for outer world use SOA for inner world of your system make your system service based deal with clients resource based. What is your opinion for this idea?
    Are you sure you want to  Yes  No
    Your message goes here
  • Did this talk in INET Colombo yesterday
    Are you sure you want to  Yes  No
    Your message goes here

Developing Distributed Web Applications, Where does REST fit in?

  1. 1. Developing Distributed Web Applications, Where does REST fit in?<br />Dr. Srinath Perera<br />Senior Software Architect, WSO2 Inc.<br />Visiting Faculty, University of Moratuwa<br />
  2. 2. What is a Distributed Web Application?<br />Users access a one server (or he thinks he does) while really the app is composed of many machines. <br />Why “Distributed”? <br />for scaling. Single machine can not handle the load<br />High availability <br />photo by arvindgrover on Flickr,<br />
  3. 3. Google as a Distributed Web Application<br />Google crawls the Web and stores all (well most of ) the Web<br />It builds indexes for included words and incoming links for each document<br />When a user sends a query, it applies the Page Rank Algorithm and returns the most relevant results. <br />It is a distributed application that built using few 100k servers<br />
  4. 4. Programming Distributed Web Applications<br />Essentially (Web) applications deal with state (data) and operations (executions or processing units)<br />Users talk to applications and either retrieve data or make changes to the current state. <br />There are two primary architectural models<br />SOA (Service Oriented Architectures) : based on processing units (verbs)<br />ROA (Resource Oriented Architecture): based on data(nouns)<br />photo by QolePejorian on Flickr,<br />
  5. 5. SOA (Service Oriented Architecture)<br />There are many stateless processing units (often grouped as services)<br />Users provide data to processing units, and they either return data after processing or change the system wide state (e.g. stored in the database).<br />A SOA based architecture includes a main storage (e.g. database) and many stateless processing units, and an application combines and composes those processing units together. <br />E.g. Google has its indexes etc., and one main operation “search” that accepts a search query as a input and returns matching documents. <br />Also implementation has many internal services <br />photo by L. Marie on Flickr,<br />
  6. 6. ROA (Resource Oriented Architecture)<br />There is a resource structure<br />Each resource supports four operations, PUT, GET, POST, DELETE<br />Users retrieve information through GET and change system state through POST, DELETE, and PUT<br />The architecture is based on resources (nouns) and processing is represented through four verbs on the resource. <br />photo by Svadilfari on Flickr, (CC)<br />
  7. 7. ROA vs. SOA<br />There are lots of fights, which I am not going to discuss in detail. <br />Argument is Web uses ROA, and it works. <br />SOA is much closer to the programing models we used to with languages like C or Java. So that is natural to us. <br />I would say, they are two useful styles, and we have to know both and use them where it naturally fits. <br />I will focus more on ROA for this discussion. <br />photo by hans s on Flickr,<br />
  8. 8. REST (Representational State Transfer)<br />ROA is realized with REST services or HTTP services (Good intro to REST,<br />Main principles of REST<br />Give everything an ID (URI)<br />Things (resources) refer to each other <br />All interactions are done through four verbs (PUT, GET, DELETE, POST) on resources<br />Photo by paraflyer on Flickr,<br />Resources can return multiple formats (choosed based on content negotiation) <br />All communication are stateless (each request has all the information need to serve the request)<br />
  9. 9. Example: Web App to Manage a Network<br />Assume we want to build a Web app to manage networks. Users can view, query, and change the network configurations through this Web App. <br />Lets see how this would look with both SOA and REST<br />Photo by sylviaduckworth on Flickr,<br />
  10. 10. With SOA<br />Architecture will include a database to hold network data and services supporting following operations<br />ListNetworks()<br />NetworkDataGetNetworkData()<br />ApplyNetworkData(NetworkDataquearyParams)<br />SearchNetworks(String queryParams)<br />Notice Each operation is a Verb, users combine those verbs to do what he needs<br />Message formats are defined through a WSDL and each service supports one message format. <br />
  11. 11. With REST<br />Give everything a ID (URI)<br /><br /><br /><br />Things (resources) refer to each other <br />Retrieving a network will return something like <br /><Networks><br /><cse ref=“”/><br /> ….<br /></Networks><br />All interactions are done through four verbs (PUT, GET, DELETE, POST) on resources<br />GET on : Getting network data <br />POST on update the network config.<br />DELETE on can delete the network etc. <br />
  12. 12. With REST (Contd.)<br />Resources can return multiple formats<br />Results can return multiple formats, XML, Jason, Binary or several XML formats etc. <br />Clients send the header Accept: text/json, text/xml+foo defining supported formats, and the server returns result in a format client supports. This means a resource can support multiple formats at the same time. Also we can use this to support new formats later. <br />All communication is stateless – this is same for SOA and ROA<br />System can use HTTP style caching <br />
  13. 13. Implementing REST Services<br />Define the resources structure <br />Define many URLs for different types of resources<br />Use a REST engine to attach code to each URL patterns, they support four verbs (e.g. see<br />Code segment is for URL, verb, content type<br />Example<br />http://…/Networks:<br />On GET text/xml do<br />….<br />end<br />Photo by Kevin Dooley on Flickr,<br />
  14. 14. REST Anti-patterns<br />Verbs in URLs<br /><br />This is doing SOA using HTTP, not REST<br />Ignoring status codes on responses <br />Not including references in responses <br /><Networks><br /> <cse><br /> <nodeCount>..</nodeCount><br /> <subnetmask> ..</subnetmask><br /><cse><br /></Networks><br />Use references whenever that makes sense, do not copy data in to response. Remember the underline linked resource structure. <br />
  15. 15. REST, is it the Architecture to solve them all?<br />Does the REST a silver bullet for all problems<br />This is the source for most fights, the answer looks “No”. Some examples.<br />It does not have a contract (Lack a WSDL) <br />Messaging – does not talk about eventing/ messaging aspects. May be need a SUBSCRIBE verb added. <br />Asynchronous invocations and reliability<br />What about composition and transactions etc. mostly things come from WS-* <br />Does error messages are enough? <br />Photo by Playaduraon Flickr,<br />
  16. 16. So when to use it?<br />Use when REST is the natural choice <br />It is very good at representing resources <br />Not that good with processes/ executions <br />Same for SOA<br />Is it OK to mix it? <br />I would say yes, but not too much<br />WSO2 use REST for registry API, while SOA for many other places. <br />Photo by QUEEN YUNA on Flickr, (CC)<br />
  17. 17. Conclusion<br />What is a Distributed Application? <br />SOA and ROA as solutions <br />Detailed looked at ROA with a Example<br />It is the architecture that solves everything? “Look like we need both”<br />
  18. 18. For more information<br />Stefan Tilkov: A Brief Introduction to REST,<br />Stefan Tilkov: REST Anti-Patterns,<br />More articles here<br />SanjivaWeerawarana: WS-* vs. REST: Mashing up the Truth from Facts, Myths and Lies,<br />
  19. 19. Questions?<br />