Async programming can make your apps faster. I’ll share how you can use async in Ruby on Rails to speed up your app. While there are examples in

Async Ruby on Rails

submited by
Style Pass
2024-06-07 17:30:07

Async programming can make your apps faster. I’ll share how you can use async in Ruby on Rails to speed up your app. While there are examples in Ruby, the principles apply to any language.

If you want an introduction to async programming or prefer a video format, I also gave a talk about it at Tropical.rb 2024.

Pay attention when you use a method that ends with _now. They’re strong candidates for things that can be done async. A common example is sending emails. Imagine a Rails controller that sends an email after a user registers:

The request doesn’t need to wait for the email to be sent to complete. Using deliver_later here can make the request faster. The same applies to any other kind of job! If you’re saving statistics, processing data, or something else that doesn’t need to be done right now, perform_later.

You can configure the maximum number of records that will be destroyed in a background job by the dependent: :destroy_async association option.

Leave a Comment