CouchApps: Requiem for Accidental Complexity

7,308 views

Published on

Talk i gave at Nosqlday with Giordano Scalzo on March 25th 2011.
It's about how CouchDB can replace a full serverside mvc stack making development of simple web apps a piece of cake

Also
http://federico.galassi.net/
http://www.nosqlday.it/
http://couchdb.apache.org/

Follow me on Twitter!
https://twitter.com/federicogalassi

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
7,308
On SlideShare
0
From Embeds
0
Number of Embeds
26
Actions
Shares
0
Downloads
46
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

CouchApps: Requiem for Accidental Complexity

  1. 1. CouchApps: Requiem for Accidental Complexity Federico Galassi Giordano Scalzo
  2. 2. We have a problem...
  3. 3. Writing software is really hard...
  4. 4. A little bit of history
  5. 5. It wasn’t easy
  6. 6. A little bit better
  7. 7. Something happened
  8. 8. A different way of programming
  9. 9. Two tiers architectureBusiness Logic + Data Presentation
  10. 10. Three tiers architecturePresentation Business Logic Data
  11. 11. Tim Berners Leeinvented the world wide web
  12. 12. Three tiers internet style View + Model ControllerThin client
  13. 13. Evolution ofMVC Web App
  14. 14. Browser is a thin client
  15. 15. Talking to asmart server
  16. 16. It all starts withan HTTP request GET / HTTP/1.1 Host: example.org
  17. 17. It hits theController
  18. 18. Web server parses it Controller
  19. 19. Dispatch tofront controller Controller
  20. 20. Routing Controller
  21. 21. Custom action Controller
  22. 22. Gets datafrom Model
  23. 23. Query onmodel objects Model
  24. 24. ORM fits into SQL Model
  25. 25. Hits a RDBMS Model
  26. 26. Populates a View
  27. 27. Template engine View
  28. 28. HTML back to the server View
  29. 29. HTML back to the client HTTP/1.1 200 OK
  30. 30. That’s MVC Model View Controller
  31. 31. A little bit old school
  32. 32. We love AJAX speed
  33. 33. Just need an API Model View Json View Controller Api Action
  34. 34. And somejavascript on client Model View Json View Javascript View Controller Api Action
  35. 35. Niceone ring to rule ‘em all
  36. 36. Nocontraindications ?
  37. 37. Accidentalcomplexity
  38. 38. Every changetouches the server
  39. 39. Hard to scale We must add another serveeeeerrrr
  40. 40. Last technology cycle WE WERE HERE MVC peak  of inflated expectationVisibility productivity disillusionment obsolescence technology trigger maturity
  41. 41. Last technology cycle peak  of inflated expectation NOW HEREVisibility productivity disillusionment obsolescence technology trigger maturity
  42. 42. Last technology cycle peak  of inflated expectation IF YOU’REVisibility AT THIS CONF productivity YOU MAY BE ALREADY HERE disillusionment obsolescence technology trigger maturity
  43. 43. Next technology to save us? ? Visibility maturity
  44. 44. It’s a cycle but we know one thing ...Visibility maturity
  45. 45. Specialization is Good
  46. 46. Very opinionated document DB
  47. 47. Very good forsome problems
  48. 48. A document DB{        "company":  "CleanCode",        "members":  [                {  "name":  "Gabriele  Lana",  "role":  "software  craftsman"},                {  "name":  "Federico  Galassi",  "role":  "software  craftsman"},                {  "name":  "Giordano  Scalzo",  "role":  "software  craftsman"}        ]}
  49. 49. Self contained data INS J O NO
  50. 50. Schema-less data DATA YO UR VO LVE E
  51. 51. Incremental Reduce: sum(checkouts) Map/Reduce 430Re-reduce 142 288 Reduce 100 42 215 73 { { { { Map "id": 1, "day": 20100123, "checkout": 100 "id": 2, "day": 20100123, "checkout": 42 "id": 3, "day": 20100123, "checkout": 215 "id": 4, "day": 20100123, "checkout": 73 } } } }
  52. 52. Multi-VersionConcurrency Control
  53. 53. Crash-only architecturelucky by design
  54. 54. A distributed DB
  55. 55. Eventualconsistency
  56. 56. Incremental replication
  57. 57. Automatic conflict resolution
  58. 58. Built of the Web“Django may be built for the Web,but CouchDB is built of the Web.I’ve never seen software that so Jacob Kaplan-Mosscompletely embraces the Co-creator of Djangophilosophies behind HTTP.”
  59. 59. Restful APIGET / Returns  MOTDGET /_all_dbs List  of  databasesPOST /_restart Restart  the  serverGET /_log Tail  of  the  server’s  logGET /_config Entire  server  configGET /_config/<section>/<key> Single  config  valuePUT /_config/<section>/<key> Set  a  single  config  valueGET /<db> Database  infoPUT /<db> Create  new  databaseDELETE /<db> Delete  databaseGET /<db>/<doc> Latest  revision  of  the  documentPUT /<db>/<doc> Insert  a  new  revision  of  the  document ... and everything else
  60. 60. Javascript to program//  MAPfunction(doc)  {    if(doc.date  &&  doc.title)  {        emit(doc.date,  doc.title);    }}
  61. 61. JSON to exchange data{    "_id":"hello-­‐world",    "_rev":"43FBA4E7AB",    "title":"Hello  World",    "body":"Well  hello  and  welcome  to  my  new  blog...",    "date":"2009/01/15  15:52:20"}
  62. 62. Applications are documents
  63. 63. Replication as deploy
  64. 64. A modern webapplication server
  65. 65. CouchApps are javascript and html5 applications serveddirectly from CouchDB
  66. 66. Problem Model View Json ViewJavascript View Controller Api Action
  67. 67. Simple Solution HTTPJavascript View
  68. 68. Experiment:5 minutes comet chat
  69. 69. The couchapp tool
  70. 70. Generate the app
  71. 71. Configure the app
  72. 72. Deploy the app
  73. 73. That’s it
  74. 74. That’s it
  75. 75. User can post a messageAdd form elements
  76. 76. User can post a messageOn click POST message to couch
  77. 77. User can post a message Yes!
  78. 78. User gets a stream of messagesAdd messages container
  79. 79. User gets a stream of messages
  80. 80. User gets a stream of messages Yes!
  81. 81. Validation?
  82. 82. Authentication?
  83. 83. Authentication?Create a user
  84. 84. Authentication?Add Form Elements
  85. 85. Authentication?HTTP Basic Auth
  86. 86. Authentication?If it goes wrong
  87. 87. Authentication?Check sender is the authenticated user
  88. 88. Authentication?{ sender: “whitehouse” } // spoofing
  89. 89. Authentication? Yes!
  90. 90. BASIC HTTP ?????No SSLYes cookie authvia _session api
  91. 91. UGLY URLS ????? Rewrites and Virtual hosts
  92. 92. Easy eh?
  93. 93. But it’s not that ring
  94. 94. Very good forCRUD/small/simple web
  95. 95. federico.galassi@cleancode.it giordano.scalzo@cleancode.ittwitter.com/federicogalassi twitter.com/giordanoscalzoslideshare.net/fgalassi slideshare.net/giordano

×