64
Azure managed OS updates You manage OS + apps .NET, node, PHP, Python .NET, node, PHP, Java, Scala, Python, Ruby, C++, freakin’ Virtual Machines Web sites

Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Embed Size (px)

Citation preview

Page 1: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Azure managed OS updates

You manage OS + apps

.NET, node, PHP, Python

.NET, node, PHP,Java, Scala,

Python, Ruby, C++,

freakin’ Erlang…

Virtual Machines

Web sites

Page 2: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Virtual Machines

Azure managed OS updates

You manage OS + apps

Web sites.NET, node, PHP, Python

.NET, node, PHP,Java, Scala,

Python, Ruby, C++,

freakin’ Erlang…

Cloud apps(Stateless VMs)

Page 3: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Virtual Machines

Azure managed OS updates

Web sites.NET, node, PHP, Python

.NET, node, PHP,Java, Scala,

Python, Ruby, C++,

freakin’ Erlang…

Service Fabric(Stateless Services)

You manage OS + apps

Page 4: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Service

Fabric

Service

Fabric Service

Fabric

Service

Fabric Service

Fabric

Service

Fabric

Service

FabricService

Fabric

Service

FabricService

Fabric

Service

FabricService

Fabric

Virtual Machines

Azure managed OS updates

Web sites.NET, node, PHP, Python

.NET, node, PHP,Java, Scala,

Python, Ruby, C++,

freakin’ Erlang… You manage OS + apps

Page 5: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Your first house

Azure managed OS updates

Hotel.NET, node, PHP, Python

.NET, node, PHP,Java, Scala,

Python, Ruby, C++,

freakin’ Erlang…

Renting a room

You manage OS + apps

Page 6: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

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

Actor programming model

Page 7: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Alexandre Brisebois, Microsoft – [email protected] / Twitter: @briseboisStephane Lapointe, Orckestra - [email protected] / Twitter: @s_lapointe

A practical overview of Service Fabric

Page 8: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Agenda Demo: Live Q&A app Microwhat? Service Fabric platform Benefits Programing models Lifecycle management Summary

Page 9: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Live Q&A applicationhttp://bit.ly/live-qnaDemo

Page 10: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Microwhat?

Page 11: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Encapsulate a customer or business scenario

Are developed by a small engineering team

Can be written in any programming language and use any framework

Consist of code and optionally state that is independently versioned, deployed, and scaled

What is a microservice?

Page 12: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Interacts with other microservices over well-defined interfaces and protocols

Has a unique name (URL) that can be used to resolve its location.

Remains consistent and available in the presence of failures

What is a microservice?

Page 13: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Build and operate services at scale

Agility - faster delivery of features & updates

Better resource utilization

Why?

Page 14: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Benefits Simpler to design Faster calls between components Testing a single productDownside Tightly coupled within the tiered layers Harder to perform fixes and upgrades

Monolithic approach

Page 15: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Benefits Scalability + fast spinup Encourage simpler business functionality encapsulation Isolated components with independent lifecycle Fit the lean startup approach – build, measure, learn, iterateDownside Increased number of separate entities More complex deployments Network latency between microservices Easy to endup with a performance nightmare

Microservice approach

Page 16: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric
Page 17: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric
Page 18: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Types of microservicesStateless microservice

Has either no state or it can be retrieved from an external store There can be N instances e.g. web frontends, protocol gateways, Azure Cloud Services etc.

Stateful microservice Maintain hard, authoritative state N consistent copies achieved through replication and local persistence e.g. database, documents, workflow, user profile, shopping cart etc.

Page 19: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Service Fabric platform

Page 20: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Microsoft Azure Service FabricA platform for reliable, hyperscale, microservice-based applications

Azure

WindowsServer Linux

Hosted Clouds

WindowsServer Linux

Service Fabric

Private Clouds

WindowsServer Linux

High Availability

Hyper-Scale

Hybrid Operations

High Density

microservices

Rolling Upgrades Stateful

services

Low Latency Fast startup & shutdown

Container Orchestration & lifecycle management Replication &

FailoverSimple

programming models

Load balancing

Self-healingData Partitioning

Automated Rollback

Health Monitoring

Placement Constraints

Page 21: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Battle-hardened for over 5 years

Azure Core Infrastruct

ure

thousands of machines

Power BI

Intune

over 1m

devices

Azure SQL

Database

millions of databases

Bing Cortana

500m evals/sec

Azure Documen

t DB

billions transactions/wee

k

Skype for

Business

Hybrid Ops

Event Hubs20bn

events/day

Page 22: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Service Fabric Subsystems

Communication

SubsystemService discovery

ReliabilitySubsystem

Reliability, Availability, Replication,

Service Orchestration

Hosting & ActivationSubsystem

Application lifecycle

