CodeDemen
CodeDemen

Reputation: 1971

Redis vs in-app caching

What are the benefits and downsides of using Redis for caching such data as userId-UserName pairs, NewsId-NewsDomainName? Why I should not cache this data in app memory bu creatinf Dictionatries for it? I think it must be much faster, than using redis? Thank you!

Upvotes: 5

Views: 1460

Answers (2)

Yao Yue
Yao Yue

Reputation: 96

Depending on what your workload looks like, you may want one or the other, or a combination of both caching strategies. Why?

  • in process caching is faster (good for latency), and more importantly, it doesn't produce any network traffic to get a hit (good for scalability);
  • remote caching, Redis or alike, allows you to keep one copy of the cached data that is accessed by all servers*, so it uses less memory (unless you only have one app server, which seems unlikely), and is less prone to data inconsistency problems (which seems important if you are dealing with user data)

In a cache cluster, or any data cluster where requests for a particular piece of data goes to a small set of servers, one of the biggest issues is hotspot. In this case, you may want to combine both- cache hot keys locally, but very briefly, to prevent overwhelming the backend servers, but not so long that it results in serving stale data for a long time.

* although, if there's more than one cache server in the cluster, and cluster management has server ejection/readmission logic but no data flush logic, you may have stale data on some of the servers.

Upvotes: 8

Bayu Alvian
Bayu Alvian

Reputation: 171

what if you have multiple server? would your second server know what are stored in the first server? Nope. this could be the main reason you need to use redis.

And if you stored, let's say a great amount of data in your server, it also could affect your server performance

Upvotes: 0

Related Questions