SlideShare una empresa de Scribd logo
1 de 71
Descargar para leer sin conexión
HOW TO
                     WRITE
                     BIG APPS.
                     Richard Rodger
                     @rjrodger
Friday 26 October 2012
Node.js apps
                     are getting
                     bigger.
Friday 26 October 2012
So, how do
                     you scale?
                     ‣be stateless,
                     ‣lots of little processes,
                     ‣funky V8 options,
                     ‣...
Friday 26 October 2012
NO

Friday 26 October 2012
How do you
                         scale this?


Friday 26 October 2012
Let's write a
                     class for
                     Cars.
Friday 26 October 2012
Classical
          function Car( params ) {
            this.color     = params.color       ||   "red"
            this.marque    = params.marque      ||   "Ferrari"
            this.model     = params.model       ||   "Testarossa"
            this.cylinders = params.cylinders   ||   12
            this.timeto60 = params.timeto60     ||   5.2 // seconds
          }

          Car.prototype.drive = function() {
            console.log( "vrooom!" )
          }

          var car = new Car({color:"yellow"})
          car.drive()



Friday 26 October 2012
Classical
          function Car( params ) {
            this.color     = params.color       ||   "red"
            this.marque    = params.marque      ||   "Ferrari"
            this.model     = params.model       ||   "Testarossa"
            this.cylinders = params.cylinders   ||   12
            this.timeto60 = params.timeto60     ||   5.2 // seconds
          }

          Car.prototype.drive = function() {
            console.log( "vrooom!" )
          }
                                                                       VO
                                                                         TE
          var car = new Car({color:"yellow"})
                                                                      NO
          car.drive()
                                                                        W

Friday 26 October 2012
var Car = {
                         Prototypical
            color:        "red",
            marque:       "Ferrari",
            model:        "Testarossa",
            cylinders:    12,
            timeto60:     5.2,

               drive: function() {
                 console.log( "vrooom!", this )
               }
          }

          var car = Object.create(Car)
          car.color = "yellow"
          car.drive()


Friday 26 October 2012
var Car = {
                         Prototypical
            color:        "red",
            marque:       "Ferrari",
            model:        "Testarossa",
            cylinders:    12,
            timeto60:     5.2,

               drive: function() {
                 console.log( "vrooom!", this )
               }
          }
                                                   VO
                                                     TE
          var car = Object.create(Car)
                                                  NO
          car.color = "yellow"
          car.drive()
                                                    W

Friday 26 October 2012
Functional
          function Car( params ) {
            var self = {}

               var       color       =   params.color       ||   "red"
               var       marque      =   params.marque      ||   "Ferrari"
               var       model       =   params.model       ||   "Testarossa"
               var       cylinders   =   params.cylinders   ||   12
               var       timeto60    =   params.timeto60    ||   5.2

               self.drive = function() {
                 console.log( "vrooom!", self )
               }
               return self
          }
          var car = Car({color:"yellow"})
          car.drive()

Friday 26 October 2012
Functional
          function Car( params ) {
            var self = {}

               var       color       =   params.color       ||   "red"
               var       marque      =   params.marque      ||   "Ferrari"
               var       model       =   params.model       ||   "Testarossa"
               var       cylinders   =   params.cylinders   ||   12
               var       timeto60    =   params.timeto60    ||   5.2

               self.drive = function() {
                 console.log( "vrooom!", self )
                                                                                 VO
                                                                                   TE
               }
               return self
                                                                                NO
          }
          var car = Car({color:"yellow"})
                                                                                  W
          car.drive()

Friday 26 October 2012
Which one
                     should we
                     use for
                     Cars?
Friday 26 October 2012
Let's play a
                     GAME.
Friday 26 October 2012
Stand up.


Friday 26 October 2012
Stand up.
                     Everybody.
Friday 26 October 2012
Is this a car?



Friday 26 October 2012
YES       NO
        Stay standing.           Sit down.
                               And stay down!



Friday 26 October 2012
Is this a car?



Friday 26 October 2012
Is this a car?



Friday 26 October 2012
Is this a car?



Friday 26 October 2012
Is this a car?



Friday 26 October 2012
Is this a car?



Friday 26 October 2012
Is this a car?



Friday 26 October 2012
Is this a car?
                     It's a painting.



Friday 26 October 2012
Which one?
                     ‣Classical
                     ‣Prototypical
                     ‣Functional

