Caching Web and Databases Part-2
Published: 2022-07-27 06:11:04

**Database Caching**
Caching can be applied to any type of database including relational databases such as Amazon RDS or NoSQL databases such as Amazon DynamoDB, MongoDB and Apache Cassandra. Also the best part of caching is that it is minimally invasive to implement and by doing so your application performance regarding both scale and speed is dramatically improved. When building distributed applications that require low latency and scalability there are a number of challenges that, the disk based databases can pose to your applications and a few common challenges include the slow processing queries. Like when there are number of query optimization techniques and schema designs that can help boost query performance. The data retrieval speed from disk plus the added query processing times generally will put your query response times in double digit milliseconds at best. Apart from this cost to scale is another challenge that can be faced. Whether the data is distributed in a disk based NoSQL database or vertically scaled up in a relational database. Scaling for extremely high reads can be costly and may require a number of database read replicas to match what a single in-memory cache node can deliver in terms of request per second and the need to simplify data access. While the relational databases provide excellent means to data model relationships they aren't optimal for the data access. There are instances where your applications may want to access the data in a particular structure or view to simplify the data retrievable and increase the application performance. 
**Strategies**
Let's have a look at a few strategies how we can do the database caching. So, database cache basically supplements your primary database by removing the unnecessary pressure on it. Because it is going to hold the frequently accessed read data so that once the query is processed the result will be stored in the cache and when the same request comes up next time the response can be sent from the cache itself instead of processing it again in the database. The cache itself can live in a number of areas including your database, application or as a standalone cache layer. So the three most common types of database caches are there. First is the **Database Integrated Cache**. Some database such as Amazon Aurora they offer an integrated caching that is managed within the database engine and has built in right through capabilities when the underlying data changes on the database table the database updates its cache automatically. There's nothing within the application tier that is required to leverage this cache additionally there is DAX, the DynamoDB accelerator which does all the heavy lifting that is required to add the in-memory acceleration to your DynamoDB tables without requiring the developers to manage the cache invalidation data population of the cluster management. Another type of cache that we are having is a **Local Caching**. Which stores your frequently used data within the application itself. This not only speeds up your the data retrieval but also removes the network traffic that is associated with retrieving the data. Making the data retrieval faster than any other caching architectures. But a major disadvantage with this kind of cache is that among your applications each node has its own resident cache working in a disconnected manner the information that is stored within an individual cache node. Whether it's database cash data, web sessions or users shopping carts cannot be shared with other local caches. But the majority of the disadvantages that are with the local caching are mitigated with the remote caches. So, let's understand what are remote caching what is a remote cache and what is **Remote Caching**. This is a separate instance which is dedicated for storing the cache data in memory the remote caches will be stored on dedicated servers. And typically they will be built on key value NoSQL store such as Redis and Memcached. They provide hundreds of thousands of up to a million requests per second per cache unit and many solutions such as Amazon ElastiCache for Redis also provide the high availability needed for the critical workloads. Also the average latency of a request to a remote cache is fulfilled in sub millisecond latency orders of magnitude faster than a disk based database. This was about the three main strategies or the types of database caching. 

> I  have a special offer for you to enjoy some summer savings - a $500 credit to play with Redis Enterprise this summer. You can redeem this coupon for any paid plan!
> Follow these steps to use the coupon. Terms and conditions apply*:
> Register or Login to the app
> Add a payment method: Billing and Payments > Payment methods
> Add a payment method: Billing and Payments > Credits >Use coupon **SUMMER500**
> Create any paid subscription
> Use code **SUMMER500**

**Terms and conditions:**

**Offer expires July 31, 2022**
**Use with a new subscription only**
**Cannot combine with any other coupon offer**
**Must use all $500 in two months**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a44fyw09izs9sr109dec.png)