SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
When to use Node.js?
                       Lessons learned
                         Coen Stevens - Amsterdam Node Meetup 2012




                  @beatlevic           BeatleTech.com


Saturday, March 31, 12
W2010

Saturday, March 31, 12
Why not Node.js
            • We never heard of Node.js at the time (2009)
                    and were experienced in Ruby
            • Lots of server-side computations / statistics /
                    map-reduce (blocking the node event-loop)
            • Typical dashboard (view on a database)
            • Not that many concurrent users
            • No need for open connections
                                     Yes, I would use Ruby again
Saturday, March 31, 12
Pivot: Penny auctions


                     • Swoopo and Bigdeal (real goods)
                     • Newcope a platform for pay-per-bid
                         auction games for virtual goods




Saturday, March 31, 12
Flash game platform




                         http://newcope-heyzap.heroku.com/home
Saturday, March 31, 12
• The Broth: BarnBuddy
                     • Facebook app
                     • Similar to Farmville
                     • Over 1 million active users per month

Saturday, March 31, 12
Challenge

                     • Build iframe / facebook app solution
                     • Have the auctions as realtime as possible
                     • Long polling (later websockets) vs pulling
                     • Lots of users with open connections
                     • Scalable

Saturday, March 31, 12
Languages considered

                 • Ruby (Eventmachine, no Goliath yet)
                 • JRuby
                 • Scala (Twitter had just moved from ruby)
                 • Erlang
                 • Javascript Node.js

Saturday, March 31, 12
Saturday, March 31, 12
Node.js experiences
           •       Functional programming

           •       Javascript for both client and server

           •       Very good performance (30k users the first day)

           •       Node v0.1.25 and no packet manager (npm)

           •       MySQL with DBSlayer (later Mongodb)

           •       Nginx to serve static files

           •       Easy to setup/deploy on EC2 (upstart deamon)

           •       Everything async (annoying to test)

           •       Fun!
                                          Yes, I would use Node.js again
Saturday, March 31, 12
Auction.prototype.startTimer = function() {
         var self = this;   
         if (this.timer) clearTimeout(this.timer);
         this.emit("start");  
         this.timer = setTimeout(function() {
           self.emit("end");
         }, self.timeLeft() * 1000);
       }

       Auction.prototype.bid = function(user) {
           var self = this;
           return function (callback, errback) {
            if (user.bid_count > 0 && self.status() === "running") {
               user.bid_count -= 1;
               dbUser.updateUser(user.id, {'bid_count': user.bid_count})(function(result){
                 if (self.timeLeft() < self.bidTimeDelta) {
                   self.setTime(me.bidTimeDelta);
                 };
                 self.price += self.bidPriceDelta;
                 var bid = { user: user, ts: new Date() }
                 self.bids.push(bid);
                 self.bidCount++;
                 callback(self);
               }, function(error) {
                 user.bid_count += 1;
                 errback("Could not update new bid count");
               })
            } else {
               errback("Bid could not be placed");
            }
         };
       }


Saturday, March 31, 12
// continuation style
       var bid = function(user) {
           return function (callback, errback) {
             if (!user) return errback("No user")
             callback(user)
           }
       }

       bid(user)(function(result){
          console.log(result)
       }, function(error) {
          console.log(error)
       })




Saturday, March 31, 12
// promise style
       var bid = function(user) {
         var promise = new Promise()
         if (!user) {
           promise.emitError("No user")
         } else {
           promise.emitSuccess(user)
         }
         return promise
       }

       var promise = bid(user)
       promise.addErrback(function(error){
          console.log(error)
       })
       promise.addCallback(function(result) {
          console.log(result)
       })




Saturday, March 31, 12
•   // callback style
       var bid = function(user, callback) {
         if (!user) return callback("No user")
         callback(null, user);
       }

       bid(user, function(err, result){
          if (err) console.log(err)
          console.log(result)
       })




Saturday, March 31, 12
• Bottlenose is the smartest social media
                         dashboard.
              • Helping you manage the information overload
                         on streams like twitter and Facebook
              • Bottlenose analyzes and filters messages using
                         NLP and clustering techniques
              • Beta launched December 2011
                                      http://bottlenose.com
