This is a huge topic, but here are a few general pointers:
- Make sure to use something like New Relic to monitor performance. This will help you see which parts of your application are getting slow as traffic increases, and can provide alerts when things start to go bad.
- Use a hosting infrastructure that makes it easy to scale horizontally, like Heroku. As the number of concurrent users increases, you can add more dynos or servers to handle the extra load.
- Use a fast, reliable database like Postgres and use the database layer to do the heavy lifting. Pushing as much filtering, sorting, and transformation into the database layer as possible is usually best. In general, databases are fast and Ruby is slow.
- Use indexes to keep your queries running as quickly as possible.
- Outsource as much as possible to third party services. Services like Heroku Postgres and Sendgrid can take the load off your application by having somebody else’s servers perform the slow parts. You don’t need to worry about scaling your email server if somebody else is delivering your email for you.
It’s difficult to give generic advice about optimization, because maybe optimizations will make one pattern of interaction faster but make another slower. For example, you can optimize your database to be as fast as possible for reading with heavy indexes and views, but this will make writing slower because each write needs to update all those indexes.
The best general practice is to obey common sense as you start, monitor as much as possible, and tune your application as traffic patterns reveal what the slowest interactions will be.