Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Architecting large node.js applications

Architecting large node.js applications

Sergi Mansilla introduces one of the main components to hold Cloud9's architecture together: Architect.

B083b8207ccd0744a5abb18c8e75d24d?s=128

Sergi Mansilla

October 22, 2012
Tweet

More Decks by Sergi Mansilla

Other Decks in Programming

Transcript

  1. large Architecting node.js applications Monday, October 22, 12

  2. @sergimansilla Monday, October 22, 12

  3. Program ☐ Cloud9 IDE? ☐ Growing pains ☐ Introducing Architect

    ☐ Lessons learned Monday, October 22, 12
  4. Normal developers Monday, October 22, 12

  5. JavaScript Developer Monday, October 22, 12

  6. Cloud9 IDE - http://c9.io Monday, October 22, 12

  7. debugging Real Monday, October 22, 12

  8. (Smart!) Code completion Monday, October 22, 12

  9. analysis Static Monday, October 22, 12

  10. Free Linux VM Monday, October 22, 12

  11. Bring your own machine Monday, October 22, 12

  12. Real terminal Monday, October 22, 12

  13. Collaboration Monday, October 22, 12

  14. See each other type Debug together Productivity++ Monday, October 22,

    12
  15. Create Share Test Deploy Run/Debug Monday, October 22, 12

  16. Program ☑ Cloud9 IDE? ☐ Growing pains ☐ Introducing Architect

    ☐ Lessons learned Monday, October 22, 12
  17. 10,000s of JavaScript LOC Monday, October 22, 12

  18. dynamic, typed weakly language Monday, October 22, 12

  19. one thread single Monday, October 22, 12

  20. Remote VM Cloud9 datacenter IDE server Remote VM Remote VM

    Openshift Monday, October 22, 12
  21. Pure madness Monday, October 22, 12

  22. Modularization Monday, October 22, 12

  23. Black box coding Monday, October 22, 12

  24. Monday, October 22, 12

  25. Java/.NET Node.js import(s) require Monday, October 22, 12

  26. abstracting away Great for require Monday, October 22, 12

  27. application modularity Not Great for require Monday, October 22, 12

  28. duplicated modules maps to folder names Relies on FS require

    Hard to configure module Monday, October 22, 12
  29. Dependency error handling coding time compile time run time KA-BOOM!

    - Server crash - Unhappy customers - Developer gets fired Monday, October 22, 12
  30. How to fix it? Static dependency list Named services Easy

    configuration Resolve at startup No FS required Pass an object Monday, October 22, 12
  31. Program ☑ Cloud9 IDE? ☑ Growing pains ☐ Introducing Architect

    ☐ Lessons learned Monday, October 22, 12
  32. Architect github.com/c9/architect Monday, October 22, 12

  33. Architect Everything is a plugin Plugins can consume plugins An

    application is just a set of plugins Monday, October 22, 12
  34. Dependency model require Architect runtime compile time Monday, October 22,

    12
  35. Dependency error handling Architect coding time compile time run time

    - Happy customers - Developer keeps job - Fails before release Monday, October 22, 12
  36. Monday, October 22, 12

  37. Declare entity ‘presenter’ with behavior Use ‘presenter’ to do a

    presentation Monday, October 22, 12
  38. Presenter Presentation Dependency model Monday, October 22, 12

  39. Express our model package.json Builds dependency tree executing code without

    Monday, October 22, 12
  40. Monday, October 22, 12

  41. What’s next? Extract the code Wrap in Architect plugin code

    Make two plugins Monday, October 22, 12
  42. Function signature Call when done Monday, October 22, 12

  43. Architect plugin code Module.exports Options - we’ll get to that

    Imports - everything you ‘consume’ Register - invoke when done Monday, October 22, 12
  44. Monday, October 22, 12

  45. Monday, October 22, 12

  46. Easy to test Mock dependencies Monday, October 22, 12

  47. Assert ‘dance’ is called 11 times Monday, October 22, 12

  48. No black magic Specify dependency model Feed architect a config

    file Call ‘createApp’ Monday, October 22, 12
  49. Monday, October 22, 12

  50. Monday, October 22, 12

  51. Configuration Per-plugin options No global options object Specify in config

    file Monday, October 22, 12
  52. Monday, October 22, 12

  53. Monday, October 22, 12

  54. Options Automatically passed in at startup Options are also dependencies

    Fail if options aren’t present Monday, October 22, 12
  55. Monday, October 22, 12

  56. Monday, October 22, 12

  57. Architect makes you think of your app as chunks of

    functionality rather than sets of classes Monday, October 22, 12
  58. Think ‘chunks of functionality’ Implicit type constraints Keep implementation private

    Swap features instead of interfaces Monday, October 22, 12
  59. How does Cloud9 use it? Open source version Local version

    (OS + sync) Hosted version Normal FTP SSH Monday, October 22, 12
  60. Monday, October 22, 12

  61. Swap feature per implementation On Open source: talk local filesystem

    On FTP: talk FTP library On SSH: talk via a SSH bridge Monday, October 22, 12
  62. Here is something your DI framework can’t do Monday, October

    22, 12
  63. IDE instance (FTP) IDE instance (SSH) IDE instance (Normal) IDE

    instance (Normal) Single node.js process Other code (dashboard etc.) Monday, October 22, 12
  64. Monday, October 22, 12

  65. Architect can do Multiple instances of same plugin Run independently

    But in the same process Monday, October 22, 12
  66. Monday, October 22, 12

  67. Monday, October 22, 12

  68. HERE’S SOMETHING COOL Monday, October 22, 12

  69. Centralized eventbus Loose coupling between plugins No hard dependencies! Can

    also do inter-context communication Monday, October 22, 12
  70. Event bus Plugin Other plugin Emit event React on event

    Monday, October 22, 12
  71. Monday, October 22, 12

  72. Monday, October 22, 12

  73. And now scale up Need something inter-server Swap it with

    i.e. Redis PubSub Plugins will never notice Modular awesomeness! Monday, October 22, 12
  74. Program ☑ Cloud9 IDE? ☑ Growing pains ☑ Introducing Architect

    ☐ Lessons learned Monday, October 22, 12
  75. Modularize in feature blocks Don’t over engineer Don’t create too

    small blocks They aren’t interfaces! Monday, October 22, 12
  76. Use dependency injection Architect (JavaScript) StructureMap (.NET) Spring (Java) Monday,

    October 22, 12
  77. Avoid context switching Less code! Less errors! Less boilerplate! Monday,

    October 22, 12
  78. Loose coupling Use an event bus Smaller dependency graph Monday,

    October 22, 12
  79. github.com/c9/architect Monday, October 22, 12

  80. Happy coding! Monday, October 22, 12

  81. Sergi Mansilla @sergimansilla github.com/sergi http://c9.io Monday, October 22, 12