Caching — The Only Guide You’ll Ever Need
In Distributed System Improving Load Time and saving cost can be tricky , luckily we have Cacheing to help us.
In my previous article System Design - Scale 0 to Millions of Users ,we learn how to scale a traditional system by using scaling , geo replication and master/salve architecture for database.
Now its time to improve Response and Load time.
This can be achieved by adding Caching Mechanism in various layers of your System.
While designing distributed system, caching should be strategically placed to optimize performance, reduce latency, and minimize load on backend services.
Caching can be implemented at multiple layers like
Edge Cache (Content Delivery Network - CDN)
A content delivery network (CDN) is a network of interconnected servers that speeds up webpage loading for data-heavy applications. CDN can stand for content delivery network or content distribution network. When a user visits a website, data from that website's server has to travel across the internet to reach the user's computer.If the user is located far from that server, it will take a long time to load a large file, such as a video or website image. Instead, the website content is stored on CDN servers geographically closer to the users and reaches their computers much faster.
Benefits of CDN :
1. Reduce page load time
Website traffic can decrease if your page load times are too slow. A CDN can reduce bounce rates and increase the time users spend on your site.
2. Reduce bandwidth costs
Bandwidth costs are a significant expense because every incoming website request consumes network bandwidth. Through caching and other optimisations, CDNs can reduce the amount of data an origin server must provide, reducing the costs of hosting for website owners.
3. Increase content availability
Too many visitors at one time or network hardware failures can cause a website to crash. CDN services can handle more web traffic and reduce the load on web servers. Also, if one or more CDN servers go offline, other operational servers can replace them to ensure uninterrupted service.
4. Improve website security
Distributed denial-of-service (DDoS) attacks attempt to take down applications by sending large amounts of fake traffic to the website. CDNs can handle such traffic spikes by distributing the load between several intermediary servers, reducing the impact on the origin server.
Client-Side Cache
This involves storing frequently accessed data on the client device, reducing the need for repeated requests to the server. It is effective for data that doesn't change frequently and can significantly improve user experience by reducing latency.
Application-Level Cache
This includes in-memory caches such as Redis or Memcached within the application layer. These caches store results of expensive database queries, session data, and other frequently accessed data to reduce the load on the database and improve application response times.
Database Cache
Techniques such as query caching in the database layer store the results of frequent queries. This reduces the number of read operations on the database and speeds up data retrieval.
Distributed Cache
In a distributed system, a distributed cache spans multiple nodes to provide high availability and scalability. It ensures that the cached data is consistent across the distributed environment and can handle the high throughput required by large-scale systems.
While most caches are traditionally in one physical server or hardware component, a distributed cache can grow beyond the memory limits of a single computer by linking together multiple computers–referred to as a distributed architecture or a distributed cluster–for larger capacity and increased processing power.
Distributed caches are especially useful in environments with high data volume and load.
The distributed architecture allows incremental expansion/scaling by adding more computers to the cluster, allowing the cache to grow in step with the data growth.
If you find this article useful Please leave a like , subscribe and share my blog .
Follow me on LinkedIn | X
While inarguably a good intro to caching concepts I'd consider revising the title... when you make a statement such as "The Only Guide You’ll Ever Need" I naturally assume that it has all the details and setup etc from soup to nuts... this was just a tasting in that perspective. Albeit a good one, but a tasting :)