SERVICE FABRIC Haishi DX, 2016
Agenda Basic concepts Exercise 1: Creating a stateless Calculator web API. Exercise 2: Testing stateful service failover.
BASIC CONCEPTS
Service Fabric Overview Build cloud-scale distributed applications Microservices architecture Proven service SQL Database, Document DB, Intune, Power BI, Skye for Business, Cortana, Data Factory… Run anywhere Azure, on-premises, Azure Stack, AWS Windows and Linux Container integration
Service Fabric Application Business Layer Data Layer Presentation Layer Web Role Worker Role Database
Separation between workload and resources
Stateless vs. Stateful add(a, b) add (3,5) 8 add(a) add (3) 3 38 add (5)8
Scaling stateless service add(a, b) Load balancer add(a, b)
Scaling stateful service add(a) Load balancer add(a) 5 3
Scaling stateful service – externalize state add(a) Load balancer add(a) 5 3 8
Scaling stateful service - affinity add(a) Load balancer add(a) 3 8
Load balancer add(a) Scaling stateful service - replication
Scaling stateful service - partition routing add(a)
Service Fabric cluster
EXERCISE 1 Creating a stateless Calculator web API
Steps 1. Launch Visual Studio 2015 as administrator. 2. Create a new Service Fabric Application. 3. On New Service Fabric Service dialog, select the Stateless Web API template, and click on the OK button. 4. Update the ValuesController to container one method: [HttpGet] public int Add(int a, int b) { return a + b; }
Steps 5. Press F5 to launch the application. 6. Open a browser, and navigate to 7. Expand the cluster tree all the way to the node level. Switch to DETAILS view. 8. Note down the port being used. 9. Open another tab in browser, and navigate to
EXERCISE 2 Testing stateful service failover
Steps 1. Launch Visual Studio 2015 as administrator. 2. Create a new Service Fabric Application. 3. On New Service Fabric Service dialog, select the Stateful Service template, and click on the OK button. 4. Right-click the project and select the Publish… menu. 5. Publish to Local Cluster.
Steps 6. Open a browser, and navigate to 7. Expand the cluster tree and observe how the replicas are distributed across nodes for the single partition. 8. In the cluster tree, find the node where the primary replica resides. Then, in the right panel, click on the ACTIONS -> Deactivate (restart) menu. 9. Observe that another node is elected as primary. 10. Modify Local.xml under the ApplicationParameters folder to change the number of partitions to Redeploy the application and observe in Service Fabric Explorer how partitions and replicas are distributed.