SlideShare une entreprise Scribd logo
1  sur  16
Télécharger pour lire hors ligne
When crontab must die
Francesco Laurita
ItalianCoders 19 June 2013, Milan - Italy
Building Scalable,
Distributed Job
Queues with Redis
(and Ruby)
Wednesday, June 19, 13
Playing with your backend
A Front End request is supposed to return a response really fast
There are certain actions that may take longer and can’t be executed “live”
* Processing an order (fraud detection, external service call)
* Converting a video
* Resizing an Image
* In general, Not customer-facing operations that might take longer than few
milliseconds (even delivering an email)
Wednesday, June 19, 13
Processing Jobs: The wrong way (crontab)
• It loads your database
• Almost impossible to scale
• Painful errors recovery
• Waste of time between each schedule
Wednesday, June 19, 13
Processing Jobs: The wrong way (crontab)
• It loads your database
• Almost impossible to scale
• Painful errors recovery
• Waste of time between each schedule
Wednesday, June 19, 13
Processing Jobs like a pro: Message Queue
• A producer pushes a message into a jobs queue
• One ore more consumer consume messages from a job queue
LPUSH RPOP
RPUSHLPOP
Wednesday, June 19, 13
Processing Jobs like a pro: Message Queue
Wednesday, June 19, 13
Our choice: Redis
What is it?
* Is a NoSQL DB
* Is an advanced Key/Value Store
* Is a caching server
* Is a lot of things...
Wednesday, June 19, 13
Our choice: Redis
What is it?
* It is a way to share Memory over TCP/IP
Can share memory (data structure) between different processes and
languages
* List (LinkedList) --> queue.pop, queue.push
* Hash --> {}
* Set --> Set
* SortedSet --> SortedSet.new
* ....
Wednesday, June 19, 13
A real use case
Q1
Q2
Q4
Q5
S1
S2
Q3 Q6
Qi = queue i | Sj = service j
S3
Wednesday, June 19, 13
Simple Queue vs Reliable Queue
Simple queue:
1) pushing values into a queue
2) a consumer waits for these values using polling or a blocking operation
* Is not reliable: a message can be lost
- Network problems
- Consumer crashes while consuming message
Wednesday, June 19, 13
Simple Queue vs Reliable Queue
Reliable queue:
1) pushing values into a queue
2) a consumer fetches a message and at the same time pushes it into a
processing list
3) remove the message from the processing list once message has been
processed
Wednesday, June 19, 13
Simple Queue vs Reliable Queue
Messages queueProducer Consumer
Processing list
/dev/null
push
push
pop
lrem
Wednesday, June 19, 13
Reliable Queue in Ruby
https://github.com/taganaka/redis-queue
gem install redis-queue
Wednesday, June 19, 13
Reliable Queue in Ruby
S1 S2 S3 S4 Sx
Wednesday, June 19, 13
Everything seems perfect....but
•Keep in mind that
• Redis is an in-memory database
• All of the operations are done atomically in memory
•But
• RAM cannot be expanded indefinitely
• RAM is expensive
• A queue of 1M of messages is about 370MB occupied on Redis (about 400
chars for each entry)
Wednesday, June 19, 13
That’s all Folks...Questions?
twitter.com/flaurita
github.com/taganaka
francesco@gild.com
facebook.com/francesco.laurita
www.gild.com
We are hiring!
Wednesday, June 19, 13

Contenu connexe

Similaire à Building Scalable, Distributed Job Queues with Redis and Ruby

MIS: Computers, Dr. Ashish K. Gupta
MIS: Computers, Dr. Ashish K. GuptaMIS: Computers, Dr. Ashish K. Gupta
MIS: Computers, Dr. Ashish K. GuptaAshish K Gupta
 
Bde sc3 2nd_workshop_2016_10_04_p05_bde_system_monitoring
Bde sc3 2nd_workshop_2016_10_04_p05_bde_system_monitoringBde sc3 2nd_workshop_2016_10_04_p05_bde_system_monitoring
Bde sc3 2nd_workshop_2016_10_04_p05_bde_system_monitoringBigData_Europe
 
