Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Sidekiq on the surface and under the hood

Sidekiq on the surface and under the hood

A presentation about Sidekiq on Wroclove.rb 2022. Good practices, design patterns to follow, and habits to develop to build a well-working background job processing system. Sidekiq internals, the way it communicates with Redis, and how the middleware is working.

Paweł Dąbrowski

September 18, 2022
Tweet

Other Decks in Programming

Transcript

  1. ABOUT ME briefly Hello, I'm Paweł Dąbrowski. I write for

    both human beings and computers, a lot. With Ruby since 2010 IT Samurai, CTO @ iRonin https://paweldabrowski.com https://ironin.it/blog https://twitter.com/pdabrowski6 https://github.com/pdabrowski6
  2. SIDEKIQ? What is Simple, efficient background processing for Ruby OPEN

    Source SIMPLE and EFFICIENT WORK OUTSIDE RAILS
  3. ON THE SURFACE UNDER THE HOOD Good practices, useful patterns,

    mistakes to avoid The connection with Redis, paid versions, plugins and middleware m o r e m o r e
  4. GOOD PRACTICES - do not annoy customers - do not

    waste the money - do not waste time Why should you care about
  5. IDEA OF SIMPLE PARAMS 01 02 03 EASIER TO QUEUE

    EASIER TO FIND BETTER ISOLATION EASY TESTING 04 HAPPIER REDIS 05
  6. Faster processing with concurrency Possible to queue manually only one

    job Easy to retry only one job and it won't affect the whole process Progress tracking
  7. JOB A has handling for error a handling for error

    B handling for error C JOB B has JOB C has
  8. If you want to retry, make sure you are able

    to rollback to initial state.
  9. Create error wrapper Or report error when you retried multiple

    times and the game is over for the job. 1.
  10. Or report error when you retried multiple times and the

    game is over for the job. 2. Re-raise error with the wrapper
  11. Or report error when you retried multiple times and the

    game is over for the job. 3. Do not report the error wrapper
  12. Or report error when you retried multiple times and the

    game is over for the job. 4. Report the original error after all retries
  13. MEAN? What do you Take care of the configuration of

    the log, thank me later. SAVE LOGS LOG JOB EXECUTION LOG INSIDE THE JOB
  14. As of Sidekiq 6.0, you have to take care of

    log redirection. bundle exec sidekiq 2>&1 >> ./log/sidekiq.log
  15. SIDEKIQ INTERNALS - learn how to extend Sidekiq - debug

    more effectively - become better developer Why should you care about
  16. MY PHILOSOPHY FOR LEARING Learn how to use BUILD SOMETHING

    RUN IN PRODUCTION Learn good practices Look under the hood
  17. MY PHILOSOPHY FOR LEARING Learn how to use BUILD SOMETHING

    RUN IN PRODUCTION Learn good practices Look under the hood LOOK INTO DOCUMENTATION
  18. - in-memory data store - open source - key value

    pairs - data types: sets, sorted sets, lists, hashes
  19. ADD JOB TO QUEUE PASS PARAMS ASSIGN DEFAULT PARAMS validation

    MIDDLEWARE PUSH QUEUE PUSH PAYLOAD VERIFY JSON
  20. VALIDATION JOB IS A HASH AT IS NUMERIC IF GIVEN

    ARGS ARE IN ARRAY TAGS ARE IN ARRAY JOB CLASS IS STRING / CLASS
  21. ASSIGN DEFAULT PARAMS Page 03 of 15 RETRY: TRUE QUEUE:

    DEFAULT CREATED_AT: TIME.now.TO_F JID: SecureRandom.hex(12)
  22. LATER? perform NO YES ZADD Add member with score to

    sorted set. SADD LPUSH Add member to set, ignore if exists Add to the head of the list
  23. MANAGER FLOW If format is wrong, job is added to

    the dead queue. Simply create instance of job and call #perform on it. DECODE PAYLOAD INVOKE MIDDLEWARE EXECUTE JOB