Saturday, March 31, 12
Saturday, March 31, 12
Why Node.js?
                     • It began (2009) with NLP in javascript, run
                         it both on the client and the server
                     • Fat client and lean server
                     • Realtime stream updates
                     • Lots of users (with open connections)
                     • Alternatives?
                                        Yes, I would use Node.js again
Saturday, March 31, 12
Summary:
                          When to use Node?
              • When you are building more of an app than a
                         website and require lots of open connections to
                         the server
              • When you want your users to get data in
                         realtime (chat, streams)
              • When you have to serve lots of requests that do
                         not take too many cpu cycles (blocking the loop)
              • When you like to work with Javascript all the way
Saturday, March 31, 12
Thanks!




                  @beatlevic
Saturday, March 31, 12

Weitere ähnliche Inhalte

Andere mochten auch

Voting presentation
Voting presentationVoting presentation
Voting presentation
hannahfenney
 
Evaluation for the music magazine
Evaluation for the music magazineEvaluation for the music magazine
Evaluation for the music magazine
Liam Wylie
 
班级新变化
班级新变化班级新变化
班级新变化
jody531
 
Facebook-Zynga
Facebook-ZyngaFacebook-Zynga
Facebook-Zynga
gndolf
 
Social game의 가까운 미래
Social game의 가까운 미래Social game의 가까운 미래
Social game의 가까운 미래
gndolf
 
Anatomyofa twitterrumor
Anatomyofa twitterrumorAnatomyofa twitterrumor
Anatomyofa twitterrumor
Gnip
 
Deploying oracle rac 10g with asm on rhel and sles with svc
Deploying oracle rac 10g with asm on rhel and sles with svcDeploying oracle rac 10g with asm on rhel and sles with svc
Deploying oracle rac 10g with asm on rhel and sles with svc
wikiwei
 

Andere mochten auch (20)

Voting presentation
Voting presentationVoting presentation
Voting presentation
 
Evaluation for the music magazine
Evaluation for the music magazineEvaluation for the music magazine
Evaluation for the music magazine
 
Gulteal region
Gulteal regionGulteal region
Gulteal region
 
Digital Audio/Podcast Assignment
Digital Audio/Podcast AssignmentDigital Audio/Podcast Assignment
Digital Audio/Podcast Assignment
 
Simplify and run your development environments with Vagrant on OpenStack
Simplify and run your development environments with Vagrant on OpenStackSimplify and run your development environments with Vagrant on OpenStack
Simplify and run your development environments with Vagrant on OpenStack
 
The Poker Entrepreneurship: Speaking @ JFDI.Asia
The Poker Entrepreneurship: Speaking @ JFDI.AsiaThe Poker Entrepreneurship: Speaking @ JFDI.Asia
The Poker Entrepreneurship: Speaking @ JFDI.Asia
 
Reference_Letter
Reference_LetterReference_Letter
Reference_Letter
 
Steps presentation
Steps presentationSteps presentation
Steps presentation
 
Internationaal privaatrecht en fundamentele rechten. Ipr als instrument ter b...
Internationaal privaatrecht en fundamentele rechten. Ipr als instrument ter b...Internationaal privaatrecht en fundamentele rechten. Ipr als instrument ter b...
Internationaal privaatrecht en fundamentele rechten. Ipr als instrument ter b...
 
P m01 inside_selling
P m01 inside_sellingP m01 inside_selling
P m01 inside_selling
 
班级新变化
班级新变化班级新变化
班级新变化
 
Marketing Management
Marketing ManagementMarketing Management
Marketing Management
 
Facebook-Zynga
Facebook-ZyngaFacebook-Zynga
Facebook-Zynga
 
Actualiteiten IPR: Nieuw Boek 10 BW; What's new in het ipr?
Actualiteiten IPR: Nieuw Boek 10 BW; What's new in het ipr?Actualiteiten IPR: Nieuw Boek 10 BW; What's new in het ipr?
Actualiteiten IPR: Nieuw Boek 10 BW; What's new in het ipr?
 
Images for the Clouds with KIWI & OBS
Images for the Clouds with KIWI & OBSImages for the Clouds with KIWI & OBS
Images for the Clouds with KIWI & OBS
 
Social game의 가까운 미래
Social game의 가까운 미래Social game의 가까운 미래
Social game의 가까운 미래
 