Friday 26 October 2012
Which one?
                     ‣Classical
                     ‣Prototypical
                     ‣Functional
                     NONE!
Friday 26 October 2012
What's wrong
                     with properties?
                     ‣Color - Lego?
                     ‣Marque - Batman brand?
                     ‣Model - Flintstones?
                     ‣Cylinders - Star Wars hover car?
                     ‣timeto60 - Model T max is 45mph
Friday 26 October 2012
Classes
                     are
                     ideal
                     Platonic
                     forms.

Friday 26 October 2012
Think of the ideal
                     triangle.
                     ‣Sides - 3!
                     ‣Points - 3!
                     ‣Total of Angles - 180°!


Friday 26 October 2012
Think of the ideal
                     triangle.
                     ‣Sides - 3!
                     ‣Points - 3!
                     ‣Total of Angles - 180°!
                     Now picture it in
                     your mind.
Friday 26 October 2012
Plato was
                     wrong.
                     Ideal forms do
                     not exist.
Friday 26 October 2012
George
                     Berkeley

                     berkeley.edu
                     same guy

                     also Irish!
Friday 26 October 2012
Inventor of...

Friday 26 October 2012
Friday 26 October 2012
There is no
                     mental image
                     of a ideal
                     triangle.
Friday 26 October 2012
Classes suck.
                     Objects are ok.
Friday 26 October 2012
Classes suck.
                     Objects are ok.
                     i nh
                          eritan ce




Friday 26 October 2012
Classes suck.
                       refac
                              torin
                     Objects are ok.
                     i nh
                          eritanc eg




Friday 26 October 2012
Classes suck.
                       refac
                              torin
                                       archi
                                             tectu

                     Objects are ok.
                            itanc eg               re
                          er
                     i nh



Friday 26 October 2012
on
                     Classes suck.

                                                           lati
                                       archi




                                                            u
                                                         aps
                       refac                 tectu


                                                        enc
                              torin
                     Objects are ok.
                            itanc eg               re
                          er
                     i nh



Friday 26 October 2012
on
                     Classes suck.
                                 sch




                                                           lati
                                     e
                                       archi
                                         ma




                                                            u
                                           s




                                                         aps
                       refac                 tectu


                                                        enc
                              torin
                     Objects are ok.
                            itanc eg               re
                          er
                     i nh



Friday 26 October 2012
on
                     Classes suck.
                                 sch




                                                           lati
                                     e
                                       archi
                                         ma




                                                            u
                                           s




                                                                       ism
                                                         aps
                       refac                 tectu




                                                                  orph
                                                        enc
                              torin
                     Objects are ok.
                            itanc eg




                                                                polym
                                                   re
                          er
                     i nh



Friday 26 October 2012
on
                     Classes suck.
                                 sch




                                                           lati
                                     e
                                       archi
                                         ma




                                                                        un
                                                            u
                                           s




                                                                       ism
                                                         aps


                                                                             it t
                       refac                 tectu




                                                                  orph
                                                        enc




                                                                              est
                              torin
                     Objects are ok.
                                  eg




                                                                                ing
                            itanc




                                                                polym
                                                   re
                          er
                     i nh



Friday 26 October 2012
on
                     Classes suck.
                                 sch




                                                            lati
                                     e
                                       archi
                                         ma




                                                                         un
                                                            u
                                           s




                                                                        ism
                                                         aps


                                                                              it t
                       refac                 tectu




                                                                   orph
                                                        enc




                                                                               est
                              torin
                     Objects are ok.
                                  eg                              encies




                                                                                 ing
                            itanc                          pen   d




                                                                 polym
                                                   re
                          er                            de
                     i nh



Friday 26 October 2012
Something is
                     wrong with
                     modeling a
                     car.
Friday 26 October 2012
But you can
                     still drive all
                     those cars.
Friday 26 October 2012
It's not what
                     you are.
                     It's what you
                     do.
Friday 26 October 2012
What does your
                     app want to do?
                     ‣Register a new user,
                     ‣Place an order,
                     ‣Call an external service,
                     ‣Save and load data,
                     ‣...
Friday 26 October 2012
This is JavaScript
          JSON           function             JSON

                                            OUTPUT,
                          A command      asynchronously,
        INPUT            for your app,      of course
      (mostly in-            that
    memory objects)      "does stuff"

Friday 26 October 2012
How do you find the
          right "thing to do"?


Friday 26 October 2012
How do you find the
          right "thing to do"?
          PATTERN
          MATCHING!
