Where do I implement Redis cache?

What is the best place to implement Redis cache?
API server or frontend? or both?

API will be used in web and mobile. I think I need to implement cache everywhere. So it will reduce network(if implemented in frontend) calls and db calls(if implemented in api).

Well, it really depends on your needs.

At first you should implement at backend level or, maybe better, at “API Gateway” level.
Once you have it at backend level you can also think to do some caching at frontend level. In that case anyway I’d not use Redis for that but just in memory caching

Well, redis is a software that you can only run on your servers, you can not deliver it to a browser, if thats what you mean by “frontend”.

Neither would a JS running in the browser be able to connect directly to a redis instance.

So if you want to use redis as a cache, this puts some restrictions on where to put it.

Of course there are plenty of other caching strategies available, of which some can be used on server side, and others on the client side.

All of them have their different use cases, pros and cons. All have to deal with cache invalidation, which is one of the 2 hard problems in CS…

  1. Naming things
  2. Cache invalidation
  3. Off-by-one-errors
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.