3

Service Fabric was just announced at the build conference. I was reading the scarce documentation about it and I have a question.

I'm evaluating Service Fabric for hosting CRUD like microservices that are at the moment built in ASP.NET WebApi.

Is Service Fabric geared towards hosting small pieces of functionality that receive data, process it and return the result, rather than hosting CRUD WebApi types of application?

Dante
  • 3,833
  • 4
  • 38
  • 55

3 Answers3

10

Service Fabric enables the creation of both stateless and stateful microservices.

As the name suggests, any state maintained by an an instance of a stateless service will be lost if the node goes down. A new, fresh instance will simply be spun up elsewhere in the cluster.

Stateful services offer the ability to persist state without relying on an external store. Any data stored in a Reliable Collection will be automatically replicated across multiple nodes in the cluster, ensuring that the state is resilient to failures.

A common pattern is to use a stateless service as the client-facing gateway to the application and then have that service direct traffic to the app's partitioned stateful services. This hides the work of resolving partitions from clients, allowing them to to target one logical endpoint with all requests.

Take a look at the WordCount sample for an example of how this works. The WordCount.WebService stateless service acts as the front end to the application. It simply resolves the partition based on the incoming request and then sends it on. The WordCount.Service stateful service (partitioned based on the first letter of the word) immediately puts those incoming requests in a ReliableQueue and then processes them in the background, storing the results in a ReliableDictionary.

For more details, see the Reliable Services Overview.

Note: for now, the best way to expose WebAPI endpoints to clients is to self-host an OWIN server in the stateless service. ASP.NET 5 projects will soon be supported as well.

Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
Sean McKenna
  • 3,706
  • 19
  • 19
  • Can we sign up anywhere to try this on actual Azure Hardware? – Firoso May 07 '15 at 01:14
  • Not yet but stay tuned. We will make the creation of clusters in Azure available as a preview later this year. – Sean McKenna May 07 '15 at 01:17
  • @SeanMcKenna-MSFT, small question. How to scale a web application. All samples run single web instance with some predifined port. how Do I know where in cluster this web application is running? – AlfeG May 13 '15 at 04:32
  • It might be better to ask this as a new question since it's distinct from the original one. – Sean McKenna May 14 '15 at 20:32
0

This video answers my own question: http://channel9.msdn.com/Events/Build/2015/2-704. In summary, we should use Stateless Services to host ASP.NET based sites or API's which persist data to external data stores.

Dante
  • 3,833
  • 4
  • 38
  • 55
  • 4
    If you persist to external data stores from your ASP.NET stateless service in Service Fabric, you'll be missing some of the best functionality of Service Fabric. Instead, you could build a stateful service that persists the data in a reliable collection. This holds its data in memory and replicates it to other nodes in the cluster for resilience. This means reads of the data are all in memory and super fast. Your ASP.NET stateless service can then communicate with the stateful service using the protocol of your choice: e.g. WebAPI, WCF, etc. – Darran May 02 '15 at 18:32
0

If you don't have state (or have it externally), Stateless Service is the way to start.

Answer to the original question is "both". Basically, anything that have main() function (with couple of more extended contract methods to talk to Service Fabric) can be a service in Service Fabric world.