SlideShare uma empresa Scribd logo
1 de 16
Baixar para ler offline
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

Mais conteúdo relacionado

Semelhante a 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
 

Semelhante a 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...
 

Último

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Último (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

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