0

I am working on a project in which I will be calling Service Fabric methods and returning the data to end user. The Data is modified very infrequently or is almost constant so I want to maintain a cache and return it if the data is not modified.

The project structure is: WepApi(Stateless Service) -> Repository -> SatefulService

What is the best way of implementing this in Azure Service Fabric? I am thinking of two options:

  1. Redis cache a. Creating a Redis cache project where it will expose two endpoints for storing and getting cache data. This project will be referenced in the repository layer. b. Creating a Redis cache service( service fabric ) and calling from the repository.
  2. stateful service a. Creating a separate dictionary in the existing stateful service and use it for getting and storing data.

And, I am also having below questions.

Approach #1:

  1. We have to depend on 3rd party system(Redis cache) and we might not get accurate results if the server is not available.

Approach #2:

  1. We might get a performance issue if the cache data is increased over time.

Any best approaches to implement a cache in service fabric?

Thanks,

Balanjaneyulu K
  • 3,660
  • 5
  • 24
  • 45
  • *We might get a performance issue if the cache data is increased over time.* -> why? what is the reason behind this assumption? The only drawback I see is that out of the box there is no cache eviction – Peter Bons Apr 03 '19 at 11:07
  • What data are we talking about? What amount / size? – Peter Bons Apr 03 '19 at 11:08
  • I might get a list of records and count would be maxing of 10000 records. Each record might have 10 - 20 properties – Balanjaneyulu K Apr 03 '19 at 11:26
  • I execute a linq query on two collections and store it in Redis or collection. The data which I store might be one record or multiple records. – Balanjaneyulu K Apr 03 '19 at 11:28
  • Have you thought about .net memory cache ? https://learn.microsoft.com/en-us/aspnet/core/performance/caching/memory?view=aspnetcore-2.2 – Rahul Ruikar Apr 03 '19 at 11:53
  • @PeterBons Is there an upper limit to the suggested size of the value stored for a particular key in Redis? – Balanjaneyulu K Apr 04 '19 at 13:39

1 Answers1

1

Reliable Collections were designed for performance, bc they run in-process and data is kept in memory if there is enough available memory (which in your case should be ok, for ten thousand records). The only slow-down compared to a regular dictionary in memory is that a reliable dictionary must maintain transactional consistency while reading, but i presume you need this consistency anyway?

Robert
  • 176
  • 7
  • 1
    The issue i have run into with Reliable collections is that there is no way to do bulk operations on them. So if you have 100k+ records you want to pull in and out quickly good luck you're pretty much screwed. I'm in the middle of realizing this the hard way, considering installing memcache on my cluster vms to have something that can handle bulk yet be local to my processing code for quick retrieval and saving of the bulk processed data. – Josh Jan 08 '20 at 01:36