Wednesday, November 27, 2013

Use of Cache to scale and improve performance

Keep frequently used data in a performant data storage location (RAM, SSD) to avoid having to access the data from less performant source data storage (DBMS). The idea is to reduce the hits on the application for database server. The caching must be fine-tuned with appropriate time-to-live (TTL) values so as to avoid excessive evictions or premature exhaustion of the cache. The hit-to-miss cache ratio must be analyzed to come up with desirable TTL values for different types of cached data. In a web application, the caching can be done in various tiers.

Browser Cache

By setting the max-age, expiration, and cache-control attributes in the headers of a web page, the browser can be instructed to save and reuse page data for subsequent page loads. There is about 50MB of shared space (i.e. for all web applications) available for such data in the Web browser cache. HTML5 appcache provides dedicated cache for each application that request such storage in their manifest.

Edge Cache

Data is stored and served from servers close to end users.
Example,content delivery networks (CDNs) such as CloudFront, Akamai

Web Cache

Caching of data after a page is generated by the application. First time, the page is generated by the application server. Subsequently the cached page is returned.
Examples: Varnish, Squid

Application Cache

Session data is stored by the application in a performant data store.
Common tools: memcached, cassandra, DynamoDb

Database Cache

A cache that exists on the database server. First query accesses data from the disk, subsequent identical query returns data from the cache.