Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying a list of Actors in Azure Service Fabric

I currently have a ReliableActor for every user in the system. This actor is appropriately named User, and for the sake of this question has a Location property. What would be the recommended approach for querying Users by Location?

My current thought is to create a ReliableService that contains a ReliableDictionary. The data in the dictionary would be a projection of the User data. If I did that, then I would need to:

  1. Query the dictionary. After GA, this seems like the recommended approach.
  2. Keep the dictionary in sync. Perhaps through Pub/Sub or IActorEvents.

Another alternative would be to have a persistent store outside Service Fabric, such as a database. This feels wrong, as it goes against some of the ideals of using the Service Fabric. If I did, I would assume something similar to the above but using a Stateless service?

Thank you very much.

like image 701
Mark De Verno Avatar asked May 22 '16 20:05

Mark De Verno


People also ask

Is Azure service fabric deprecated?

Azure Service Fabric versions - Azure Service Fabric | Microsoft Learn. This browser is no longer supported. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Who uses Azure service fabric?

Service Fabric powers many Microsoft services today, including Azure SQL Database, Azure Cosmos DB, Cortana, Microsoft Power BI, Microsoft Intune, Azure Event Hubs, Azure IoT Hub, Dynamics 365, Skype for Business, and many core Azure services.

What is Azure fabric cluster?

A Service Fabric cluster is a network-connected set of virtual or physical machines into which your microservices are deployed and managed. A machine or VM that is part of a cluster is called a cluster node. Clusters can scale to thousands of nodes.

Is Azure service fabric deals with infrastructure problems?

— per secondAzure Service Fabric deals with infrastructure problems.


2 Answers

I'm personally exploring the use of Actors as the main datastore (ie: source of truth) for my entities. As Actors are added, updated or deleted, I use MassTransit to publish events. I then have Reliable Statefull Services subscribed to these events. The services receive the events and update their internal IReliableDictionary's. The services can then be queried to find the entities required by the client. Each service only keeps the entity data that it requires to perform it's queries.

I'm also exploring the use of EventStore to publish the events as well. That way, if in the future I decide I need to query the entities in a new way, I could create a new service and replay all the events to it.

These Pub/Sub methods do mean the query services are only eventually consistent, but in a distributed system, this seems to be the norm.

like image 110
Nick Barrett Avatar answered Oct 03 '22 01:10

Nick Barrett


While the standard recommendation is definitely as Vaclav's response, if querying is the exception then Actors could still be appropriate. For me whether they're suitable or not is defined by the normal way of accessing them, if it's by key (presumably for a user record it would be) then Actors work well.

It is possible to iterate over Actors, but it's quite a heavy task, so like I say is only appropriate if it's the exceptional case. The following code will build up a set of Actor references, you then iterate over this set to fetch the actors and then can use Linq or similar on the collection that you've built up.

ContinuationToken continuationToken = null;
var actorServiceProxy = ActorServiceProxy.Create("fabric:/MyActorApp/MyActorService", partitionKey);
var queriedActorCount = 0;
do
{
    var queryResult = actorServiceProxy.GetActorsAsync(continuationToken, cancellationToken).GetAwaiter().GetResult();
    queriedActorCount += queryResult.Items.Count();
   continuationToken = queryResult.ContinuationToken;
} while (continuationToken != null);

TLDR: It's not always advisable to query over actors, but it can be achieved if required. Code above will get you started.

like image 36
mckjerral Avatar answered Oct 03 '22 01:10

mckjerral