Digital Audio/Podcast Assignment
Digital Audio/Podcast AssignmentDigital Audio/Podcast Assignment
Digital Audio/Podcast Assignment
 
House for sale
House for saleHouse for sale
House for sale
 
Anatomyofa twitterrumor
Anatomyofa twitterrumorAnatomyofa twitterrumor
Anatomyofa twitterrumor
 
Deploying oracle rac 10g with asm on rhel and sles with svc
Deploying oracle rac 10g with asm on rhel and sles with svcDeploying oracle rac 10g with asm on rhel and sles with svc
Deploying oracle rac 10g with asm on rhel and sles with svc
 

Ähnlich wie When to use Node? Lessons learned

Dev tools rendering & memory profiling
Dev tools rendering & memory profilingDev tools rendering & memory profiling
Dev tools rendering & memory profiling
Open Academy
 

Ähnlich wie When to use Node? Lessons learned (20)

node.js in production: Reflections on three years of riding the unicorn
node.js in production: Reflections on three years of riding the unicornnode.js in production: Reflections on three years of riding the unicorn
node.js in production: Reflections on three years of riding the unicorn
 
node.js in action
node.js in actionnode.js in action
node.js in action
 
Everything you ever wanted to know about lotus script
Everything you ever wanted to know about lotus scriptEverything you ever wanted to know about lotus script
Everything you ever wanted to know about lotus script
 
Node.js
Node.jsNode.js
Node.js
 
Softshake 2013: Introduction to NoSQL with Couchbase
Softshake 2013: Introduction to NoSQL with CouchbaseSoftshake 2013: Introduction to NoSQL with Couchbase
Softshake 2013: Introduction to NoSQL with Couchbase
 
How to Make Norikra Perfect
How to Make Norikra PerfectHow to Make Norikra Perfect
How to Make Norikra Perfect
 
Nexmark with beam
Nexmark with beamNexmark with beam
Nexmark with beam
 
A Morning with MongoDB Barcelona: Use Cases and Roadmap
A Morning with MongoDB Barcelona: Use Cases and RoadmapA Morning with MongoDB Barcelona: Use Cases and Roadmap
A Morning with MongoDB Barcelona: Use Cases and Roadmap
 
Ledingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @LendingkartLedingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @Lendingkart
 
Concurrency (Fisher Syer S2GX 2010)
Concurrency (Fisher Syer S2GX 2010)Concurrency (Fisher Syer S2GX 2010)
Concurrency (Fisher Syer S2GX 2010)
 
Google Chrome DevTools: Rendering & Memory profiling on Open Academy 2013
Google Chrome DevTools: Rendering & Memory profiling on Open Academy 2013Google Chrome DevTools: Rendering & Memory profiling on Open Academy 2013
Google Chrome DevTools: Rendering & Memory profiling on Open Academy 2013
 
Dev tools rendering & memory profiling
Dev tools rendering & memory profilingDev tools rendering & memory profiling
Dev tools rendering & memory profiling
 
All about that reactive ui
All about that reactive uiAll about that reactive ui
All about that reactive ui
 
FluentMigrator - Dayton .NET - July 2023
FluentMigrator - Dayton .NET - July 2023FluentMigrator - Dayton .NET - July 2023
FluentMigrator - Dayton .NET - July 2023
 
Design of Experiments on Federator Polystore Architecture
Design of Experiments on Federator Polystore ArchitectureDesign of Experiments on Federator Polystore Architecture
Design of Experiments on Federator Polystore Architecture
 
Cloud accounting software uk
Cloud accounting software ukCloud accounting software uk
Cloud accounting software uk
 
Gopher in performance_tales_ms_go_cracow
Gopher in performance_tales_ms_go_cracowGopher in performance_tales_ms_go_cracow
Gopher in performance_tales_ms_go_cracow
 
Js memory
Js memoryJs memory
Js memory
 
Scalable JavaScript
Scalable JavaScriptScalable JavaScript
Scalable JavaScript
 
Big Data Tutorial V4
Big Data Tutorial V4Big Data Tutorial V4
Big Data Tutorial V4
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL 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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 