Hotspot Garbage Collection - Tuning Guide
Hotspot Garbage Collection - Tuning GuideHotspot Garbage Collection - Tuning Guide
Hotspot Garbage Collection - Tuning GuidejClarity
 
How IBM's Massive POWER9 UNIX Servers Benefit from InfluxDB and Grafana Techn...
How IBM's Massive POWER9 UNIX Servers Benefit from InfluxDB and Grafana Techn...How IBM's Massive POWER9 UNIX Servers Benefit from InfluxDB and Grafana Techn...
How IBM's Massive POWER9 UNIX Servers Benefit from InfluxDB and Grafana Techn...DevOps.com
 
Arnaud Porterie - The Truth About C++
Arnaud Porterie - The Truth About C++Arnaud Porterie - The Truth About C++
Arnaud Porterie - The Truth About C++Arnaud Porterie
 
20130626 OpenRefine Introduction
20130626 OpenRefine Introduction20130626 OpenRefine Introduction
20130626 OpenRefine IntroductionMartin Magdinier
 
Writing SaltStack Modules - OpenWest 2013
Writing SaltStack Modules - OpenWest 2013Writing SaltStack Modules - OpenWest 2013
Writing SaltStack Modules - OpenWest 2013SaltStack
 
OSMC 2013 | Flapjack - monitoring notification system by Birger Schmidt
OSMC 2013 | Flapjack - monitoring notification system by Birger SchmidtOSMC 2013 | Flapjack - monitoring notification system by Birger Schmidt
OSMC 2013 | Flapjack - monitoring notification system by Birger SchmidtNETWAYS
 
Applying Evolutionary Architecture on a Popular API
Applying Evolutionary Architecture on a  Popular APIApplying Evolutionary Architecture on a  Popular API
Applying Evolutionary Architecture on a Popular APIPhil Calçado
 
Visualizing Internet-Measurements Data for Research Purposes: the NeuViz Data...
Visualizing Internet-Measurements Data for Research Purposes: the NeuViz Data...Visualizing Internet-Measurements Data for Research Purposes: the NeuViz Data...
Visualizing Internet-Measurements Data for Research Purposes: the NeuViz Data...giuseppe_futia
 

Similaire à Building Scalable, Distributed Job Queues with Redis and Ruby (11)

MIS: Computers, Dr. Ashish K. Gupta
MIS: Computers, Dr. Ashish K. GuptaMIS: Computers, Dr. Ashish K. Gupta
MIS: Computers, Dr. Ashish K. Gupta
 
Bde sc3 2nd_workshop_2016_10_04_p05_bde_system_monitoring
Bde sc3 2nd_workshop_2016_10_04_p05_bde_system_monitoringBde sc3 2nd_workshop_2016_10_04_p05_bde_system_monitoring
Bde sc3 2nd_workshop_2016_10_04_p05_bde_system_monitoring
 
Hotspot Garbage Collection - Tuning Guide
Hotspot Garbage Collection - Tuning GuideHotspot Garbage Collection - Tuning Guide
Hotspot Garbage Collection - Tuning Guide
 
How IBM's Massive POWER9 UNIX Servers Benefit from InfluxDB and Grafana Techn...
How IBM's Massive POWER9 UNIX Servers Benefit from InfluxDB and Grafana Techn...How IBM's Massive POWER9 UNIX Servers Benefit from InfluxDB and Grafana Techn...
How IBM's Massive POWER9 UNIX Servers Benefit from InfluxDB and Grafana Techn...
 
Arnaud Porterie - The Truth About C++
Arnaud Porterie - The Truth About C++Arnaud Porterie - The Truth About C++
Arnaud Porterie - The Truth About C++
 
20130626 OpenRefine Introduction
20130626 OpenRefine Introduction20130626 OpenRefine Introduction
20130626 OpenRefine Introduction
 
Writing SaltStack Modules - OpenWest 2013
Writing SaltStack Modules - OpenWest 2013Writing SaltStack Modules - OpenWest 2013
Writing SaltStack Modules - OpenWest 2013
 
