AsynchronousArchitectures Mark Ethan Trostler firstname.lastname@example.org @zzoass
Motivation Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface. Controlling complexity is the essence of computer programming The only way to write complex software that wont fall on its face is to hold its global complexity down — to build it out of simple parts connected by well-defined interfaces, so that most problems are local and you can have some hope of upgrading a part without breaking the whole.
Code Complexity #1 indicator of bugs: code size ( > 9300 chars) In the eye of the beholder: the Co-Worker Test Dependency count - coupling
Dependencies Required for object operation Lots of dependencies make code complex Long chains of dependencies make code complex More code loaded locally – more chance for something to go wrong* Load JS, ‘require’ Minimize Dependencies!
Coupling What do you do with a dependency?? Instantiate it? Call methods? Access properties? Change shared global state? Alter all of them (prototype)? Keep Coupling Loose!
Application?Applications are message passing systems with a bag ofobjects in the middle with input and output at eitherends. Object1 Object2 Object3
Current Application Paradigms Method based APIs Tight coupling adds complexity Remote interfaces Non-local – sync or async Local interface to remote object (Model) Object-based callbacks Eventing/Callbacks require dependent object to be local
Pure Event with Hub Asynchronous emitter Asynchronous listener NO local reference Shared nothing Loose coupling Function callbacks
Central Hub Independent modules cannot find each other All connect to central hub Hub unicast/broadcast events/responses Session handling Authorization services Event registration No local references Services run anywhere (no same-domain)
What Does It Look Like?Listeners on event name, get an object and an optional callbackEmitters send event name, data object and an optional callbackCallback function expects (error, response) where error is either an object or string or null and response is an object (NodeJS standard)