When to use Node? Lessons learned

  • 1. When to use Node.js? Lessons learned Coen Stevens - Amsterdam Node Meetup 2012 @beatlevic BeatleTech.com Saturday, March 31, 12
  • 3. Why not Node.js • We never heard of Node.js at the time (2009) and were experienced in Ruby • Lots of server-side computations / statistics / map-reduce (blocking the node event-loop) • Typical dashboard (view on a database) • Not that many concurrent users • No need for open connections Yes, I would use Ruby again Saturday, March 31, 12
  • 4. Pivot: Penny auctions • Swoopo and Bigdeal (real goods) • Newcope a platform for pay-per-bid auction games for virtual goods Saturday, March 31, 12
  • 5. Flash game platform http://newcope-heyzap.heroku.com/home Saturday, March 31, 12
  • 6. • The Broth: BarnBuddy • Facebook app • Similar to Farmville • Over 1 million active users per month Saturday, March 31, 12
  • 7. Challenge • Build iframe / facebook app solution • Have the auctions as realtime as possible • Long polling (later websockets) vs pulling • Lots of users with open connections • Scalable Saturday, March 31, 12
  • 8. Languages considered • Ruby (Eventmachine, no Goliath yet) • JRuby • Scala (Twitter had just moved from ruby) • Erlang • Javascript Node.js Saturday, March 31, 12
  • 10. Node.js experiences • Functional programming • Javascript for both client and server • Very good performance (30k users the first day) • Node v0.1.25 and no packet manager (npm) • MySQL with DBSlayer (later Mongodb) • Nginx to serve static files • Easy to setup/deploy on EC2 (upstart deamon) • Everything async (annoying to test) • Fun! Yes, I would use Node.js again Saturday, March 31, 12
  • 11. Auction.prototype.startTimer = function() { var self = this;    if (this.timer) clearTimeout(this.timer);   this.emit("start");     this.timer = setTimeout(function() {     self.emit("end");   }, self.timeLeft() * 1000); } Auction.prototype.bid = function(user) {     var self = this;     return function (callback, errback) {      if (user.bid_count > 0 && self.status() === "running") {         user.bid_count -= 1;         dbUser.updateUser(user.id, {'bid_count': user.bid_count})(function(result){           if (self.timeLeft() < self.bidTimeDelta) {             self.setTime(me.bidTimeDelta);           };           self.price += self.bidPriceDelta;           var bid = { user: user, ts: new Date() }           self.bids.push(bid);           self.bidCount++;           callback(self);         }, function(error) {           user.bid_count += 1;           errback("Could not update new bid count");         })      } else {         errback("Bid could not be placed");      }   }; } Saturday, March 31, 12
  • 12. // continuation style var bid = function(user) {     return function (callback, errback) { if (!user) return errback("No user") callback(user) } } bid(user)(function(result){ console.log(result) }, function(error) { console.log(error) }) Saturday, March 31, 12
  • 13. // promise style var bid = function(user) { var promise = new Promise() if (!user) { promise.emitError("No user") } else { promise.emitSuccess(user) }   return promise } var promise = bid(user) promise.addErrback(function(error){ console.log(error) }) promise.addCallback(function(result) { console.log(result) }) Saturday, March 31, 12
  • 14. // callback style var bid = function(user, callback) { if (!user) return callback("No user") callback(null, user); } bid(user, function(err, result){ if (err) console.log(err) console.log(result) }) Saturday, March 31, 12
  • 15. • Bottlenose is the smartest social media dashboard. • Helping you manage the information overload on streams like twitter and Facebook • Bottlenose analyzes and filters messages using NLP and clustering techniques • Beta launched December 2011 http://bottlenose.com Saturday, March 31, 12
  • 17. Why Node.js? • It began (2009) with NLP in javascript, run it both on the client and the server • Fat client and lean server • Realtime stream updates • Lots of users (with open connections) • Alternatives? Yes, I would use Node.js again Saturday, March 31, 12
  • 18. Summary: When to use Node? • When you are building more of an app than a website and require lots of open connections to the server • When you want your users to get data in realtime (chat, streams) • When you have to serve lots of requests that do not take too many cpu cycles (blocking the loop) • When you like to work with Javascript all the way Saturday, March 31, 12
  • 19. Thanks! @beatlevic Saturday, March 31, 12