Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Autoscaling Node.js on AWS

Avatar for Rod Petrovic Rod Petrovic
November 26, 2014

Autoscaling Node.js on AWS

A talk on how we autoscaled a simple Node.js microservice (for event ingestion) on AWS. It hopefully shows that autoscaling isn't necessarily hard to do.

Avatar for Rod Petrovic

Rod Petrovic

November 26, 2014

Other Decks in Programming

Transcript

  1. API app.post '/events', (req, res) ->
 
 errors = validateEvent

    res.body
 
 if errors?
 res.status(400).send errors
 
 else
 writeToKinesis res.body
 res.status(202).send accepted: yes
  2. Queue Size queueSize = 0 writeToKinesis = (event) -> queueSize++

    params = { ... } kinesis.putRecord params, (err, data) -> queueSize--
  3. Taking a Break app.get '/status', (req, res) -> if queueSize

    < maxQueueSize res.status(200).send alive: yes else res.status(503).send alive: no
  4. Scaling Policy • Set a threshold < initial maxQueueSize •

    If average queue size goes over the threshold, add n instances to the auto scaling group • If average queue size goes under the threshold, remove m instances from the auto scaling group • Cool down period in both cases (a few minutes)
  5. The Result • The auto scaling group had between 7

    and 70 micro instances. • We were able to feed Kinesis, event by event, in near real time. • We did it for about 30% of the cost of an instance that would be big enough to do the same job.