SlideShare a Scribd company logo
atx node.js
August Meetup
background jobs
in an async world
Cody Stoltman
@particlebanana
sponsors
who are you?
Cody Stoltman
@particlebanana
co-founder of Treeline
Sails.js core team
maintainer of Waterline ORM
what’s a background job?
browser /foo/bar
does
some stuff
normal request/response lifecycle
browser /foo/bar
does
some stuff
slow function
long running process lifecycle
browser /foo/bar
does
some stuff
slow function
this isn’t ruby
node is async
we have callbacks
what does blocking mean?
browser 1
traditionally
browser 2
server
do something
browser 1
with node.js
browser 2
server
do something
browser 3
browser /foo/bar
does
some stuff
slow fuction
how can we handle that function?
• callbacks
• just ignore the callback
• over engineer something related
to process spawning
Background processes and tasks in an async world
why this isn’t ideal
we aren’t blocking so the server can
keep responding
but we have to wait until the process is
done before responding to the client’s
request
how can we handle that function?
• callbacks
• just ignore the callback
• over engineer something related
to process spawning
browser /foo/bar
does
some stuff
slow function
Background processes and tasks in an async world
why this isn’t ideal
the client get’s data back but we have no
clue as to the success/failure of the task.
we could add logs but we have no way to
give the client feedback or to re-try.
how can we handle that function?
• callbacks
• just ignore the callback
• over engineer something related
to process spawning
let’s learn from our synchronous,
threaded brothers and sisters
whats the answer then?
how can we handle that function?
• remote queues
remote queue
queue worker
slow function
server
does
some stuff
job
browser
job
why this is better
We can observe our queue
We can scale out horizontally and add
capacity as needed
Our queue can be preserved so no jobs
are abandoned
scalable remote queue
server server server server
worker worker worker worker
load balancer
queue
back to that event loop thing
Background processes and tasks in an async world
call stack libuv api
callback queue
event loop
.on()
handler
handler ()
lets see what blocking actually means
call stack libuv api
callback queue
event loop
.on()
handler
handler ()
delayFn ()
handler handler handler
handler ()
so synchronous code blocks the
event loop, don’t do that
what happens if we don’t block it?
call stack libuv api
callback queue
event loop
.on()
handler
handler()
sendEmail() queue
cbhandler handler
cb()handler()
sendEmail() queue
cb
remote queues are good because
they let you do more, faster
so more work in the event loop
means less concurrency
when should you move a function into
a background job?
if for any reason it will block the
event loop
it will prevent the response from
returning in a timely manner
node modules
node-resque
github.com/taskrabbit/node-resque
kue
github.com/Automattic/kue
bull
github.com/OptimalBits/bull
most queues are built on redis
Disque

github.com/antirez/disque
you could also build on a
traditional message queue
summary
remote queues in node same as
anywhere else
actually better because you can do more
on a single cpu simultaneously
(example: sending emails)
scheduled tasks
you need a database backed scheduler
someone should write one
agenda (mongo only)
github.com/rschmukler/agenda
until then
demo
thanks!
Phillip Roberts (@latentflip)

github.com/latentflip/loupe
Evan Tahler (@evantahler)

blog.evantahler.com
atx node.js
August Meetup

More Related Content

KEY
Concurrency in ruby
PDF
Event Machine
PDF
Embracing the Future
PDF
ESNext, service workers, and the future of the web
PPTX
JS Fest 2018. Алексей Волков. Полезные инструменты для JS разработки
PPT
Ruby vs Node ShiningRay Shanghai
PDF
Distributed Queue System using Gearman
PDF
Mongrel Handlers
Concurrency in ruby
Event Machine
Embracing the Future
ESNext, service workers, and the future of the web
JS Fest 2018. Алексей Волков. Полезные инструменты для JS разработки
Ruby vs Node ShiningRay Shanghai
Distributed Queue System using Gearman
Mongrel Handlers

What's hot (20)

PPTX
Distributed Applications with Perl & Gearman
ODP
Grape golilath
PPTX
Gearman, Supervisor and PHP - Job Management with Sanity!
PDF
Queue your work
PPT
Gearman - Job Queue
PPTX
What is Node.js
PPTX
Automating JavaScript testing with Jasmine and Perl
PDF
Faster PHP apps using Queues and Workers
PDF
Gearman: A Job Server made for Scale
PDF
Converting LotusScript Agents to Java Agents
KEY
Gearman and CodeIgniter
PDF
Khanh-Nguyen - Gearman - distributed process solution
KEY
Scale like a pro with Gearman
PPT
Gearman and asynchronous processing in PHP applications
PDF
I Promise You
PDF
YAPC::EU 2015 - Perl Conferences
PDF
Mastering Async/Await in JavaScript
KEY
Why I Love TorqueBox (And Why You Will Too)
PDF
Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016
PPTX
Continuous deployment of Rails apps on AWS OpsWorks
Distributed Applications with Perl & Gearman
Grape golilath
Gearman, Supervisor and PHP - Job Management with Sanity!
Queue your work
Gearman - Job Queue
What is Node.js
Automating JavaScript testing with Jasmine and Perl
Faster PHP apps using Queues and Workers
Gearman: A Job Server made for Scale
Converting LotusScript Agents to Java Agents
Gearman and CodeIgniter
Khanh-Nguyen - Gearman - distributed process solution
Scale like a pro with Gearman
Gearman and asynchronous processing in PHP applications
I Promise You
YAPC::EU 2015 - Perl Conferences
Mastering Async/Await in JavaScript
Why I Love TorqueBox (And Why You Will Too)
Deploying node.js at scale - Maraschi, Collina - Codemotion Amsterdam 2016
Continuous deployment of Rails apps on AWS OpsWorks
Ad

