node package manager



Build Status

celerity uses redis to do centralized rate limiting for applications running on multiple heroku dynos (or processes).


npm install celerity


see example.js for a simple rate limited webserver using celerity


var celerity = require('celerity');
var redis = require('redis');
var config = {
    redis: redis.createClient(),
    timespan: 10 * 1000,
    bucketCount: 10

celerity keeps the rate for the last timespan milliseconds.

timespan is divided into bucketCount buckets. the rate is stored in the buckets. buckets older than timespan expire every timespan / bucketCount milliseconds.

a higher bucketCount increases the frequency and accuracy of the expires but uses more memory and results in slower read operations. if timespan is several seconds long it is usually enough to have a bucket for every second.

use the prefix property to set a prefix for all redis keys used by celerity. the default prefix is celerity:.

increment(config, event, n, cb)
celerity.increment(config, 'event', 1, function(err) {

atomic. complexity: O(1).

read(config, event, cb), 'event', function(err, rate) {

atomic. complexity: O(n) where n is bucketCount.

incrementAndRead(config, event, n, cb)
celerity.incrementAndRead(config, 'event', 1, function(err, rate) {

atomic. complexity: O(n) where n is bucketCount.

license: MIT