Download presentation
Published byDavid Foster Modified over 9 years ago
2
Creating highly available and resilient Microservices on Microsoft Azure Service Fabric
Mahesh Krishnan CLD334
3
Agenda Why use microservices?
Azure Service Fabric Platform – An introduction Service Fabric Programming model Reliable Actors Reliable Services Wrap up
4
Traditional Monolithic approach
A monolithic application has most of its functionality within a single process that is commonly componentized with libraries Scales by cloning the app on multiple servers/VMs/ containers
5
Microservices approach
Separates functionality into separate smaller services Uses a standard communication protocol Scales out be deploying each service independently creating instances of these services across servers/VMs containers
6
Why use microservices? Can be versioned, deployed and scaled independently Allows use of different technologies Loose coupling of services Faster delivery of features Facilitates small, focused teams Improves fault isolation
7
Microsoft Azure Service Fabric A platform for reliable, hyperscale, microservice-based applications
microservices Service Fabric Health Monitoring Container Orchestration & lifecycle management High Availability Hybrid Operations Data Partitioning Self-healing Simple programming models High Density Rolling Upgrades Low Latency Placement Constraints Fast startup & shutdown Replication & Failover Load balancing Hyper-Scale Automated Rollback Stateful services Private Clouds Windows Server Linux Azure Windows Server Linux Hosted Clouds Windows Server Linux
8
Service Fabric cluster with microservices
App1 App2
9
Types of Microservices
Stateless microservice Stateful microservices
10
Stateless Microservices
Has either no state or state is persisted externally (such as Azure database or Azure storage) There can be multiple instances of the services e.g. Existing ASP.NET web apps, Azure cloud services
11
Stateful Microservices
State is maintained within the microservice Allows for hot data to be next to the compute State is partitioned for scale Each partition state is replicated for reliability e.g. Database, documents, user profile, shopping cart, etc
12
Cloud Services vs Service Fabric
Azure Cloud services Service Fabric One service instance/VM Multiple microservices/VM Lower compute density High microservice density Slow in deployment and upgrades Faster Slower scaling and DR Fast scaling across the cluster
13
Programming models
14
Service fabric applications
15
Reliable Actors API
16
Actor programming model
Introduced in 1973! An actor is the fundamental unit of computation Does some processing Holds state Communicates with other actors Similar to objects in OOP
17
Reliable Actors API Build reliable stateless and stateful objects using a virtual Actor programming model Suitable for applications with multiple independent units of scale and compute Automatic state management and turn based concurrency
18
Reliable Actors Actors have an lD that maps to an object
Service Fabric manages nodes and can transparently move actors amongst them (provides HA and scale) Actor methods run via turn based concurrency
19
Getting started Download the Service Fabric Download
Ensure PowerShell is installed and right execution policies set up Run the DevClusterSetup.ps1script to start local cluster
20
Server side code - Interface
public interface IMyActor : IActor { Task<string> DoWorkAsync(); }
21
Server side code - Implementation
public class MyActor : Actor, IMyActor { public async Task<string> DoWorkAsync() … return await Task.FromResult("result"); }
22
Client side code var app = "fabric:/HelloWorld";
var proxy = ActorProxy.Create<IMyActor> (ActorId.NewId(), app); var result = proxy.DoWorkAsync().Result;
23
Demo Reliable Actors Microsoft Ignite 2015 4/26/2017 8:23 AM
© 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
24
Actor Lifecycle
25
Actor lifecycle - Activation
If actor is not active, a new actor is created Its state is then loaded (for stateful actors) OnActivateSync method is called Added to Active Actors table
26
Actor lifecycle - Deactivation
Unused actors removed from the Active Actors table OnDeactivateSync method is called on Actor Once deactivated, objects are garbage collected by CLR
27
Actor lifecycle – more concepts
Scan interval – Time interval between successive scans by Actor runtime for inactive actors (Default: 60 seconds) Idle timeout – Time an actor can be idle before it is deactivated (Default: 60 seconds) ActorGarbageCollection attribute used to change defaults
28
Reliable Services API
29
Reliable Services API Write services that are reliable, available, scalable and provide consistency Use Reliable Collections to persist state Communicate using tech of your choice (WCF, WebAPI, ..)
30
Reliable Collection Can be used to create Stateful services. Features:
Multi-machine Replicated (HA) Persistance (durable) Asynchrounous Transactional
31
Getting started… Only two methods you need to implement to get started. CreateCommunicationListener – Method where the communication stack for the service is defined RunAsync – This is where the Service runs the business logic – similar to WorkerRole’s Run method
32
Server side code - Implementation
public class MyStatelessService : StatelessService { protected override ICommunicationListener CreateCommunicationListener() { …} protected override async Task RunAsync(CancellationToken cancellationToken) { … } }
33
Reliable Collection var myDictionary = await this.StateManager.GetOrAddAsync <IReliableDictionary<string, long>>("myDictionary"); using (var tx = this.StateManager.CreateTransaction()) { … await myDictionary.AddOrUpdateAsync(tx, "counter", 0, (k, v) => ++v); await tx.CommitAsync(); }
34
Scalability Can be partitioned for scalability – you choose scheme S
Node 1 Node 2 Node 3 Node 4 Node 5 Node 6 S P2 P1 S S S S P3 P4 S S S
35
Demo Reliable Services
36
Demo Service Fabric in the portal
37
Wrap up… Service Fabric is the next generation of PaaS that can be used to create microservices Has 2 programming models: Reliable Actor API Reliable Service API Can create either stateful or stateless services Availability, Scalability, load balancing, etc comes OOB
38
Complete your session evaluation on My Ignite for your chance to win one of many daily prizes.
39
Continue your Ignite learning path
Microsoft Ignite 2015 4/26/2017 8:23 AM Continue your Ignite learning path Visit Microsoft Virtual Academy for free online training visit Visit Channel 9 to access a wide range of Microsoft training and event recordings Head to the TechNet Eval Centre to download trials of the latest Microsoft products © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.