title: How can I stop active record callbacks from throwing an error when they fail?
body: <p>I have a Rails app that includes some <code>after_save</code> active record callbacks, which are responsible for updating a second cache database.</p>
  <p>Recently I was having some load issues and the second database was slow to respond or refusing connections, and my users started getting 500 errors when they tried to save objects.</p>
  <p>I think this was down to me misunderstanding how callbacks work - I assumed that by making these <code>after_save</code> rather than <code>before_save</code>, the user was &quot;safe&quot; and if the callback failed, that would be graceful and silent.</p>
  <p><strong>How might I refactor my code to stop this behaviour and avoid exposing my users to error messages when these callbacks fail?</strong></p>
  <p>I've looked at refactoring the callbacks to simply trigger an active job, like this:</p>
  <pre><code># models/mymodel.rb
  
  after_save :update_index
  
  def update_index
      UpdateIndexJob.perform_later(self)
  end
  
  </code></pre>
  <p>The active job includes the logic for actually updating the second cache database.</p>
  <p>I'm not sure whether I would also need to implement sidekiq and redis for this to work.</p>
  <p>I've also read about <a href="https://stackoverflow.com/questions/1531514/observers-vs-callbacks">rails observers</a>, which apparently work similar to callbacks but don't break the request-response cycle when they fail.</p>