TestabilitySubsystemFault Inject,

Test in productionFederationFederates a set of nodes to form a consistent scalable fabric

TransportSecure point-to-point communication

Application Programming Models

ManagementSubsystemDeployment, Upgrade and Monitoring

microservices

Page 23: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

What is a microservice in Service Fabric? L+S (logic + state) that is independently versioned,

deployed, and scaled Has a unique name that can be resolved

e.g. fabric:/myapplication/myservice Interacts with other microservices over well defined

interfaces and protocols like REST Remains always logically consistent in the presence

of failures Hosted inside a “container” (code + config) Can be written in any language and framework

.NET, node.js, Java VMs, any EXE

Page 24: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

A set of independent machines; physical or virtual

Typical datacenter

Page 25: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

A set of machines that Service Fabric stitches together to form a cluster

Clusters can scale to1000s of machines

Cluster: A federation of machines

Node

Node

Node

Node

Node

Node

Page 26: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Cluster: System viewSystem Services Failover manager

Cluster manager

Naming

Image store

Page 27: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

App1

App2

Service Fabric cluster with microservices

Page 28: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Stateful microserviceApplication Package

PSSreplication

replication

PSS

Page 29: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Each service is backed by replica set to make its internal state reliable

All replicas are logically consistent – meaning all replicas see the same linearized order of read and write operations to initial state

Read-Write quorums are supported and are dynamically adjusted

Replica set is dynamically reconfigured to account for replica arrivals and departures

Stateful microservices are reliable and consistent

Page 30: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Service Fabric Benefits

Page 31: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Massive scale No difference between dev and production Executables & frameworks can be .NET

and/or OSS Stateless or Stateful (micro)services Simplify application design, stateful service

instead of caches/queues

Key capabilities of Service Fabric

Page 32: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Deploy applications in seconds Write once, deploy almost anywhere Higher density than VM Multiple versions of the same application

side by side No downtime for breaking & nonbreaking

upgrades

Key capabilities of Service Fabric

Page 33: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Management via .NET APIs, PowerShell or REST

Upgrade and patch specific microservices OOB health & diagnostic Automatically adjust to scale up or scale

down Multiple version of the same application side

by side, each independently upgradable Self-healing resource balancer

Key capabilities of Service Fabric

Page 34: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Programming models

Page 35: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Service Fabric Applications

Azure Private Clouds

Applications composed of microservices

High Availability

Hyper-Scale

Hybrid Operations

High Density

Rolling Upgrades Stateful

services

Low Latency Fast startup & shutdown

Container Orchestration & lifecycle management Replication &

FailoverSimple

programming models

Load balancing

Self-healingData Partitioning

Automated Rollback

Health Monitoring

Placement Constraints

Service Fabric

Reliable Actors API Reliable Services API

Page 36: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Application Package

Unit of • Lifetime• Versioning• Isolation

LiveQnA.APIService type

LiveQnAExtensions type

Defining applications and services

LiveQnA Pkg

Code Config

LiveQnAExtensions

Pkg

Application Type

Page 37: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Instantiating an application

ServiceType is "like" a class type ApplicationType is "like" a typed Container ApplicationInstance is an instance of the ApplicationType and has an unique name

"fabric:/LiveQnAApplication" Each service instance has a unique name in the "namespace" of the application

"fabric:/LiveQnAApplication/LiveQnA.ApiService"

Service Package

B

Service Package

A

app1

Service Package

B

Service Package

Aapp4

Service Package

B

Service Package

A

app2

Service Package

B

Service Package

A

app3

Page 38: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Reliable Actors

Page 39: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

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

Reliable Actors

Page 40: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

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

Reliable Actors

Page 41: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Reliable Actors - Server side - Interfacepublic interface IMyActor : IActor{ Task<string> DoWorkAsync();}

Page 42: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Reliable Actors - Server side - Implementationpublic class MyActor : Actor, IMyActor{ public async Task<string> DoWorkAsync() { … return await Task.FromResult("result"); }}

Page 43: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Reliable Actors - Client side codevar app = "fabric:/HelloWorld";

var proxy = ActorProxy.Create<IMyActor> (ActorId.NewId(), app);

var result = proxy.DoWorkAsync().Result;

Page 44: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Actor Lifecycle

Page 45: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

1. If actor is not active, a new actor is created

2. Its state is then loaded (for stateful actors)

3. OnActivateSync method is called4. Added to Active Actors table

Actor lifecycle - Activation

Page 46: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Actor lifecycle - Deactivation1. Unused actors removed from the Active

Actors table2. OnDeactivateSync method is called on

Actor3. Once deactivated, objects are garbage

collected by CLR

Page 47: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Live Q&A application with Reliable ActorsDemo

Page 48: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Reliable Services

