REST in peace: a handbook of software waste @ Jazoon 2011 06-22-2011

2,282 views

Published on

A 20-minutes presentation I gave at the 2011 Jazoon conference in Zurich about RESTful architectures, REST antipatterns and how to implement scalability and adaptability in our systems.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,282
On SlideShare
0
From Embeds
0
Number of Embeds
103
Actions
Shares
0
Downloads
23
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

REST in peace: a handbook of software waste @ Jazoon 2011 06-22-2011

  1. 1. REST in peace A handbook of software wasteAlessandro NadalinDNSEE430 SPEAKER‘S COMPANY LOGO
  2. 2. AGENDA> Vol. 1: REST in a nutshell > Vol. 2: To the rescue – Tenets – HTTP cache – Antipatterns – ESI> WWW: a tremendous architecture – HATEOAS – Stateless > Vol. 3: REST is not a panacea – Layered – SOAP – Cacheable – Limited horizon – Fault-tolerant – Agile development – Failure-prone 2 SPEAKER‘S COMPANY LOGO
  3. 3. Sorry for the ugly slide. There will be others. Really sorry. SPEAKER‘S COMPANY LOGO
  4. 4. REST in a nutshell:1. Client <> Server SPEAKER‘S COMPANY LOGO
  5. 5. REST in a nutshell: 2. Stateless SPEAKER‘S COMPANY LOGO
  6. 6. REST in a nutshell: 3. Cacheable SPEAKER‘S COMPANY LOGO
  7. 7. REST in a nutshell:4. Layered system SPEAKER‘S COMPANY LOGO
  8. 8. REST in a nutshell: 5. Uniform interface SPEAKER‘S COMPANY LOGO
  9. 9. And obviously nobody had a clue 9 SPEAKER‘S COMPANY LOGO
  10. 10. ANTIPATTERNS 10 SPEAKER‘S COMPANY LOGO
  11. 11. 1 URIsSPEAKER‘S COMPANY LOGO
  12. 12. "REST is about cool URI design"http://apple.com/users/1/licenses/4.json SPEAKER‘S COMPANY LOGO
  13. 13. "REST is about cool URI design"http://apple.com/users/1/licenses/4.json SPEAKER‘S COMPANY LOGO
  14. 14. http://apple.com/site/en_US/showUsers.jsp?uid=1&license=4 is OK too SPEAKER‘S COMPANY LOGO
  15. 15. butSPEAKER‘S COMPANY LOGO
  16. 16. cool URIs help youthink in term of resources David Zuelke SPEAKER‘S COMPANY LOGO
  17. 17. 2URIs (bis)SPEAKER‘S COMPANY LOGO
  18. 18. REST follows a URI schema GET /users POST /users PUT /users/{id} DELETE /users/{id} ... SPEAKER‘S COMPANY LOGO
  19. 19. REST follows a URI schema GET /users POST /users PUT /users/{id} DELETE /users/{id} ... SPEAKER‘S COMPANY LOGO
  20. 20. what if you change your URL? SPEAKER‘S COMPANY LOGO
  21. 21. Yeah,client isbroken SPEAKER‘S COMPANY LOGO
  22. 22. RESTful clients should be driven by services hypermedia controlsRoy Fielding : http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven SPEAKER‘S COMPANY LOGO
  23. 23. HATEOAS SPEAKER‘S COMPANY LOGO
  24. 24. 3POST is cool SPEAKER‘S COMPANY LOGO
  25. 25. said SOAP SPEAKER‘S COMPANY LOGO
  26. 26. said SOAP SPEAKER‘S COMPANY LOGO
  27. 27. loosing meaningful verbs at the protocol level SPEAKER‘S COMPANY LOGO
  28. 28. loosing meaningful verbs at the protocol level nothing cacheable by default SPEAKER‘S COMPANY LOGO
  29. 29. loosing meaningful verbs at the protocol level nothing cacheable by default what about bookmarking? SPEAKER‘S COMPANY LOGO
  30. 30. Have a break 30SPEAKER‘S COMPANY LOGO
  31. 31. The WWW 31 SPEAKER‘S COMPANY LOGO
  32. 32. the largest data-exchange network on the planet 32 SPEAKER‘S COMPANY LOGO
  33. 33. And meanwhile, at Facebook...12TB of new data every day (1 year ago) 500 million users 33 SPEAKER‘S COMPANY LOGO
  34. 34. via HTTP , baby! 34 SPEAKER‘S COMPANY LOGO
  35. 35. HTTP in a nutshell:1. Client <> Server SPEAKER‘S COMPANY LOGO
  36. 36. HTTP in a nutshell: 2. Stateless SPEAKER‘S COMPANY LOGO
  37. 37. HTTP in a nutshell:3. widespread cache spec http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html SPEAKER‘S COMPANY LOGO
  38. 38. HTTP in a nutshell: Lao Tze Song offices laptop Company proxy Great chinese (fire)wall Reverse proxy Origin server4. Layered system SPEAKER‘S COMPANY LOGO
  39. 39. HTTP in a nutshell: 5. it is the uniform interface between clients and servers SPEAKER‘S COMPANY LOGO
  40. 40. HTTP bleeds REST 40 SPEAKER‘S COMPANY LOGO
  41. 41. Vol.2 Implementing all this goodnessSPEAKER‘S COMPANY LOGO
  42. 42. 1.caching & scalability SPEAKER‘S COMPANY LOGO
  43. 43. Caching with Expiration SPEAKER‘S COMPANY LOGO
  44. 44. HTTP/1.1 200 OKHost: www.example.comExpires: 0 SPEAKER‘S COMPANY LOGO
  45. 45. HTTP/1.1 200 OKHost: www.example.comExpires: 0 SPEAKER‘S COMPANY LOGO
  46. 46. HTTP/1.1 200 OKHost: www.example.comExpires: Tue, 31 Jan 2011 01:00 GMT SPEAKER‘S COMPANY LOGO
  47. 47. HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public SPEAKER‘S COMPANY LOGO
  48. 48. HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public SPEAKER‘S COMPANY LOGO
  49. 49. HTTP/1.1 200 OKHost: www.example.comCache-Control: max-age=60, public Cacheable for 60 seconds SPEAKER‘S COMPANY LOGO
  50. 50. GET / HTTP/1.1Host: www.example.comCache-Control: max-age=60, publicCacheable by both local and shared caches SPEAKER‘S COMPANY LOGO
  51. 51. HTTP/1.1 200 OKHost: www.example.comCache-Control: stale-if-error=600, stale-while-revalidate=600 SPEAKER‘S COMPANY LOGO
  52. 52. HTTP/1.1 200 OKHost: www.example.comCache-Control: stale-if-error=600, stale-while-revalidate=600 fault-tolerant SPEAKER‘S COMPANY LOGO
  53. 53. HTTP/1.1 200 OKHost: www.example.comCache-Control: stale-if-error=600, stale-while-revalidate=600 available during downtime SPEAKER‘S COMPANY LOGO
  54. 54. HTTP/1.1 200 OKHost: www.example.comCache-Control: stale-if-error=600, stale-while-revalidate=600 available during revalidation SPEAKER‘S COMPANY LOGO
  55. 55. Caching with Validation SPEAKER‘S COMPANY LOGO
  56. 56. HTTP/1.1 200 OKHost: www.example.comEtag: 1234 SPEAKER‘S COMPANY LOGO
  57. 57. HTTP/1.1 200 OK Host: www.example.com Etag: 1234an identifier for your response SPEAKER‘S COMPANY LOGO
  58. 58. Conditional requests GET / HTTP/1.1 Host: www.example.com If-None-Match: 1234the browsers asks you if it has been modified SPEAKER‘S COMPANY LOGO
  59. 59. HTTP/1.1 304 Not Modified SPEAKER‘S COMPANY LOGO
  60. 60. Calculating an Etag is cheaper than generating a full MVC response SPEAKER‘S COMPANY LOGO
  61. 61. but hey, you saySPEAKER‘S COMPANY LOGO
  62. 62. HTTPs cache fails when dealing with really dynamicpages, because consumers will always have to hit the origin server, although a part of the page would be cacheable ( header and footer, for example ) SPEAKER‘S COMPANY LOGO
  63. 63. Nope NopeSPEAKER‘S COMPANY LOGO
  64. 64. ESI was built for that http://www.w3.org/TR/esi-lang SPEAKER‘S COMPANY LOGO
  65. 65. Edge Side IncludesServer side includes ( not SSI! ) usually handled by the architectures ESI processor. http://www.w3.org/TR/esi-lang http://www.w3.org/TR/edge-arch SPEAKER‘S COMPANY LOGO
  66. 66. <esi:include src="http://jazoon.com/talks/1" /> SPEAKER‘S COMPANY LOGO
  67. 67. <esi:include src="http://jazoon.com/talks/1" /> SPEAKER‘S COMPANY LOGO
  68. 68. <esi:include src="http://jazoon.com/talks/1" /> SPEAKER‘S COMPANY LOGO
  69. 69. 15 seconds cache1 day cache SPEAKER‘S COMPANY LOGO
  70. 70. <esi:include src=tweets.html /><esi:include src=footer.html /> SPEAKER‘S COMPANY LOGO
  71. 71. and hey, Varnish is a reverse proxy implementing what you need of the ESI specification take 2, pay for 1 SPEAKER‘S COMPANY LOGO
  72. 72. So what does HTTP cache is meant to solve? SPEAKER‘S COMPANY LOGO
  73. 73. Less work SPEAKER‘S COMPANY LOGO
  74. 74. http://www.flickr.com/photos/snakphotography/5004775320/sizes/o/in/photostream/ because the hard work is delegated to the browser/proxy SPEAKER‘S COMPANY LOGO
  75. 75. evolveSPEAKER‘S COMPANY LOGO
  76. 76. because cache is abstracted from the application SPEAKER‘S COMPANY LOGO
  77. 77. loose coupling SPEAKER‘S COMPANY LOGO
  78. 78. because caching is bound to the protocol, HTTP, notto your implementation ( Sf, RoR, Django ) SPEAKER‘S COMPANY LOGO
  79. 79. 2.adaptability & durability SPEAKER‘S COMPANY LOGO
  80. 80. Hypermedia another long-time friend SPEAKER‘S COMPANY LOGO
  81. 81. Linksoutrageously semplifying SPEAKER‘S COMPANY LOGO
  82. 82. <link rel="payment" href="/checkout" type="text/html" ... /> SPEAKER‘S COMPANY LOGO
  83. 83. <link rel="payment" href="/checkout" type="text/html" ... /> SPEAKER‘S COMPANY LOGO
  84. 84. <link rel="payment" href="/checkout" type="text/html" ... /> SPEAKER‘S COMPANY LOGO
  85. 85. <link rel="payment" href="/checkout" type="text/html" ... /> SPEAKER‘S COMPANY LOGO
  86. 86. POST /users Host: www.example.comHTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /users/1 SPEAKER‘S COMPANY LOGO
  87. 87. POST /users Host: www.example.comHTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /users/1 SPEAKER‘S COMPANY LOGO
  88. 88. POST /users Host: www.example.comHTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /new-users-db/1 SPEAKER‘S COMPANY LOGO
  89. 89. POST /users Host: www.example.comHTTP/1.1 201 CreatedHost: www.example.comEtag: 1234X-Powered-By: php/5.3Location: /new-users-db/1 SPEAKER‘S COMPANY LOGO
  90. 90. consumers of your API are able to follow the changes of your design SPEAKER‘S COMPANY LOGO
  91. 91. everything seems coolBut why REST? SPEAKER‘S COMPANY LOGO
  92. 92. ProsPerformances SPEAKER‘S COMPANY LOGO
  93. 93. ProsScalability SPEAKER‘S COMPANY LOGO
  94. 94. SPEAKER‘S COMPANY LOGO
  95. 95. Pros DurabilitySPEAKER‘S COMPANY LOGO
  96. 96. "REST is software design on the scale of decades: every detail is intended topromote software longevity and independent evolution. Many of the constraints are directly opposed to short-term efficiency. Unfortunately, people are fairly good at short-term design, and usually awful at long-term design. " Roy Fielding SPEAKER‘S COMPANY LOGO
  97. 97. Put a bit of RESTeverywhere SPEAKER‘S COMPANY LOGO
  98. 98. Rules ofgood design SPEAKER‘S COMPANY LOGO
  99. 99. Use natives =Eliminate waste SPEAKER‘S COMPANY LOGO
  100. 100. The wheel!HTTP - 1991~1997 REST - 2000 SPEAKER‘S COMPANY LOGO
  101. 101. Vol.3 REST is not a panaceaSPEAKER‘S COMPANY LOGO
  102. 102. SOAPNo need to re-invent the wheel: if you need to do SOAP integration, SOAP is the way.If you have a completely functional SOAP service, no - apparent - need to rewrite it RESTful from scratch. SPEAKER‘S COMPANY LOGO
  103. 103. AGILEThe last responsible moment conflicts with REST. But quality enhance agility: REST is quality. SPEAKER‘S COMPANY LOGO
  104. 104. LIMITEDHORIZON My blog wont ever be RESTful.But incremental design, bare it in mind. SPEAKER‘S COMPANY LOGO
  105. 105. Alessandro Nadalin odino.orgDNSEE @_odino_Rome github.com/odino SPEAKER‘S COMPANY LOGO
  106. 106. Credits http://www.flickr.com/photos/larachris/16564077/sizes/o/in/photostream/ http://www.flickr.com/photos/ashatenbroeke/4367373081/sizes/z/in/photostream/ http://www.flickr.com/photos/yourdon/3140270189/sizes/l/in/photostream/ http://www.flickr.com/photos/jox1989/4964706072/sizes/l/in/photostream/ http://www.flickr.com/photos/brainfg/168506259/sizes/o/in/photostream/ http://www.flickr.com/photos/norte_it/3897091546/sizes/o/in/photostream/ http://www.zdnet.com/blog/service-oriented/soap-versus-rest-a-matter-of-style/3568http://www.flickr.com/photos/turtlemom_nancy/2046347762/sizes/l/in/photostream/ http://www.flickr.com/photos/juanpg/3333385784/sizes/z/in/photostream/ http://www.flickr.com/photos/congvo/301678287/sizes/l/in/photostream/ http://www.flickr.com/photos/ihasb33r/2573196546/sizes/z/in/photostream/ http://www.flickr.com/photos/martin_heigan/4544138976/sizes/o/in/photostream/ http://www.flickr.com/photos/cknara/4195099999/sizes/o/in/photostream/ http://www.flickr.com/photos/1080p/3076529265/sizes/l/in/photostream/ http://www.flickr.com/photos/adamrice/280300202/sizes/l/in/photostream/ http://www.flickr.com/photos/tomer_a/541411897/sizes/o/in/photostream/ http://www.flickr.com/photos/subpra/4514008262/sizes/l/in/photostream/ http://www.flickr.com/photos/lippincott/2539720043/sizes/l/in/photostream/ http://www.flickr.com/photos/rawryder/5086090931/sizes/l/in/photostream/ http://www.flickr.com/photos/robboudon/5312731161/sizes/l/in/photostream/ http://www.flickr.com/photos/bc-burnslibrary/4158243488/sizes/o/in/photostream/http://www.flickr.com/photos/13606325@N08/2416993706/sizes/o/in/photostream/ http://www.flickr.com/photos/neothezion/5135841069/sizes/l/in/photostream/ http://www.flickr.com/photos/planetschwa/2494067809/ http://www.flickr.com/photos/thomasthomas/258931782/ http://www.flickr.com/photos/rustyboxcars/2629631562/sizes/l/in/photostream/ http://www.flickr.com/photos/ell-r-brown/4138727474/sizes/l/in/photostream/ http://www.flickr.com/photos/noah123/5082076630/sizes/z/in/photostream/ http://www.flickr.com/photos/jungle_boy/220181177/sizes/l/in/photostream/ http://www.flickr.com/photos/prettydaisies/872539081/sizes/l/in/photostream/ http://www.flickr.com/photos/kaptainkobold/76256150/sizes/o/in/photostream/ http://www.flickr.com/photos/uomoincravatta/1438372865/sizes/z/in/photostream/ SPEAKER‘S COMPANY LOGO

×