architecting large node.js applications

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

Upload: sergi-mansilla

Post on 11-May-2015

22.627 views

Category:

Technology


3 download

DESCRIPTION

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

TRANSCRIPT

Page 1: Architecting large Node.js applications

largeArchitecting

node.jsapplications

Monday, October 22, 12

Page 2: Architecting large Node.js applications

@sergimansilla

Monday, October 22, 12

Page 3: Architecting large Node.js applications

P r o g r a m

☐ C l o u d 9 I D E ?

☐ G r o w i n g p a i n s

☐ I n t r o d u c i n g A r c h i te c t

☐ Le s s o n s l e a r n e d

Monday, October 22, 12

Page 4: Architecting large Node.js applications

Normal developers

Monday, October 22, 12

Page 5: Architecting large Node.js applications

JavaScript Developer

Monday, October 22, 12

Page 6: Architecting large Node.js applications

Cloud9 IDE - http://c9.io

Monday, October 22, 12

Page 7: Architecting large Node.js applications

debuggingReal

Monday, October 22, 12

Page 8: Architecting large Node.js applications

(Smart!)Code completion

Monday, October 22, 12

Page 9: Architecting large Node.js applications

analysisStatic

Monday, October 22, 12

Page 10: Architecting large Node.js applications

FreeLinux VM

Monday, October 22, 12

Page 11: Architecting large Node.js applications

Bring your own machineMonday, October 22, 12

Page 12: Architecting large Node.js applications

Real terminal

Monday, October 22, 12

Page 13: Architecting large Node.js applications

Collaboration

Monday, October 22, 12

Page 14: Architecting large Node.js applications

See each other typeDebug togetherProductivity++

Monday, October 22, 12

Page 15: Architecting large Node.js applications

Create

Share Test

Deploy Run/Debug

Monday, October 22, 12

Page 16: Architecting large Node.js applications

P r o g r a m

☑ C l o u d 9 I D E ?

☐ G r o w i n g p a i n s

☐ I n t r o d u c i n g A r c h i te c t

☐ Le s s o n s l e a r n e d

Monday, October 22, 12

Page 17: Architecting large Node.js applications

10,000s

of JavaScriptLOC

Monday, October 22, 12

Page 18: Architecting large Node.js applications

dynamic,typedweakly

languageMonday, October 22, 12

Page 19: Architecting large Node.js applications

onethreadsingle

Monday, October 22, 12

Page 20: Architecting large Node.js applications

Remote VM

Cloud9 datacenter

IDE server Remote VM

Remote VM

Openshift

Monday, October 22, 12

Page 21: Architecting large Node.js applications

Pure madness

Monday, October 22, 12

Page 22: Architecting large Node.js applications

ModularizationMonday, October 22, 12

Page 23: Architecting large Node.js applications

Blackboxcoding

Monday, October 22, 12

Page 24: Architecting large Node.js applications

Monday, October 22, 12

Page 25: Architecting large Node.js applications

Java/.NET

Node.js

import(s)

require

Monday, October 22, 12

Page 26: Architecting large Node.js applications

abstractingawayGreat for

require

Monday, October 22, 12

Page 27: Architecting large Node.js applications

applicationmodularity

Not Great forrequ

ire

Monday, October 22, 12

Page 28: Architecting large Node.js applications

duplicated modulesmaps to folder names

Relies on FSrequ

ire

Hard to configure module

Monday, October 22, 12

Page 29: Architecting large Node.js applications

Dependency error handling

coding time compile time run time

KA-BO

OM!

- Server crash- Unhappy customers- Developer gets fired

Monday, October 22, 12

Page 30: Architecting large Node.js applications

How to fix it?

Static dependency list

Named services

Easy configuration

Resolve at startup

No FS required

Pass an object

Monday, October 22, 12

Page 31: Architecting large Node.js applications

P r o g r a m

☑ C l o u d 9 I D E ?

☑ G r o w i n g p a i n s

☐ I n t r o d u c i n g A r c h i te c t

☐ Le s s o n s l e a r n e d

Monday, October 22, 12

Page 32: Architecting large Node.js applications

Architect

github.com/c9/architect

Monday, October 22, 12

Page 33: Architecting large Node.js applications

Architect

Everything is a plugin

Plugins can consume plugins

An application is just a set of plugins

Monday, October 22, 12

Page 34: Architecting large Node.js applications

Dependency model

require

Architect

runtime

compile time

Monday, October 22, 12

Page 35: Architecting large Node.js applications

Dependency error handlingArchitect

coding time compile time run time

- Happy customers- Developer keeps job- Fails before release

Monday, October 22, 12

Page 36: Architecting large Node.js applications

Monday, October 22, 12

Page 37: Architecting large Node.js applications

Declare entity ‘presenter’ with behaviorUse ‘presenter’ to do a presentation

Monday, October 22, 12

Page 38: Architecting large Node.js applications

Presenter Presentation

Dependency model

Monday, October 22, 12