Friday 26 October 2012
{
                         thing: "product",
                         cmd:   "save",

                         ... other fields
                                             doSave()
                    }




                    {
                         thing: "product",
                         cmd:   "load",

                         ... other fields
                                             doLoad()
                    }




Friday 26 October 2012
Define your
          "business logic" in
          terms of these
          commands.
Friday 26 October 2012
What do you get as
          the pay off?

Friday 26 October 2012
Really easy testing.
          Verify the returned
          JSON and you're
          done.
Friday 26 October 2012
A distributed system,
          if you need it.
          That gives you scale
          too.
Friday 26 October 2012
Completely
          decoupled
          commands that never
          need to know about
          each other.
Friday 26 October 2012
Plugins for free - just
          bundle up a few
          related commands.
          Organize your code!
Friday 26 October 2012
middleware-style
          layering - e.g. add a
          caching layer by
          matching data
          storage commands.
Friday 26 October 2012
Stay in control -
          tracing, logging,
          throttling,
          permissions, special
          cases - all easy.
Friday 26 October 2012
Documentation - just
          list all the commands
          and the JSON they
          expect.
Friday 26 October 2012
Code!
          Open sourced at
          http://senecajs.org
          npm install seneca

Friday 26 October 2012
Define and call a command.
          var seneca = require('seneca')()

          // define a command
          seneca.add({role:'math', cmd:'sum'},
                     function(args,callback) {
                        var sum = args.left + args.right
                        callback(null,{answer:sum})
                     })

          // call the command
          seneca.act({role:'math', cmd:'sum', left:1, right:2},
                     function(err,result) {
                        if( err ) return console.error( err )
                        console.log(result)
                     })

          // prints: { answer: 3 }




Friday 26 October 2012
Pinning an API for convenience
          // define a command
          seneca.add({role:'math', cmd:'sum'},
                     function(args,callback) {
                        var sum = args.left + args.right
                        callback(null,{answer:sum})
                     })

          // pin the API
          var math = seneca.pin({role:'math',cmd:'*'})

          // call the command
          math.sum({left:1,right:2},
                   function(err,result) {
                      console.log(result)
                   })

          // prints: { answer: 3 }




Friday 26 October 2012
Plugins: commands + HTTP API.
          seneca.use( function(seneca,options,callback) {
            seneca.add( {role:'math', cmd:'sum'}, function(args,callback) {
               var sum = args.left + args.right
               callback(null,{answer:sum})
            })

               seneca.add( {role:'math', cmd:'product'}, function(args,callback) {
                  var product = args.left * args.right
                  callback(null,{answer:product})
               })

               callback( null, seneca.http({ // just a connect middleware
                 pin: {role:'math', cmd:'*'},
                 map: { sum: {}, product: {} }, // GET is the default HTTP method
                 args: { left: parseFloat, right: parseFloat }
               }))
          })

          var app = connect()
            .use(connect.query())
            .use(seneca.service())
            .listen(3000)
          // http://localhost:3000/api/sum?left=1&right=2


Friday 26 October 2012
Build a distributed system
          // client:
          // use transport plugin to calculate product remotely
          seneca.use('transport',{
             pins:[ {role:'math', cmd:'product'} ]
          })

          // this will go out over network
          seneca.act({role:'math', cmd:'product', left:3, right:4},
                     function(err,result) {
                        if( err ) return console.error( err )
                        console.log(result)
                     })




          // server (as per previous slide):
          seneca.use('transport')
          ...
          app.use( connect.json() )
          ...




Friday 26 October 2012
Data storage (also plugin-based)
          var product = seneca.make('product')
          product.name = 'apple'
          product.price = 100

          // ActiveRecord-style
          product.save$(function( err, product ) {
            if( err ) return console.error( err )
            console.log( 'saved: '+product )

               // product.id was generated for you
               product.load$({id:product.id},function( err, product ) {
                  if( err ) return console.error( err )
                  console.log( 'loaded: '+product )
               })
          })

          // output:
          // saved: //product:{id=286624;name=apple;price=100}
          // loaded: //product:{id=286624;name=apple;price=100}


          // mix-and-match in-memory, MongoDB, MySQL, PostreSQL, etc.



Friday 26 October 2012
Also, seneca...
                     ‣is about 18 months old
                     ‣has detailed tracing
                     ‣has nice error messages
                     ‣has a REPL! @dshaw happy?
                     ‣is used in production