Viewers also liked (20)

PDF
Substance Abuse Ingham, Michigan
PPT
Дзвони душі Віктора Погрібного
DOC
new cv15
PDF
Substance Abuse Shiawassee, Michigan
PPTX
1 4 презентация bell-intera
PDF
BTB test
PDF
itd object 2
PDF
Desalination_Taking_Ocean_Water_to_Taps
PPTX
Trabalho Servidor FTP
DOC
Juliet Lopez
PDF
Ha Thi Doan cv
PDF
Tesla di fond-oinfondo_giugno2015
PDF
Macani Ship Wood Catalogue Highlights
PDF
Bringing Green Home Silcock EMBA Project Oct 2008
PDF
Substance Abuse Missaukee, Michigan
PDF
FYP Report rev34 AM-10-04-15
PDF
Ici&itd 2015 project 1
PDF
Substance Abuse Mackinac, Michigan
PDF
Michael Kühne - How to Build an API Your Developers will Love - code.talks 2015
PDF
Robert Reiz - How to Build a Tech Startup - code.talks 2015
Substance Abuse Ingham, Michigan
Дзвони душі Віктора Погрібного
new cv15
Substance Abuse Shiawassee, Michigan
1 4 презентация bell-intera
BTB test
itd object 2
Desalination_Taking_Ocean_Water_to_Taps
Trabalho Servidor FTP
Juliet Lopez
Ha Thi Doan cv
Tesla di fond-oinfondo_giugno2015
Macani Ship Wood Catalogue Highlights
Bringing Green Home Silcock EMBA Project Oct 2008
Substance Abuse Missaukee, Michigan
FYP Report rev34 AM-10-04-15
Ici&itd 2015 project 1
Substance Abuse Mackinac, Michigan
Michael Kühne - How to Build an API Your Developers will Love - code.talks 2015
Robert Reiz - How to Build a Tech Startup - code.talks 2015
Ad

Similar to Background processes and tasks in an async world (20)

PDF
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
PPTX
Introduction to Node.js
PPTX
Node.js: A Guided Tour
PDF
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
PDF
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
PPTX
Events for JavaScript event loop track.pptx
PDF
Node js internal
PPTX
Beginners Node.js
PPTX
PDF
Server Side Event Driven Programming
PPTX
Building node.js applications on windows azure
PPT
JavaScript Event Loop
PDF
Introduction to Node.js
PPTX
How NOT to write in Node.js
PPTX
ODP
Introduce about Nodejs - duyetdev.com
PDF
Real timeninja - Codemotion 2015 Roma
PPTX
The JavaScript Event Loop - Concurrency in the Language of the Web
KEY
Playing With Fire - An Introduction to Node.js
PPTX
Introduction to Node js
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
Introduction to Node.js
Node.js: A Guided Tour
"Node.js vs workers — A comparison of two JavaScript runtimes", James M Snell
Beautiful code instead of callback hell using ES6 Generators, Koa, Bluebird (...
Events for JavaScript event loop track.pptx
Node js internal
Beginners Node.js
Server Side Event Driven Programming
Building node.js applications on windows azure
JavaScript Event Loop
Introduction to Node.js
How NOT to write in Node.js
Introduce about Nodejs - duyetdev.com
Real timeninja - Codemotion 2015 Roma
The JavaScript Event Loop - Concurrency in the Language of the Web
Playing With Fire - An Introduction to Node.js
Introduction to Node js

Recently uploaded (20)

PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Encapsulation theory and applications.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Machine Learning_overview_presentation.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Electronic commerce courselecture one. Pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Spectroscopy.pptx food analysis technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Review of recent advances in non-invasive hemoglobin estimation
MYSQL Presentation for SQL database connectivity
Encapsulation_ Review paper, used for researhc scholars
Encapsulation theory and applications.pdf
Spectral efficient network and resource selection model in 5G networks
Machine Learning_overview_presentation.pptx
Approach and Philosophy of On baking technology
20250228 LYD VKU AI Blended-Learning.pptx
Assigned Numbers - 2025 - Bluetooth® Document
Electronic commerce courselecture one. Pdf
Empathic Computing: Creating Shared Understanding
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Machine learning based COVID-19 study performance prediction
Spectroscopy.pptx food analysis technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
The AUB Centre for AI in Media Proposal.docx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Background processes and tasks in an async world