Reliable collection caching as a cache in service fabric

My system uses a bunch of microservices to process the item, and I plan to create a Stateful MicroService that contains the last state of the item. In this service, I plan to store the entire state of the element in a trusted dictionary, and whenever the element gets access to update the Last Access field of the element.

My requirement is that I only want to keep recently used items in a reliable collection and move items that have not been available for access to external storage for a long time, for example, in the azure table storage, And the External storage and Reliable collection should be synchronized.

The value of all items must be in external storage and recently used items in a trusted collection.

This is a reduction in overhead in a reliable collection.

Like a reliable collection it acts like a cache.

Is it better to apply my solutions as above? Is it good practice to list a ReliableCollection?

+6
source share
2 answers

If a trusted dictionary is intended to be used as a cache, then I really see no reason to unload unused items in Azure Storage. If this is a cache, I would expect that the unused elements will be cleared, and the caller will need to return to the source of truth for anything that has expired from the cache. But it looks like you want a reliable dictionary to be the last source of truth. Therefore, I think that you need to first decide whether you are really creating a cache, or a source of a true data store that can output data from memory. This is more like the latter.

In any case, this can be done as you described, but it is not easy to synchronize them sequentially, because you do not have a transaction through a reliable dictionary and an external store.

Enumerating the collection is fine, but it is an expensive operation, so I would not recommend doing this on large amounts of data in a hot way, for example, on a user request path. It is normal to do this periodically in a planned manner.

Need to offload data to external storage? Can you offload the local disk? Trusted collections will soon automatically dump the state to disk.

+3
source

I would use an actor. Give each element its own actor and save it there. When an actor collects trash, you can save the state elsewhere or simply do so on the actorโ€™s timer.

Doing this means you don't have to replicate a lot of actor code to manage multiple instances.

CAVEAT

It makes sense if your overall design makes sense. As stated in the commentary of Wenceslas, actors are not suitable for general-purpose cache due to the single-threaded model for actors. But if in your design there is an actor representing a single object, and caching is associated with this object (for example, with the user), then processing the actor in the form of a cache can work well.

0
source

All Articles