OSMC 2013 | Flapjack - monitoring notification system by Birger Schmidt
OSMC 2013 | Flapjack - monitoring notification system by Birger SchmidtOSMC 2013 | Flapjack - monitoring notification system by Birger Schmidt
OSMC 2013 | Flapjack - monitoring notification system by Birger Schmidt
 
Applying Evolutionary Architecture on a Popular API
Applying Evolutionary Architecture on a  Popular APIApplying Evolutionary Architecture on a  Popular API
Applying Evolutionary Architecture on a Popular API
 
Velocity dust
Velocity dustVelocity dust
Velocity dust
 
Visualizing Internet-Measurements Data for Research Purposes: the NeuViz Data...
Visualizing Internet-Measurements Data for Research Purposes: the NeuViz Data...Visualizing Internet-Measurements Data for Research Purposes: the NeuViz Data...
Visualizing Internet-Measurements Data for Research Purposes: the NeuViz Data...
 

Dernier

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 

Dernier (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 

Building Scalable, Distributed Job Queues with Redis and Ruby

  • 1. When crontab must die Francesco Laurita ItalianCoders 19 June 2013, Milan - Italy Building Scalable, Distributed Job Queues with Redis (and Ruby) Wednesday, June 19, 13
  • 2. Playing with your backend A Front End request is supposed to return a response really fast There are certain actions that may take longer and can’t be executed “live” * Processing an order (fraud detection, external service call) * Converting a video * Resizing an Image * In general, Not customer-facing operations that might take longer than few milliseconds (even delivering an email) Wednesday, June 19, 13
  • 3. Processing Jobs: The wrong way (crontab) • It loads your database • Almost impossible to scale • Painful errors recovery • Waste of time between each schedule Wednesday, June 19, 13
  • 4. Processing Jobs: The wrong way (crontab) • It loads your database • Almost impossible to scale • Painful errors recovery • Waste of time between each schedule Wednesday, June 19, 13
  • 5. Processing Jobs like a pro: Message Queue • A producer pushes a message into a jobs queue • One ore more consumer consume messages from a job queue LPUSH RPOP RPUSHLPOP Wednesday, June 19, 13
  • 6. Processing Jobs like a pro: Message Queue Wednesday, June 19, 13
  • 7. Our choice: Redis What is it? * Is a NoSQL DB * Is an advanced Key/Value Store * Is a caching server * Is a lot of things... Wednesday, June 19, 13
  • 8. Our choice: Redis What is it? * It is a way to share Memory over TCP/IP Can share memory (data structure) between different processes and languages * List (LinkedList) --> queue.pop, queue.push * Hash --> {} * Set --> Set * SortedSet --> SortedSet.new * .... Wednesday, June 19, 13
  • 9. A real use case Q1 Q2 Q4 Q5 S1 S2 Q3 Q6 Qi = queue i | Sj = service j S3 Wednesday, June 19, 13
  • 10. Simple Queue vs Reliable Queue Simple queue: 1) pushing values into a queue 2) a consumer waits for these values using polling or a blocking operation * Is not reliable: a message can be lost - Network problems - Consumer crashes while consuming message Wednesday, June 19, 13
  • 11. Simple Queue vs Reliable Queue Reliable queue: 1) pushing values into a queue 2) a consumer fetches a message and at the same time pushes it into a processing list 3) remove the message from the processing list once message has been processed Wednesday, June 19, 13
  • 12. Simple Queue vs Reliable Queue Messages queueProducer Consumer Processing list /dev/null push push pop lrem Wednesday, June 19, 13
  • 13. Reliable Queue in Ruby https://github.com/taganaka/redis-queue gem install redis-queue Wednesday, June 19, 13
  • 14. Reliable Queue in Ruby S1 S2 S3 S4 Sx Wednesday, June 19, 13
  • 15. Everything seems perfect....but •Keep in mind that • Redis is an in-memory database • All of the operations are done atomically in memory •But • RAM cannot be expanded indefinitely • RAM is expensive • A queue of 1M of messages is about 370MB occupied on Redis (about 400 chars for each entry) Wednesday, June 19, 13