Application Level Caching Overview and uses
Tags: caching, backend, systems, api
Published: 2022-09-09 00:41:53

Latency and cost of Internet based services are a major concern for maintainers and to continue user's demands and to improve the availablility and scalability of the application encourages the usage of application level caching.

Dynamically generated web content is a major part of the web requests where the content changes based on the user request and due to this, the rate at which dynamic documents are delivered is often slower than static documents. Therefore, dynamic content place a load on the server which can lead to performance bottlenecks.

One of the techniques used to meet user's demands and reduce overhead on the servers is **caching**. Caching can reduce the user perceived latency and Internet traffic, and improve the scalability and availability of servers.

Application-level caching is placed on the server-side and typically uses a key-value in-memory store system to cache frequently accessed or expensive to compute data that remain not cached in other caching levels, lowering the load on database or services that are difficult to scale up.

Even though the concept is quite popular nowadays in applications, there are still designs which the developers integrating in system design need to take care of.

The design should pose four main questions :
1. How to cache the data?
2. What data should be cached?
3. When should be the data be cached?
4. Where the cached data should be put ?
5. For how long should be data be cached and then cache should get updated?

There are lots of resources online on how to use caching optimally and also there are tools available.

For Caching, Memcached and Redis are popular solutions and are a critical web infrastructure component.

**Caching Example on server side:**

Caching on webserver can be implemented at many places depending on the architecture of the system.Depending on where caching is implemented, different types of content can be cached like the final HTML page , intermediate HTML or XML
fragments,database queries, or database tables.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e0t5mkkzaxlzr1md7fdp.png)

The figure llustrates an example where an application level cache is used to lower the application workload. The application gets an HTTP request from the user and then goes to the webserver, then webserver tries to search the data in the cache, depending on how the cache is implemented. If the data is found in the cache it would result in a cache hit, otherwise it would be cache miss. In case of cache miss, webserver would query the data to the database itself, which could take a bit longer for the first time. But once it obtains the data from database, it would put it in cache again to serve the request from the user again in the future. Based on the caching strategy, the developers of the webserver would need to decide on how long would the data be cached.

Memcached  and Redis are popular solutions and are a critical web infrastructure component.

------------------------------------------------------------

If you liked reading the content, please do share it with other people who you think might be interested. 
Also I do regularly post content on Twitter, do follow me [@DhirenSerai](https://twitter.com/DhirenSerai) for more.