You've been working hard over the past few months on your app that's built using Ruby on Rails. Let's say its a blogging platform, with social network elements around it.
You have fixed most issues and are now ready to open the gates to users ( hopefully, lots of them :) )
You want to make sure your servers don't crash and burn when you launch.
Here are a some points, from experience, that I recommend you check off your list, before you go live.
Moving non critical tasks into the background
I love sidekiq gem for this. You should definitely move stuff like :
- sending push notifications
- notification emails
- updating counts in cache when a user likes some content/ follows another user.
Cache your frequent queries to avoid overloading your database. Examples :
- Adding an article to a user's list of favourites or bookmarked.
- Increasing/Decreasing comment count on an Article when a comment is added/removed
- Maintaining user follow relationships, counts.
Proper DB constraints :
Do not just stop beyond
has_one/has_many. This does not add foreign key constraints on the database.
foreignergem and uncover all the loopholes in your data relationships and fix them ASAP.
Measure Measure Measure
Use a tool like NewRelic and keep a check on your server response times. Without this, you're in the blind and have no idea if your servers are burning or if they're just chilling (and can be reduced)
Set up a slave database
Slow non user facing activities should always happen on the slave database. Also make sure you have automated backups for the DB in place.
Do some load testing.
I highly recommend using Loader.io. Dead simple to use and produces really easy to understand reports.
Set up an exception notification system :
You should know when exceptions happen or if requests take too long. Set up notifiers and hook them up to your email and slack. Also have more than one developer receive them.
Anything that can go wrong, will go wrong. And you should be prepared for it.
Your search servers might go down. Have a backup plan to search from your database. Or hide the search UI, till the search servers are back up.
Redis might be down. Which could mean your background jobs may not work and your cache is unavailable. Be prepared to run the jobs synchronously, or have a failover redis instance ready.
Would love to hear your thoughts and experiences launching apps on production.
If I did a boo boo, please correct me :)