profile

Hi, I’m a creator

Caching Patterns — How to Cache in a Microservice Architecture

Published 10 months ago • 1 min read

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.

Cache-Aside

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

Read-Through/Write-Through

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

Write-Behind

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

Hi, I’m a creator

Read more from Hi, I’m a creator

Hello there, Hope you are doing good. Token based Authentication is one of the most popular and widely used authentication and identity management systems used across the world. It is simple, easy to integrate and makes user experience better. Applications can decouple User Identity and Authentication layer to an externalized Authorization Server layer and delegate authentication to this server. You will only enter credentials at a centralized Identity Provider site and the application...

9 months ago • 2 min read

Hello there, Hope you are doing good. I wanted to share some interesting news to you. You want to add authentication to secure your resources, authorize access, implement CORS policies, enforce HTTPS, or even cache responses – you will add the respective built-in libraries to the web application. These are all exposed by the ASP.NET Core framework as Middleware – pieces of code blocks that are responsible for a single functionality. Announcing my new digital product - "How to work with...

10 months ago • 1 min read

Hello there, Hope you are doing good. This week I want to introduce you to Authorization and How to implement Authorization for a Web API in ASP.NET Core. .NET provides us with 3 ways of implementing Authorization depending on the requirement and the use-cases. In this article, I touch base on all the 3 mechanisms with explaining examples, so you don't need to look up for another content. Article Link - https://codingramen.com/blog/how-to-authorize-requests-in-asp-net-core-web-api/ I hope you...

10 months ago • 1 min read
Share this post