Reliable Collections

The Microsoft.ServiceFabric.Data.Collections namespace contains various collections that act as reliable state providers and are known as Reliable Collections. You must have used standard data collections such as dictionary and queue present in the System.Collections namespace in your applications; the interfaces in Reliable Collections allow you to interact with the state provider in a similar manner. The Reliable Collections differ from the classes in System.Collections, in that they are:

  • Replicated: The state data is replicated across nodes for high availability
  • Persisted: The state data is persisted both in memory and in disk for durability against large-scale outages
  • Asynchronous: The Service Fabric API supports asynchronous operations on the Reliable Collections to ensure that threads are not blocked when incurring I/O
  • Transactional: Service Fabric APIs utilize the abstraction of transactions so you can manage multiple Reliable Collections within a service easily

The Service Fabric API implements the Reliable Collections in a pluggable manner, so you can expect to see new collections being added to the existing offering from time to time. Service Fabric currently provides three Reliable Collections:

  • Reliable Dictionary: It represents a replicated, transactional, and asynchronous collection of key/value pairs. Similar to ConcurrentDictionary, both the key and the value can be of any type.
  • Reliable Queue: It represents a replicated, transactional, and asynchronous strict first-in, first-out (FIFO) queue. Similar to ConcurrentQueue, the value can be of any type.
  • Reliable Concurrent Queue: This queue is similar to Reliable Queue but offer a higher throughput in lieu of doing away with FIFO restrictions that Reliable Queue has.

The Reliable State Manager manages the lifetime of the state providers. Since the data structure needs to be replicated to several nodes, coordination among nodes is required to create instance of the data structure. Using the IReliableStateManager interface, your service can access the state manager to create new instances of Reliable Collections. The Reliable State Managers also support transactions. Using transactions, your service can operate with several collections in an atomic manner.

All state data that your site writes or modifies must go through the primary replica. Service Fabric ensures that there are is more than one primary replica of a service available at any point of time. However, data can be read from either the primary replica or secondary replicas.

Let's build a simple application which will help us understand how we can work with Reliable Collections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.87.35