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.

Sergi Mansilla

October 22, 2012
Tweet

More Decks by Sergi Mansilla

Other Decks in Programming

Transcript

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

    ☐ Lessons learned Monday, October 22, 12
  2. Program ☑ Cloud9 IDE? ☐ Growing pains ☐ Introducing Architect

    ☐ Lessons learned Monday, October 22, 12
  3. duplicated modules maps to folder names Relies on FS require

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

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

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

    ☐ Lessons learned Monday, October 22, 12
  7. Architect Everything is a plugin Plugins can consume plugins An

    application is just a set of plugins Monday, October 22, 12
  8. Dependency error handling Architect coding time compile time run time

    - Happy customers - Developer keeps job - Fails before release Monday, October 22, 12
  9. What’s next? Extract the code Wrap in Architect plugin code

    Make two plugins Monday, October 22, 12
  10. Architect plugin code Module.exports Options - we’ll get to that

    Imports - everything you ‘consume’ Register - invoke when done Monday, October 22, 12
  11. No black magic Specify dependency model Feed architect a config

    file Call ‘createApp’ Monday, October 22, 12
  12. Options Automatically passed in at startup Options are also dependencies

    Fail if options aren’t present Monday, October 22, 12
  13. Architect makes you think of your app as chunks of

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

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

    (OS + sync) Hosted version Normal FTP SSH Monday, October 22, 12
  16. 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
  17. IDE instance (FTP) IDE instance (SSH) IDE instance (Normal) IDE

    instance (Normal) Single node.js process Other code (dashboard etc.) Monday, October 22, 12
  18. Architect can do Multiple instances of same plugin Run independently

    But in the same process Monday, October 22, 12
  19. Centralized eventbus Loose coupling between plugins No hard dependencies! Can

    also do inter-context communication Monday, October 22, 12
  20. 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
  21. Program ☑ Cloud9 IDE? ☑ Growing pains ☑ Introducing Architect

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

    small blocks They aren’t interfaces! Monday, October 22, 12