1.

How will you implement caching for microservices?

Answer»

Caching is a technique of performance improvement for getting query results from a service. It helps minimize the calls to network, database, etc. We can use caching at multiple levels in microservices architecture - 

  1. Server-Side Caching - DISTRIBUTED caching software like Redis/MEMCACHE/etc are used to cache the results of business operations. The cache is distributed so all instances of a microservice can see the values from the shared cache. This type of caching is opaque to clients.
  2. Gateway Cache - central API gateway can cache the query results as per business needs and provide improved performance. This way we can achieve caching for multiple services at one place. Distributed caching software like Redis or Memcache can be used in this case.
  3. Client-Side Caching - We can set cache-headers in HTTP response and allow clients to cache the results for a pre-defined time. This will drastically reduce the load on servers since the client will not make REPEATED calls to the same resource. Servers can inform the clients when information is changed, thereby any changes in the query result can also be handled. E-Tags can be used for client-side load BALANCING. If the end client is a microservice itself, then Spring Cache support can be used to cache the results locally. 


Discussion

No Comment Found