As Ruby Developers, we’ve grown accustomed to needing heavy caching. The rule of thumb is your page load should never be dependent on a call to the DB and if you haven’t generated a response in a few seconds its too slow. Obviously you need to access your DB, so in general you want to either be loading everything asynchronously (which can sometimes only give you a metrics-based impression of speed) or putting everything you access into a cache with millisecond response times, including as many precomputed values, views, etc as possible.
I’ll dive into caching at a later date, because I want to talk about something a little less common, but arguably just as important. We all have tons of assets that never change, so we hand them off to services like S3 or Cloudfront that help us deliver them as fast as possible. The problem with S3 and Cloudfront of course is that their expirations take hours at times, which can be hell when deploying. The first byte times with S3 + Cloudfront is pretty dismal, for large files its fine but for a lot of small assets it really sucks. They also don’t let us cache our HTML directly, arguably the most important part that we’re spending a lot of time calculating on each request.
So two main issues-we want to cache our HTML, and we need a real-time ability to update our assets.
Enter Front-End Optimization Tools. Three favorite companies in this space:
InstartLogic which is my favorite, but is for more enterprise, large scale applications. They do a unique HTML streaming that automagically loads what you need in the order a user typically sees it, through some sort of machine learning. That means they’re not wasting time sending down stuff for the bottom of the page until everything in the top is loaded for view. Pretty cool right?
Fastly, which has a SaaS pricing model and support from the father of Web Performance, Steve Souders, is another option. It’s less full-featured but for a smaller website it might fit your price point vs. InstartLogic.
Both these are tools that provide support for streaming media, HTML, all of your normal CDN benefits across several global end points, and the ability to protect your site in the event of DDoS or similar events.
Cloudflare will give you the DDoS protection, but their solution is far less customizable (but very cheap). It has some caching to it, but from usage I’ve noticed it’s cache isn’t as good as some of their competitors. On the otherhand, they are the biggest name in DDoS prevention and have been known to repel back some large scale attacks.
The main advantage is that unlike an S3 or Cloudfront, they’re going to by default be distributed around the world and update your assets in real-time. They go one step further from a CDN and actually become the “front” of your website, so all traffic will flow through them before it hits your website. In fact, they’ll only hit your site when they need a new copy of the request (this is on GET of course). At least with InstartLogic, they can pretty much do whatever you want and create custom caching rules with multiple endpoints based on pretty arbitrary criteria.
If you’re having performance problems that can’t be solved by performance tuning and server-side client, try out Fastly. If you need something more advanced or continue to have performance issues, that’s when I’d called up InstartLogic who can give you the hands-on, custom support you need for a more mission-critical application.
Good luck and happy caching!