Creating Scalable Node.js Applications

Doug Martin

Topics Covered

  • Project organization
  • Property configuration
  • Logging
  • Scaling across cores and machines

Project Organization!

Reusable Modules

  • Organize code into modules
    • Model
    • Routes
    • Helper/Util
    • Logging

grunt-link

grunt-link allows the linking of local modules.

To add grunt link to your project

npm install --save-dev grunt-link

And in your Gruntfile

grunt.loadNpmTask("grunt-link");

Example

Open project1.

Run

npm install
grunt link

Configuration

  • Multiple files
  • Different environments
  • Overrides for development
  • Single point of entry

Gofigure

gofigure is a module that loads your configuration files and handles the merging and monitoring of configuration properties based on the current environment.

To add gofigure to your project

npm install --save gofigure

Example

Building off of the previous example lets add some logic to our config module!

Logging

comb

At c2fo we use a module called comb which contains utilities that we use in all of our projects.

In this example we will use the comb logger.

comb.logger

To add comb to your project.
npm install --save comb

Example

Lets add some logging to our modules.

Scaling Cores and Machines

Worker Processes

Cluster

Node has a core module called cluster which allows a scaling across cores but has some drawbacks.

werker

werker is a module for creating a pool of werker processes for scaling across cores.

Worker Queues

RabbitMQ

  • Robust messaging for applications
  • Easy to use
  • Runs on all major operating systems
  • Supports a huge number of developer platforms
  • Open source and commercially supported

hare

hare is a wrapper around node-amqp that makes setting up different types messaging configurations easy.

Questions?

Sponsors
Fork me on GitHub
Tweet