Friday 26 October 2012
Why did we built it?
                     builds
          Minimum Viable
          Products that
          become big apps.
Friday 26 October 2012
senecajs.org
          @nodeseneca

          Thanks!


Friday 26 October 2012

Más contenido relacionado

Destacado

A pattern language for microservices (#gluecon #gluecon2016)
A pattern language for microservices (#gluecon #gluecon2016)A pattern language for microservices (#gluecon #gluecon2016)
A pattern language for microservices (#gluecon #gluecon2016)Chris Richardson
 
Microservices + Events + Docker = A Perfect Trio (dockercon)
Microservices + Events + Docker = A Perfect Trio (dockercon)Microservices + Events + Docker = A Perfect Trio (dockercon)
Microservices + Events + Docker = A Perfect Trio (dockercon)Chris Richardson
 
Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)Chris Richardson
 
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...Chris Richardson
 
Bare-metal performance for Big Data workloads on Docker containers
Bare-metal performance for Big Data workloads on Docker containersBare-metal performance for Big Data workloads on Docker containers
Bare-metal performance for Big Data workloads on Docker containersBlueData, Inc.
 
The New Stack Container Summit Talk
The New Stack Container Summit TalkThe New Stack Container Summit Talk
The New Stack Container Summit TalkThe New Stack
 

Destacado (6)

A pattern language for microservices (#gluecon #gluecon2016)
A pattern language for microservices (#gluecon #gluecon2016)A pattern language for microservices (#gluecon #gluecon2016)
A pattern language for microservices (#gluecon #gluecon2016)
 
Microservices + Events + Docker = A Perfect Trio (dockercon)
Microservices + Events + Docker = A Perfect Trio (dockercon)Microservices + Events + Docker = A Perfect Trio (dockercon)
Microservices + Events + Docker = A Perfect Trio (dockercon)
 
Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)Developing microservices with aggregates (SpringOne platform, #s1p)
Developing microservices with aggregates (SpringOne platform, #s1p)
 
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
Handling Eventual Consistency in JVM Microservices with Event Sourcing (javao...
 
Bare-metal performance for Big Data workloads on Docker containers
Bare-metal performance for Big Data workloads on Docker containersBare-metal performance for Big Data workloads on Docker containers
Bare-metal performance for Big Data workloads on Docker containers
 
The New Stack Container Summit Talk
The New Stack Container Summit TalkThe New Stack Container Summit Talk
The New Stack Container Summit Talk
 

Más de Richard Rodger

Using RAG to create your own Podcast conversations.pdf
Using RAG to create your own Podcast conversations.pdfUsing RAG to create your own Podcast conversations.pdf
Using RAG to create your own Podcast conversations.pdfRichard Rodger
 
Richard_TheDev2023_pattern.pptx.pdf
Richard_TheDev2023_pattern.pptx.pdfRichard_TheDev2023_pattern.pptx.pdf
Richard_TheDev2023_pattern.pptx.pdfRichard Rodger
 
richard-rodger-awssofia-microservices-2019.pdf
richard-rodger-awssofia-microservices-2019.pdfrichard-rodger-awssofia-microservices-2019.pdf
richard-rodger-awssofia-microservices-2019.pdfRichard Rodger
 
richardrodger-microservice-algebra-cluj-apr.pdf
richardrodger-microservice-algebra-cluj-apr.pdfrichardrodger-microservice-algebra-cluj-apr.pdf
richardrodger-microservice-algebra-cluj-apr.pdfRichard Rodger
 
richardrodger-designing-microservices-london-may.pdf
richardrodger-designing-microservices-london-may.pdfrichardrodger-designing-microservices-london-may.pdf
richardrodger-designing-microservices-london-may.pdfRichard Rodger
 
richardrodger-designing-microservices-london-may.pdf
richardrodger-designing-microservices-london-may.pdfrichardrodger-designing-microservices-london-may.pdf
richardrodger-designing-microservices-london-may.pdfRichard Rodger
 
richardrodger-microservice-risk-dublin-mar.pdf
richardrodger-microservice-risk-dublin-mar.pdfrichardrodger-microservice-risk-dublin-mar.pdf
richardrodger-microservice-risk-dublin-mar.pdfRichard Rodger
 
richardrodger-service-discovery-waterford-feb.pdf
richardrodger-service-discovery-waterford-feb.pdfrichardrodger-service-discovery-waterford-feb.pdf
richardrodger-service-discovery-waterford-feb.pdfRichard Rodger
 
richardrodger-vespa-waterford-oct.pdf
richardrodger-vespa-waterford-oct.pdfrichardrodger-vespa-waterford-oct.pdf
richardrodger-vespa-waterford-oct.pdfRichard Rodger
 
Richardrodger designing-microservices-uxdx-dublin-oct
Richardrodger designing-microservices-uxdx-dublin-octRichardrodger designing-microservices-uxdx-dublin-oct
Richardrodger designing-microservices-uxdx-dublin-octRichard Rodger
 
How microservices fail, and what to do about it
How microservices fail, and what to do about itHow microservices fail, and what to do about it
How microservices fail, and what to do about itRichard Rodger
 
Rapid Digital Innovation: How Node.js Delivers
Rapid Digital Innovation: How Node.js DeliversRapid Digital Innovation: How Node.js Delivers
Rapid Digital Innovation: How Node.js DeliversRichard Rodger
 
Richardrodger nodeconfeu-2014-final
Richardrodger nodeconfeu-2014-finalRichardrodger nodeconfeu-2014-final
Richardrodger nodeconfeu-2014-finalRichard Rodger
 
Richardrodger nodeday-2014-final
Richardrodger nodeday-2014-finalRichardrodger nodeday-2014-final
Richardrodger nodeday-2014-finalRichard Rodger
 
Richardrodger nodeday-2014-final
Richardrodger nodeday-2014-finalRichardrodger nodeday-2014-final
Richardrodger nodeday-2014-finalRichard Rodger
 
Richardrodger microxchgio-feb-2015-final
Richardrodger microxchgio-feb-2015-finalRichardrodger microxchgio-feb-2015-final
Richardrodger microxchgio-feb-2015-finalRichard Rodger
 
Micro-services Battle Scars
Micro-services Battle ScarsMicro-services Battle Scars
Micro-services Battle ScarsRichard Rodger
 
Richard rodger technical debt - web summit 2013
Richard rodger   technical debt - web summit 2013Richard rodger   technical debt - web summit 2013
Richard rodger technical debt - web summit 2013Richard Rodger
 
The Seneca Pattern at EngineYard Distill 2013 Conference
The Seneca Pattern at EngineYard Distill 2013 ConferenceThe Seneca Pattern at EngineYard Distill 2013 Conference
The Seneca Pattern at EngineYard Distill 2013 ConferenceRichard Rodger
 
Building businesspost.ie using Node.js
Building businesspost.ie using Node.jsBuilding businesspost.ie using Node.js
Building businesspost.ie using Node.jsRichard Rodger
 

Más de Richard Rodger (20)

Using RAG to create your own Podcast conversations.pdf
Using RAG to create your own Podcast conversations.pdfUsing RAG to create your own Podcast conversations.pdf
Using RAG to create your own Podcast conversations.pdf
 
Richard_TheDev2023_pattern.pptx.pdf
Richard_TheDev2023_pattern.pptx.pdfRichard_TheDev2023_pattern.pptx.pdf
Richard_TheDev2023_pattern.pptx.pdf
 
richard-rodger-awssofia-microservices-2019.pdf
richard-rodger-awssofia-microservices-2019.pdfrichard-rodger-awssofia-microservices-2019.pdf
richard-rodger-awssofia-microservices-2019.pdf
 
richardrodger-microservice-algebra-cluj-apr.pdf
richardrodger-microservice-algebra-cluj-apr.pdfrichardrodger-microservice-algebra-cluj-apr.pdf
richardrodger-microservice-algebra-cluj-apr.pdf
 
richardrodger-designing-microservices-london-may.pdf
richardrodger-designing-microservices-london-may.pdfrichardrodger-designing-microservices-london-may.pdf
richardrodger-designing-microservices-london-may.pdf
 
richardrodger-designing-microservices-london-may.pdf
richardrodger-designing-microservices-london-may.pdfrichardrodger-designing-microservices-london-may.pdf
richardrodger-designing-microservices-london-may.pdf
 
richardrodger-microservice-risk-dublin-mar.pdf
richardrodger-microservice-risk-dublin-mar.pdfrichardrodger-microservice-risk-dublin-mar.pdf
richardrodger-microservice-risk-dublin-mar.pdf
 
richardrodger-service-discovery-waterford-feb.pdf
richardrodger-service-discovery-waterford-feb.pdfrichardrodger-service-discovery-waterford-feb.pdf
richardrodger-service-discovery-waterford-feb.pdf
 
richardrodger-vespa-waterford-oct.pdf
richardrodger-vespa-waterford-oct.pdfrichardrodger-vespa-waterford-oct.pdf
richardrodger-vespa-waterford-oct.pdf
 
Richardrodger designing-microservices-uxdx-dublin-oct
Richardrodger designing-microservices-uxdx-dublin-octRichardrodger designing-microservices-uxdx-dublin-oct
Richardrodger designing-microservices-uxdx-dublin-oct
 
How microservices fail, and what to do about it
How microservices fail, and what to do about itHow microservices fail, and what to do about it
How microservices fail, and what to do about it
 
Rapid Digital Innovation: How Node.js Delivers
Rapid Digital Innovation: How Node.js DeliversRapid Digital Innovation: How Node.js Delivers
Rapid Digital Innovation: How Node.js Delivers
 
Richardrodger nodeconfeu-2014-final
Richardrodger nodeconfeu-2014-finalRichardrodger nodeconfeu-2014-final
Richardrodger nodeconfeu-2014-final
 
Richardrodger nodeday-2014-final
Richardrodger nodeday-2014-finalRichardrodger nodeday-2014-final
Richardrodger nodeday-2014-final
 
Richardrodger nodeday-2014-final
Richardrodger nodeday-2014-finalRichardrodger nodeday-2014-final
Richardrodger nodeday-2014-final
 
Richardrodger microxchgio-feb-2015-final
Richardrodger microxchgio-feb-2015-finalRichardrodger microxchgio-feb-2015-final
Richardrodger microxchgio-feb-2015-final
 
Micro-services Battle Scars
Micro-services Battle ScarsMicro-services Battle Scars
Micro-services Battle Scars
 
Richard rodger technical debt - web summit 2013
Richard rodger   technical debt - web summit 2013Richard rodger   technical debt - web summit 2013
Richard rodger technical debt - web summit 2013
 
The Seneca Pattern at EngineYard Distill 2013 Conference
The Seneca Pattern at EngineYard Distill 2013 ConferenceThe Seneca Pattern at EngineYard Distill 2013 Conference
The Seneca Pattern at EngineYard Distill 2013 Conference
 
Building businesspost.ie using Node.js
Building businesspost.ie using Node.jsBuilding businesspost.ie using Node.js
Building businesspost.ie using Node.js
 

Último

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Último (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

How to Write Big Apps (Richard Rodger NodeDublin 2012)

  • 1. HOW TO WRITE BIG APPS. Richard Rodger @rjrodger Friday 26 October 2012
  • 2. Node.js apps are getting bigger. Friday 26 October 2012
  • 3. So, how do you scale? ‣be stateless, ‣lots of little processes, ‣funky V8 options, ‣... Friday 26 October 2012
  • 5. How do you scale this? Friday 26 October 2012
  • 6. Let's write a class for Cars. Friday 26 October 2012
  • 7. Classical function Car( params ) { this.color = params.color || "red" this.marque = params.marque || "Ferrari" this.model = params.model || "Testarossa" this.cylinders = params.cylinders || 12 this.timeto60 = params.timeto60 || 5.2 // seconds } Car.prototype.drive = function() { console.log( "vrooom!" ) } var car = new Car({color:"yellow"}) car.drive() Friday 26 October 2012
  • 8. Classical function Car( params ) { this.color = params.color || "red" this.marque = params.marque || "Ferrari" this.model = params.model || "Testarossa" this.cylinders = params.cylinders || 12 this.timeto60 = params.timeto60 || 5.2 // seconds } Car.prototype.drive = function() { console.log( "vrooom!" ) } VO TE var car = new Car({color:"yellow"}) NO car.drive() W Friday 26 October 2012
  • 9. var Car = { Prototypical color: "red", marque: "Ferrari", model: "Testarossa", cylinders: 12, timeto60: 5.2, drive: function() { console.log( "vrooom!", this ) } } var car = Object.create(Car) car.color = "yellow" car.drive() Friday 26 October 2012
  • 10. var Car = { Prototypical color: "red", marque: "Ferrari", model: "Testarossa", cylinders: 12, timeto60: 5.2, drive: function() { console.log( "vrooom!", this ) } } VO TE var car = Object.create(Car) NO car.color = "yellow" car.drive() W Friday 26 October 2012
  • 11. Functional function Car( params ) { var self = {} var color = params.color || "red" var marque = params.marque || "Ferrari" var model = params.model || "Testarossa" var cylinders = params.cylinders || 12 var timeto60 = params.timeto60 || 5.2 self.drive = function() { console.log( "vrooom!", self ) } return self } var car = Car({color:"yellow"}) car.drive() Friday 26 October 2012
  • 12. Functional function Car( params ) { var self = {} var color = params.color || "red" var marque = params.marque || "Ferrari" var model = params.model || "Testarossa" var cylinders = params.cylinders || 12 var timeto60 = params.timeto60 || 5.2 self.drive = function() { console.log( "vrooom!", self ) VO TE } return self NO } var car = Car({color:"yellow"}) W car.drive() Friday 26 October 2012
  • 13. Which one should we use for Cars? Friday 26 October 2012
  • 14. Let's play a GAME. Friday 26 October 2012
  • 15. Stand up. Friday 26 October 2012
  • 16. Stand up. Everybody. Friday 26 October 2012
  • 17. Is this a car? Friday 26 October 2012
  • 18. YES NO Stay standing. Sit down. And stay down! Friday 26 October 2012
  • 19. Is this a car? Friday 26 October 2012
  • 20. Is this a car? Friday 26 October 2012
  • 21. Is this a car? Friday 26 October 2012
  • 22. Is this a car? Friday 26 October 2012
  • 23. Is this a car? Friday 26 October 2012
  • 24. Is this a car? Friday 26 October 2012
  • 25. Is this a car? It's a painting. Friday 26 October 2012
  • 26. Which one? ‣Classical ‣Prototypical ‣Functional Friday 26 October 2012
  • 27. Which one? ‣Classical ‣Prototypical ‣Functional NONE! Friday 26 October 2012
  • 28. What's wrong with properties? ‣Color - Lego? ‣Marque - Batman brand? ‣Model - Flintstones? ‣Cylinders - Star Wars hover car? ‣timeto60 - Model T max is 45mph Friday 26 October 2012
  • 29. Classes are ideal Platonic forms. Friday 26 October 2012
  • 30. Think of the ideal triangle. ‣Sides - 3! ‣Points - 3! ‣Total of Angles - 180°! Friday 26 October 2012
  • 31. Think of the ideal triangle. ‣Sides - 3! ‣Points - 3! ‣Total of Angles - 180°! Now picture it in your mind. Friday 26 October 2012
  • 32. Plato was wrong. Ideal forms do not exist. Friday 26 October 2012
  • 33. George Berkeley berkeley.edu same guy also Irish! Friday 26 October 2012
  • 34. Inventor of... Friday 26 October 2012
  • 36. There is no mental image of a ideal triangle. Friday 26 October 2012
  • 37. Classes suck. Objects are ok. Friday 26 October 2012
  • 38. Classes suck. Objects are ok. i nh eritan ce Friday 26 October 2012
  • 39. Classes suck. refac torin Objects are ok. i nh eritanc eg Friday 26 October 2012
  • 40. Classes suck. refac torin archi tectu Objects are ok. itanc eg re er i nh Friday 26 October 2012
  • 41. on Classes suck. lati archi u aps refac tectu enc torin Objects are ok. itanc eg re er i nh Friday 26 October 2012
  • 42. on Classes suck. sch lati e archi ma u s aps refac tectu enc torin Objects are ok. itanc eg re er i nh Friday 26 October 2012
  • 43. on Classes suck. sch lati e archi ma u s ism aps refac tectu orph enc torin Objects are ok. itanc eg polym re er i nh Friday 26 October 2012
  • 44. on Classes suck. sch lati e archi ma un u s ism aps it t refac tectu orph enc est torin Objects are ok. eg ing itanc polym re er i nh Friday 26 October 2012
  • 45. on Classes suck. sch lati e archi ma un u s ism aps it t refac tectu orph enc est torin Objects are ok. eg encies ing itanc pen d polym re er de i nh Friday 26 October 2012
  • 46. Something is wrong with modeling a car. Friday 26 October 2012
  • 47. But you can still drive all those cars. Friday 26 October 2012
  • 48. It's not what you are. It's what you do. Friday 26 October 2012
  • 49. What does your app want to do? ‣Register a new user, ‣Place an order, ‣Call an external service, ‣Save and load data, ‣... Friday 26 October 2012
  • 50. This is JavaScript JSON function JSON OUTPUT, A command asynchronously, INPUT for your app, of course (mostly in- that memory objects) "does stuff" Friday 26 October 2012
  • 51. How do you find the right "thing to do"? Friday 26 October 2012
  • 52. How do you find the right "thing to do"? PATTERN MATCHING! Friday 26 October 2012
  • 53. { thing: "product", cmd: "save", ... other fields doSave() } { thing: "product", cmd: "load", ... other fields doLoad() } Friday 26 October 2012
  • 54. Define your "business logic" in terms of these commands. Friday 26 October 2012
  • 55. What do you get as the pay off? Friday 26 October 2012
  • 56. Really easy testing. Verify the returned JSON and you're done. Friday 26 October 2012
  • 57. A distributed system, if you need it. That gives you scale too. Friday 26 October 2012
  • 58. Completely decoupled commands that never need to know about each other. Friday 26 October 2012
  • 59. Plugins for free - just bundle up a few related commands. Organize your code! Friday 26 October 2012
  • 60. middleware-style layering - e.g. add a caching layer by matching data storage commands. Friday 26 October 2012
  • 61. Stay in control - tracing, logging, throttling, permissions, special cases - all easy. Friday 26 October 2012
  • 62. Documentation - just list all the commands and the JSON they expect. Friday 26 October 2012
  • 63. Code! Open sourced at http://senecajs.org npm install seneca Friday 26 October 2012
  • 64. Define and call a command. var seneca = require('seneca')() // define a command seneca.add({role:'math', cmd:'sum'}, function(args,callback) { var sum = args.left + args.right callback(null,{answer:sum}) }) // call the command seneca.act({role:'math', cmd:'sum', left:1, right:2}, function(err,result) { if( err ) return console.error( err ) console.log(result) }) // prints: { answer: 3 } Friday 26 October 2012
  • 65. Pinning an API for convenience // define a command seneca.add({role:'math', cmd:'sum'}, function(args,callback) { var sum = args.left + args.right callback(null,{answer:sum}) }) // pin the API var math = seneca.pin({role:'math',cmd:'*'}) // call the command math.sum({left:1,right:2}, function(err,result) { console.log(result) }) // prints: { answer: 3 } Friday 26 October 2012
  • 66. Plugins: commands + HTTP API. seneca.use( function(seneca,options,callback) { seneca.add( {role:'math', cmd:'sum'}, function(args,callback) { var sum = args.left + args.right callback(null,{answer:sum}) }) seneca.add( {role:'math', cmd:'product'}, function(args,callback) { var product = args.left * args.right callback(null,{answer:product}) }) callback( null, seneca.http({ // just a connect middleware pin: {role:'math', cmd:'*'}, map: { sum: {}, product: {} }, // GET is the default HTTP method args: { left: parseFloat, right: parseFloat } })) }) var app = connect() .use(connect.query()) .use(seneca.service()) .listen(3000) // http://localhost:3000/api/sum?left=1&right=2 Friday 26 October 2012
  • 67. Build a distributed system // client: // use transport plugin to calculate product remotely seneca.use('transport',{ pins:[ {role:'math', cmd:'product'} ] }) // this will go out over network seneca.act({role:'math', cmd:'product', left:3, right:4}, function(err,result) { if( err ) return console.error( err ) console.log(result) }) // server (as per previous slide): seneca.use('transport') ... app.use( connect.json() ) ... Friday 26 October 2012
  • 68. Data storage (also plugin-based) var product = seneca.make('product') product.name = 'apple' product.price = 100 // ActiveRecord-style product.save$(function( err, product ) { if( err ) return console.error( err ) console.log( 'saved: '+product ) // product.id was generated for you product.load$({id:product.id},function( err, product ) { if( err ) return console.error( err ) console.log( 'loaded: '+product ) }) }) // output: // saved: //product:{id=286624;name=apple;price=100} // loaded: //product:{id=286624;name=apple;price=100} // mix-and-match in-memory, MongoDB, MySQL, PostreSQL, etc. Friday 26 October 2012
  • 69. Also, seneca... ‣is about 18 months old ‣has detailed tracing ‣has nice error messages ‣has a REPL! @dshaw happy? ‣is used in production Friday 26 October 2012
  • 70. Why did we built it? builds Minimum Viable Products that become big apps. Friday 26 October 2012
  • 71. senecajs.org @nodeseneca Thanks! Friday 26 October 2012