Hello there,
Hope you are doing good.
This week, I want to introduce you to the 3 caching patterns that we generally use to implement Caching in our applications. We choose a caching pattern that best fits our application based on its behavior, business requirements and tolerance.
The following are the 3 popular patterns used for caching in microservices.
The cache is lazy loaded with data only when needed and is not available in the cache. The microservice decides if the data needs to be cached. If the data is available in the cache, it is accessed by the service. If it is not available, the service fetches data from the backend and updates the cache before returning with a response.
Read my full article on How to implement a Cache-Aside pattern in ASP.NET Core with an illustrating Example
A batch service loads the cache and is seeded with data before the application starts. When there is any update in the data, the microservice first updates the database and then immediately writes to the cache. The cache is always warm with the latest data available.
Applications that deal with large sets of data — where the data updates are very rare and the querying takes a lot of resources — can use this approach.
Read my full article on How to implement a Write-Through Caching pattern in ASP.NET Core with an illustrating Example
The microservice writes its updates to the cache and doesn’t actively save the changes to the backend — the cache asynchronously writes to the backend. When a client requests for data, the microservice queries the cache for data and if not present it fetches from the backend and writes to the cache.
This approach is used when we are okay with eventual consistency.
There is a significant performance improvement on the application, but there is a chance of stale data returned to the client even after an update, since the updates are asynchronous.
There could also be a data loss when any cache goes down, since the cache holds the latest version and the backend doesn’t.
Not all Caching providers support this feature and is generally offered in their Enterprise or Paid versions.
Read my full article on how to implement a Write-Behind cache in NCache
I hope these articles are of some use to you.
I'm trying to build my mailing list over Substack, Please subscribe to my Publication - https://codingramen.substack.com
Have a great week.
Cheers
Ram
If you're starting in software engineering or an experienced professional, I post informative content around stuff I work with - Full Stack Development. Subscribe to my newsletter to receive my latest posts.
Hello there, Hope you are doing good. In this week's newsletter, I want to introduce you to the third principle of the SOLID principles: five principles describing few fundamental rules for developing arguably ideal software components which are scalable, extensible, robust and flexible - the Liskov Substitution Principle. This principle can be termed as one of the basic foundations of the Object Oriented Design languages which talks mainly about substitutions and inheritance. The principle...
Hello there, Hope you are doing good. In this week's newsletter I want to introduce you to one of the most efficient internal sorting algorithm, and discuss how to implement it - Quicksort algorithm step by step with an example and analyze time complexity. Quick Sort is an internal sorting technique which can be used to arrange a given set of unordered dataset into required order. It is the most efficient internal sorting technique, which doesn’t use any auxiliary memory (or additional space...
Hello there, Hope you are doing good. In this week's newsletter, I want to introduce you to the fourth principle of the SOLID principles - Interface Segregation. In the early stages of application development, it’s common to place all logic into a single class. As the application grows, these classes become bloated or “fat” with unrelated responsibilities. Later, when we try to extract interfaces from these classes for modularity or extension, we may end up with interfaces containing many...