Page 49: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Write services that are reliable, available, scalable and provide consistency

More control over data partitioning so you can determine data relationships and consistency requirements between chunks of state

Multithreaded Use Reliable Collections to persist state More likely to BYO transport (WCF,

WebAPI, ..)

Reliable Services

Page 50: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Reliable Collections

Collections• Single Threaded

Concurrent Collections• Multi-Threaded

Reliable Collections• Multi-Node

• Replicated (HA)• Persistence

Option• Asynchronous• Transactional

Dictionary<TKey, TValue> ConcurrentDictionary<TKey, TValue> ReliableDictionary<TKey, TValue>

Single Machine Multi-Machine

Use our replicated datastructures or build your own

Page 51: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Data is replicated and durably stored on multiple replicas.Atomically update one or more collections using transactions.Reads are repeatable within the transaction.Enumerations are snapshot based.Supports LINQ.

Reliable CollectionsIReliableQueue<T>IReliableDictionary<

K,V>

Page 52: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Reliable Actors APIs Reliable Services APIsYour problem space involves many small independent units of state and logic

You need to maintain logic across multiple components

You want to work with single-threaded objects while still being able to scale and maintain consistency

You want to use reliable collections (like .NET Dictionary and Queue) to store and manage your state

You want the framework to manage the concurrency and granularity of state

You want to control the granularity and concurrency of your state

You want the platform to manage communication for you

You want to manage the communication and control the partitioning scheme for your service

Comparing Reliable Actors & Reliable Service

Page 53: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Lifecycle management

Page 54: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Upgrading Services with zero downtime

One UD at a time Change only modified

service Automatic rollback

Node

Node

NodeNode

Node

Node

FD0/UD0

FD0/UD1

FD2/UD3

FD1/UD6

FD1/UD5

FD2/UD4Service Package

B

Service Package

A

1.0.0.0

2.0.0.0

Page 55: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Application upgradeDemo

Page 56: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Health PoliciesMaxPercentUnhealthyServices, MaxPercentUnhelathyDeployedApplications, ConsiderWarningsasError

UpgradeTimeoutIf an entire upgrade hits this timeout, the upgrade is failed.

Upgrade DomainTimeoutIf upgrading a UD hits this timeout, the upgrade is failed.

HealthCheckWaitDurationAfter an UD is upgraded, wait for this time before checking health of nodes in that UD.

HealthCheckStableDurationEven if the last health check passed, keep checking the health for this duration to ensure the upgrade is stable. If stable, upgrade the next UD.

UpgradeHealthCheckIntervalKeep checking health periodically with this interval until HealthCheckStableDuration is hit.

HealthCheckRetryTimeoutOnce this time out is hit, stop checking health and fail the upgrade.

Health Policies & Timeouts

Page 57: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Generates faults across the entire Service Fabric cluster

Compresses faults generally seen in months or years to a few hours

Combination of interleaved faults with the high fault rate finds corner cases that are otherwise missed

Leads to a significant improvement in the code quality of the service

Testability in Service Fabric

Page 58: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Chaos test Restart a node Restart a deployed code package Remove a replica Restart a replica Move a primary replica (optional) Move a secondary replica (optional) Failover test

Testability in Service Fabric

Page 59: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Failover test Restart a deployed code package where the partition is

hosted Remove a primary/secondary replica or stateless instance Restart a primary secondary replica (if a persisted service) Move a primary replica Move a secondary replica Restart the partition

Testability in Service Fabric

Page 60: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Welcome ChaosDemo

Page 61: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Stateless servicesA service that has state where the state is persisted to external storage, such as Azure databases or Azure storageExisting web (ASP.NET) and worker role applications

When will you build/use Service Fabric?

Stateful servicesReliability of state through replication and local persistenceReduces latencyReduces the complexity and number of components in traditional three tier architecture

Existing apps written with other frameworks

node.js, Java VMs, any EXE

Page 62: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Wrapping up… Are microservices for me?

Use Service Fabric to Reduce the complexities of building applications with the microservice approach

Start small, scale when needed, deprecate services, add new ones, evolve with customer usage, that’s the approach.

Page 63: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Wrapping up… Built micro-services using Reliable Actors

and Reliable Services APIs

Achieve Data Reliability through Stateful Actors and Reliable Collections

Scale-out using partitioning

Page 64: Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Service Fabric

Download the Service Fabric developer SDKhttp://aka.ms/ServiceFabric

Download the samples from GitHubhttp://aka.ms/ServiceFabricSamples

Learn from the tutorials and videoshttp://aka.ms/ServiceFabricDocs

Provide feedbackhttp://aka.ms/ServiceFabricForumhttp://stackoverflow.com/questions/tagged/azure-service-fabricTwitter hastag #AzureServiceFabric

Call to Action