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
Asynchronous Processing for Fun and Profit
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Mike Perham
November 02, 2012
Technology
11
890
Asynchronous Processing for Fun and Profit
Some pro tips and an overview of Sidekiq for great async victory!
Mike Perham
November 02, 2012
Tweet
Share
More Decks by Mike Perham
See All by Mike Perham
Computer Science vs Software Engineering
mperham
0
340
A Tribute to Ezra Zygmuntowicz
mperham
1
1.1k
Other Decks in Technology
See All in Technology
顧客との商談議事録をみんなで読んで顧客解像度を上げよう
shibayu36
0
210
ブロックテーマでサイトをリニューアルした話 / 2026-01-31 Kansai WordPress Meetup
torounit
0
460
Ruby版 JSXのRuxが気になる
sansantech
PRO
0
140
10Xにおける品質保証活動の全体像と改善 #no_more_wait_for_test
nihonbuson
PRO
2
230
30万人の同時アクセスに耐えたい!新サービスの盤石なリリースを支える負荷試験 / SRE Kaigi 2026
genda
3
1.2k
広告の効果検証を題材にした因果推論の精度検証について
zozotech
PRO
0
150
Frontier Agents (Kiro autonomous agent / AWS Security Agent / AWS DevOps Agent) の紹介
msysh
3
160
Agile Leadership Summit Keynote 2026
m_seki
1
580
AI駆動開発を事業のコアに置く
tasukuonizawa
1
130
GitLab Duo Agent Platform × AGENTS.md で実現するSpec-Driven Development / GitLab Duo Agent Platform × AGENTS.md
n11sh1
0
130
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.3k
Codex 5.3 と Opus 4.6 にコーポレートサイトを作らせてみた / Codex 5.3 vs Opus 4.6
ama_ch
0
120
Featured
See All Featured
RailsConf 2023
tenderlove
30
1.3k
Six Lessons from altMBA
skipperchong
29
4.1k
What's in a price? How to price your products and services
michaelherold
247
13k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Navigating Team Friction
lara
192
16k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
290
Site-Speed That Sticks
csswizardry
13
1.1k
Done Done
chrislema
186
16k
Heart Work Chapter 1 - Part 1
lfama
PRO
5
35k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
450
Color Theory Basics | Prateek | Gurzu
gurzu
0
200
A designer walks into a library…
pauljervisheath
210
24k
Transcript
Async Processing for Fun and Profit Mike Perham @mperham
Me Director of Engineering, TheClymb.com
Agenda • Basics • Protips • Sidekiq
Why? • User-Perceived Performance • I/O is SLOOOOOOOOOOOW • I/O
is unreliable
What? • Optional work • Anything not required to build
the HTTP response
How? • Client puts message on a queue • Server
pulls message off queue • Worker executes code based on message
How? async do # perform some work end
How? • Marshalling a Proc • Need to serialize closure
How? async(instance, :method, args)
How? • Marshal instance • Marshal args
How? async(Class, :method, args)
How? • Serialize just the class name • Marshal the
arguments
Congratulations! This is exactly how Resque and Sidekiq work.
How?
How?
How?
Tip #1 Small, Stateless Messages
Stateless • Database holds objects (nouns) • Queue holds actions
(verbs) • “Perform X on Object 123”
Avoid State • Bad • @user.delay.sync_images • Good • User.delay.sync_images(@user.id)
Simple Types • Small & Easy to read • Cross-platform
• Sidekiq / Resque use JSON
Debugging
Tip #2 Idempotent, Transactional Units of Work
Idempotent • Fancy computer science term • “Work can be
applied multiple times without changing the result beyond the initial application”
Idempotent • Canceling an order • Updating user’s email address
Not Idempotent! • Charging credit card • Sending email
Idempotent • Your code has bugs! • Sidekiq will retry
jobs that raise • Design jobs to be retried • e.g. verify you need to perform action before performing it
Transactional • Infinite credit?
Tip #3 Embrace Concurrency
Concurrency • Resque/DJ = 4 workers • Sidekiq = 100
workers • Mike, what is best in life?
“To crush their servers, see them smoking before you and
hear the lamentations of their admins.”
Concurrency • Use connection_pool gem to limit client connections •
Split work into small batches • 100 items => 10 jobs of 10 items
Concurrency • Thread safety rarely an issue • Most gem
maintainers very responsive • Recently fixed: • cocaine, typheuos
Theory, meet Practice
Sidekiq • Simple, efficient message processing • Like Resque, but
10x faster
MODERN RUBY IS NOT SLOW SINGLE THREADING IS SLOW
Concurrency • To scale single-threaded, create lots of processes. •
HORRIBLY RAM INEFFICIENT
Threads vs Processes • Example: 400MB single-threaded process • 25
processes = 10GB RAM = EC2 xlarge • 25 threads = 1GB RAM = EC2 small • $60/month vs $480/month • 160 dynos => 10 dynos • 150 dynos * $35/month =~ $5000/month
Quick Rant • GIL + poor GC • C extension
API must DIE • What’s larger: 50% or 800%?
Client Your App Client Middleware Redis Sidekiq Client API Rails
Process
Server Processor Server Middleware Redis Worker Sidekiq Process Processor Server
Middleware Worker Processor Server Middleware Worker Processor Server Middleware Worker Fetcher Manager
Versions • Sidekiq - Free, LGPLv3 • Sidekiq Pro -
more features, support, $ • motivation!
Features Sidekiq Resque DJ Concurrency Store Hooks Web UI Scheduler
Retry Delay Batches Threads Processes Processes Redis Redis DB middleware callbacks callbacks ✓ ✓ ? ✓ ? ✓ ✓ ? ✓ ✓ ? ✓ Pro ? - ? - optional
Future • Nicer, more functional Web UI • APIs for
managing queues / retries • Rails 4 Queue API
Pro Future • Enterprise-y features • Workflow • Notifications
Conclusion • small, stateless messages • idempotent / transactional •
concurrency • sidekiq
Questions? @mperham
[email protected]