Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Background jobs at scale (Montreal.rb)
Search
Kerstin Puschke
February 26, 2019
Programming
0
360
Background jobs at scale (Montreal.rb)
Talks at Montreal.rb
Kerstin Puschke
February 26, 2019
Tweet
Share
More Decks by Kerstin Puschke
See All by Kerstin Puschke
High availability by offloading work - background jobs, message queues, or Kafka
titanoboa
0
440
EuRuKo 2018: Scaling a monolith isn't scaling microservices
titanoboa
2
120
Background jobs at scale
titanoboa
1
58
Background jobs at scale
titanoboa
0
56
Decouple all the things: Asynchronous messaging keeps it simple
titanoboa
0
110
Decouple all the things - Asynchronous messaging keeps it simple
titanoboa
0
85
Decouple all the things - asynchronous messaging keeps it simple
titanoboa
0
460
Decouple all the things - asynchronous messaging keeps it simple
titanoboa
0
610
No RSVP required: Asynchronous Messaging
titanoboa
0
300
Other Decks in Programming
See All in Programming
クリーンアーキテクチャから見る依存の向きの大切さ
shimabox
2
270
GAEログのコスト削減
mot_techtalk
0
120
『GO』アプリ バックエンドサーバのコスト削減
mot_techtalk
0
140
sappoRo.R #12 初心者セッション
kosugitti
0
250
第3回関東Kaggler会_AtCoderはKaggleの役に立つ
chettub
3
1k
Rails アプリ地図考 Flush Cut
makicamel
1
120
『GO』アプリ データ基盤のログ収集システムコスト削減
mot_techtalk
0
120
Multi Step Form, Decentralized Autonomous Organization
pumpkiinbell
1
740
pylint custom ruleで始めるレビュー自動化
shogoujiie
0
120
AWS Organizations で実現する、 マルチ AWS アカウントのルートユーザー管理からの脱却
atpons
0
150
2024年のkintone API振り返りと2025年 / kintone API look back in 2024
tasshi
0
220
Kubernetes History Inspector(KHI)を触ってみた
bells17
0
230
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
The World Runs on Bad Software
bkeepers
PRO
67
11k
Building an army of robots
kneath
303
45k
Designing on Purpose - Digital PM Summit 2013
jponch
117
7.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
A better future with KSS
kneath
238
17k
A Tale of Four Properties
chriscoyier
158
23k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
1k
YesSQL, Process and Tooling at Scale
rocio
172
14k
Navigating Team Friction
lara
183
15k
Producing Creativity
orderedlist
PRO
344
39k
How STYLIGHT went responsive
nonsquared
98
5.4k
Transcript
Kerstin Puschke @titanoboa42 Background jobs at scale
None
@titanoboa42 Scaling applications using background jobs keeping code simple
@titanoboa42 Outline
@titanoboa42 • Introduction to background jobs Outline
@titanoboa42 • Introduction to background jobs • Features Outline
@titanoboa42 • Introduction to background jobs • Features • Mastering
challenges Outline
@titanoboa42 Outline
@titanoboa42 • Being RESTful Outline
@titanoboa42 • Being RESTful • Background jobs at scale Outline
@titanoboa42 • Being RESTful • Background jobs at scale •
Summary Outline
@titanoboa42 Introduction to background jobs
@titanoboa42 Background job: Work to be done later App Server
Worker
@titanoboa42 Asynchronous communication App Server Message Queue Worker
@titanoboa42 Asynchronous communication App Server Message Queue Worker Task Queue
@titanoboa42 Asynchronous communication App Server Message Queue Worker Worker Worker
Task Queue
@titanoboa42 Background job backend: task queue & broker
@titanoboa42 Encapsulating async communication
@titanoboa42 Features
@titanoboa42 Task Queue Response times App Server Worker
@titanoboa42 Task Queue Spikeability App Server Worker
@titanoboa42 Task Queue Parallelization App Server Worker Worker Worker
@titanoboa42 Task Queue Retries App Server Worker Worker Worker
@titanoboa42 Prioritization App Server Worker Worker High Prio Queue Low
Prio Queue
@titanoboa42 Prioritization App Server Worker Worker High Prio Queue Low
Prio Queue
@titanoboa42 Prioritization App Server Worker Worker High Prio Queue Low
Prio Queue
@titanoboa42 Mastering challenges
@titanoboa42 No exactly once delivery
@titanoboa42 • “At least” vs. “at most” once delivery No
exactly once delivery
@titanoboa42 • “At least” vs. “at most” once delivery •
Idempotent jobs & at least once delivery No exactly once delivery
@titanoboa42 Out of order delivery
@titanoboa42 • If order matters, queue sequentially Out of order
delivery
@titanoboa42 • If order matters, queue sequentially • First job
queues follow up jobs Out of order delivery
@titanoboa42 Job queued and processed by different versions
@titanoboa42 • No breaking changes to job parameters Job queued
and processed by different versions
@titanoboa42 • No breaking changes to job parameters • Changes
need to be backwards compatible until legacy jobs have been processed Job queued and processed by different versions
@titanoboa42 Eventual consistency (at best)
@titanoboa42 • Prepare for inconsistency Eventual consistency (at best)
@titanoboa42 • Prepare for inconsistency • Trade-off lack of consistency
guarantees vs. benefits of background jobs Eventual consistency (at best)
@titanoboa42 Non-transactional queuing
@titanoboa42 • Don’t queue from within a db transaction Non-transactional
queuing
@titanoboa42 • Don’t queue from within a db transaction •
Job runs before commit, or if rollback Non-transactional queuing
@titanoboa42 • Don’t queue from within a db transaction •
Job runs before commit, or if rollback • Commit before queuing or stage transactionally Non-transactional queuing
@titanoboa42 Being RESTful
@titanoboa42 Don’t lie about resource creation
@titanoboa42 • 202 Accepted Don’t lie about resource creation
@titanoboa42 • 202 Accepted • Location: temporary resource Don’t lie
about resource creation
@titanoboa42 • 202 Accepted • Location: temporary resource • 303
See other Don’t lie about resource creation
@titanoboa42 • 202 Accepted • Location: temporary resource • 303
See other • Location: does not represent target resource Don’t lie about resource creation
@titanoboa42 Callers can enforce (a)sync behaviour
@titanoboa42 • Expect header Callers can enforce (a)sync behaviour
@titanoboa42 • Expect header • 202-accepted Callers can enforce (a)sync
behaviour
@titanoboa42 • Expect header • 202-accepted • 200-ok/201-created/204-no-content Callers can
enforce (a)sync behaviour
@titanoboa42 • Expect header • 202-accepted • 200-ok/201-created/204-no-content • 417
Expectation failed Callers can enforce (a)sync behaviour
@titanoboa42 Background jobs at scale
@titanoboa42 DelayedJob is easy to get started
@titanoboa42 • No additional infrastructure DelayedJob is easy to get
started
@titanoboa42 • No additional infrastructure • ActiveRecord DelayedJob is easy
to get started
@titanoboa42 ActiveJob makes swapping backends easy
@titanoboa42 DelayedJob issues
@titanoboa42 • Overhead of relational database DelayedJob issues
@titanoboa42 • Overhead of relational database • Workers monitored from
outside DelayedJob issues
@titanoboa42 • Overhead of relational database • Workers monitored from
outside • Frequently needs workers to restart DelayedJob issues
@titanoboa42 Resque scales
@titanoboa42 • Redis - no relational db Resque scales
@titanoboa42 • Redis - no relational db • Parent-child forking
for workers Resque scales
@titanoboa42 • Redis - no relational db • Parent-child forking
for workers • Rarely needs workers to restart Resque scales
@titanoboa42 • Redis - no relational db • Parent-child forking
for workers • Rarely needs workers to restart • Workers manage their own state Resque scales
@titanoboa42 Resque issues
@titanoboa42 • Child processes Resque issues
@titanoboa42 • Child processes • Memory hungry and slow Resque
issues
@titanoboa42 Sidekiq scales
@titanoboa42 • Redis - no relational db Sidekiq scales
@titanoboa42 • Redis - no relational db • Threads instead
of child processes Sidekiq scales
@titanoboa42 • Redis - no relational db • Threads instead
of child processes • Fast and less memory hungry Sidekiq scales
@titanoboa42 Sidekiq issues
@titanoboa42 • Requires thread safe code Sidekiq issues
@titanoboa42 Long running jobs - Resque
@titanoboa42 • Prevent worker shutdown Long running jobs - Resque
@titanoboa42 • Prevent worker shutdown • No deployments Long running
jobs - Resque
@titanoboa42 • Prevent worker shutdown • No deployments • Not
cloud-friendly Long running jobs - Resque
@titanoboa42 • Aborted and requeued on shutdown Long running jobs
- Sidekiq
@titanoboa42 • Aborted and requeued on shutdown • Job may
not finish before being aborted again Long running jobs - Sidekiq
@titanoboa42 github.com /Shopify/job-iteration
@titanoboa42 Large collections
@titanoboa42 • Split job into collection and task to be
done Large collections
@titanoboa42 • Split job into collection and task to be
done • Checkpoint after iteration & requeue Large collections
@titanoboa42 Interruptible job with automatic resuming
@titanoboa42 • Shutdown workers anytime Interruptible job with automatic resuming
@titanoboa42 • Shutdown workers anytime • Disaster prevention Interruptible job
with automatic resuming
@titanoboa42 • Shutdown workers anytime • Disaster prevention • Data
integrity Interruptible job with automatic resuming
@titanoboa42 Abstracting scaling issues simplifies concrete background jobs
@titanoboa42 github.com /Shopify/job-iteration
@titanoboa42 Background jobs
@titanoboa42 • Benefit apps of all sizes Background jobs
@titanoboa42 • Benefit apps of all sizes • Require trade-offs
Background jobs
@titanoboa42 • Benefit apps of all sizes • Require trade-offs
• Keep code simple at scale Background jobs
Thanks! Questions? @titanoboa42 https://www.shopify.com/careers