Page 39: Architecting large Node.js applications

Express our model

package.json

Builds dependency tree

executing codewithout

Monday, October 22, 12

Page 40: Architecting large Node.js applications

Monday, October 22, 12

Page 41: Architecting large Node.js applications

What’s next?

Extract the codeWrap in Architect plugin code

Make two plugins

Monday, October 22, 12

Page 42: Architecting large Node.js applications

Function signature

Call when done

Monday, October 22, 12

Page 43: Architecting large Node.js applications

Architect plugin code

Module.exportsOptions - we’ll get to thatImports - everything you ‘consume’Register - invoke when done

Monday, October 22, 12

Page 44: Architecting large Node.js applications

Monday, October 22, 12

Page 45: Architecting large Node.js applications

Monday, October 22, 12

Page 46: Architecting large Node.js applications

Easy to testMock dependencies

Monday, October 22, 12

Page 47: Architecting large Node.js applications

Assert ‘dance’ is called 11 times

Monday, October 22, 12

Page 48: Architecting large Node.js applications

No black magic

Specify dependency modelFeed architect a config file

Call ‘createApp’

Monday, October 22, 12

Page 49: Architecting large Node.js applications

Monday, October 22, 12

Page 50: Architecting large Node.js applications

Monday, October 22, 12

Page 51: Architecting large Node.js applications

Configuration

Per-plugin optionsNo global options objectSpecify in config file

Monday, October 22, 12

Page 52: Architecting large Node.js applications

Monday, October 22, 12

Page 53: Architecting large Node.js applications

Monday, October 22, 12

Page 54: Architecting large Node.js applications

Options

Automatically passed in at startupOptions are also dependencies

Fail if options aren’t present

Monday, October 22, 12

Page 55: Architecting large Node.js applications

Monday, October 22, 12

Page 56: Architecting large Node.js applications

Monday, October 22, 12

Page 57: Architecting large Node.js applications

Architect makes you think of your app as chunks of functionality

rather than sets of classes

Monday, October 22, 12

Page 58: Architecting large Node.js applications

Think ‘chunks of functionality’

Implicit type constraintsKeep implementation private

Swap features instead of interfaces

Monday, October 22, 12

Page 59: Architecting large Node.js applications

How does Cloud9 use it?

Open source version

Local version (OS + sync)

Hosted version

Normal

FTP

SSH

Monday, October 22, 12

Page 60: Architecting large Node.js applications

Monday, October 22, 12

Page 61: Architecting large Node.js applications

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

Page 62: Architecting large Node.js applications

Here is something your DI framework can’t do

Monday, October 22, 12

Page 63: Architecting large Node.js applications

IDE instance(FTP)

IDE instance(SSH)

IDE instance(Normal)

IDE instance(Normal)

Single node.js process

Other code (dashboard etc.)

Monday, October 22, 12

Page 64: Architecting large Node.js applications

Monday, October 22, 12

Page 65: Architecting large Node.js applications

Architect can do

Multiple instances of same pluginRun independently

But in the same process

Monday, October 22, 12

Page 66: Architecting large Node.js applications

Monday, October 22, 12

Page 67: Architecting large Node.js applications

Monday, October 22, 12

Page 68: Architecting large Node.js applications

HERE’S SOMETHING COOL

Monday, October 22, 12

Page 69: Architecting large Node.js applications

Centralized eventbus

Loose coupling between plugins

No hard dependencies!

Can also do inter-context communication

Monday, October 22, 12

Page 70: Architecting large Node.js applications

Eventbus

Plugin

Other plugin

Emit event

React on event

Monday, October 22, 12

Page 71: Architecting large Node.js applications

Monday, October 22, 12

Page 72: Architecting large Node.js applications

Monday, October 22, 12

Page 73: Architecting large Node.js applications

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

Page 74: Architecting large Node.js applications

P r o g r a m

☑ C l o u d 9 I D E ?

☑ G r o w i n g p a i n s

☑ I n t r o d u c i n g A r c h i te c t

☐ Le s s o n s l e a r n e d

Monday, October 22, 12

Page 75: Architecting large Node.js applications

Modularize in feature blocks

Don’t over engineerDon’t create too small blocksThey aren’t interfaces!

Monday, October 22, 12

Page 76: Architecting large Node.js applications

Use dependency injection

Architect (JavaScript)StructureMap (.NET)Spring (Java)

Monday, October 22, 12

Page 77: Architecting large Node.js applications

Avoid context switching

Less code!Less errors!Less boilerplate!

Monday, October 22, 12

Page 78: Architecting large Node.js applications

Loose coupling

Use an event bus

Smaller dependency graph

Monday, October 22, 12

Page 79: Architecting large Node.js applications

github.com/c9/architect

Monday, October 22, 12

Page 80: Architecting large Node.js applications

Happy coding!

Monday, October 22, 12

Page 81: Architecting large Node.js applications

Sergi Mansilla@sergimansilla

github.com/sergi

http://c9.io

Monday, October 22, 12