API Scalability: Cache large ‘chunks’ in the API response
Highscalability.com has an interesting piece on caching as "secret sauce" for good web performance.
Facebook and Twitter are cache assembly lines -- every web page and API request is served up by many calls to various caches at different levels - assembling the final result from many different chunks. At this scale there is almost no other way to deliver reasonable performance.
For APIs - what's the largest chunk of all? The entire API response.
APIs lend themselves nicely to caching responses because it is often easy to identify the cache key. If you follow the REST pattern each URL maps uniquely to a resource that has a well-defined lifecycle.
If you're working on the next Twitter, you will need many layers of caching to deliver great performance, including the filesystem and database caches, and then you will add additional caching layers using products like memcached or Coherence. But a final tier of caching for the API responses themselves can only help performance, so consider:
- Can API analytics data show the most common or slowest API calls?
- Are there slow API calls that return the same data over and over?
- Can you design using a REST pattern to make it easy to identify individual cache items?
There are a number of ways to speed up calls that are caching candidates, such as memcached or something similar.
Another way is to use an API proxy. A proxy that is sitting in front of your API servers is an efficient and easy way to add an additional caching layer without making any changes to the server tier. We have helped a number of customers drastically improve the performance of their APIs by inserting such a caching tier without touching the clients or servers.
And caching isn't just helpful if you are building an API. Applications that consume APIs, whether they are running on another web server or on a smartphone, can set up their own API proxy so that responses from many devices are cached in a central place, even if the APIs that the application is depending on can't be depended on themselves to return good performance.
(thanks to jules:stone for the photo!)
COMMENTS (0) | Add a comment
*required ADD A COMMENT