ankane/production_rails

Caching & Mailer best practices

oyeanuj opened this issue · 3 comments

Hi @ankane, this list is super helpful to most of us who haven't deployed to production before. Would you be able to include a section on caching and mailers in production as well?

Thank you for creating this!

Added a few tips. Let me know if there are other topics you're interested in.

This is super helpful, if I can ask a couple of followups on that commit:

  1. I am on a Rails API only project (with a React frontend), so wondering if for caching, you have any API caching tips? They seem to be hard to find. From your experience, HTTP level caching vs model level caching? Russian doll caching or simple data-stores work well?

  2. Any tips to keep in mind while scaling? Especially dealing with Heroku, some best practices there?

Thank you!

I typically keep caching pretty simple. Either action caching (https://github.com/rails/actionpack-action_caching), fragment caching, or simply in a controller:

Rails.cache.fetch("some_key", expires_in: 5.minutes) do
  # return something
end

You can get pretty far with almost no caching - only cache what absolutely needed for performance.

For scaling, it's about finding bottlenecks and fixing them. Again, don't optimize prematurely.

Overall, my advice would be focus on your product and only worry about caching and scaling when it begins to get in the way of delivering a great user experience.