-
Notifications
You must be signed in to change notification settings - Fork 20
Caching Redis & Internal
A cache is a hardware or software component that stores data so that future requests for that data can be served faster. The data stored in a cache might be the result of an earlier computation or a copy of data stored elsewhere. In mentoring services, all the necessary data which are used frequently will be cached in Redis and the Internal cache.
A cache miss occurs when a cache does not have the requested data in its memory. Meanwhile, a hit is when a cache successfully finds the requested data, satisfying the search query.
Caching Implementation
Internal and Redis caching is implemented with the help of an npm package called elevate-node-cache. This package exports 3 modules.
- RedisConfig
- RedisCache
- InternalCache
Attempt | #1 | #2 | #3 | #4 | #5 | #6 | #7 | #8 | #9 | #10 | #11 |
---|---|---|---|---|---|---|---|---|---|---|---|
Seconds | 301 | 283 | 290 | 286 | 289 | 285 | 287 | 287 | 272 | 276 | 269 |
In mentoring services entities are used to store information on types of users, categories of sessions, etc. this service has limited data and will store in an internal cache for serving faster and better.
Mentoring services have mentee and mentor profile data. Mentor profile data will be used by mentees to check their upcoming sessions and the rating of a mentor. Mentor profile data will be utilized by many mentees. Frequently mentor data will be used to improve performance and serve faster this data will cache in Redis. If a mentor profile is called in mentoring services then it will make a call to users services to get the profile of the mentor. If the mentor profile is found in Redis (hit) then will return profile data and if the mentor profile is not found in the cache (miss) then it will make calls to the database and store that data in the cache and returns profile data of that mentor and if someone request same profile data then it will be served from cache.
Multiple micro-services will be running for the same service, when form data gets an update request at that time it will update its data and it will delete the current data from the cache and one message along with the key will be published in Kafka for the rest of the services to delete their internal cache and update with new form version.
- When backend services receive API calls to update form data they will perform the update operation.
- Once the update operation is completed then it before sending a response to a client it will publish one event in Kafka for other microservice of the same instance.
- When an event is published in Kafka it will return a response and the same event is consumed by other microservices to delete their internal cache.
- After deleting the cache from another microservice when it receives any API call it will check whether a cache is present or not it not then it creates a cache and send the data to a client.
When mentor profile API is called with updated data then data of that particular mentor will be deleted from the global cache and new data will be cached. If Redis memory is full then the least called mentor profile will be deleted and new data will be cached. Doc Link: https://redis.io/docs/manual/eviction/