Download - 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
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)
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
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
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
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
Alexandre Brisebois, Microsoft – [email protected] / Twitter: @briseboisStephane Lapointe, Orckestra - [email protected] / Twitter: @s_lapointe
A practical overview of Service Fabric
Agenda Demo: Live Q&A app Microwhat? Service Fabric platform Benefits Programing models Lifecycle management Summary
Live Q&A applicationhttp://bit.ly/live-qnaDemo
Microwhat?
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?
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?
Build and operate services at scale
Agility - faster delivery of features & updates
Better resource utilization
Why?
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
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
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.
Service Fabric platform
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
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
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
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
A set of independent machines; physical or virtual
Typical datacenter
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
Cluster: System viewSystem Services Failover manager
Cluster manager
Naming
Image store
App1
App2
Service Fabric cluster with microservices
Stateful microserviceApplication Package
PSSreplication
replication
PSS
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
Service Fabric Benefits
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
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
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
Programming models
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
Application Package
Unit of • Lifetime• Versioning• Isolation
LiveQnA.APIService type
LiveQnAExtensions type
Defining applications and services
LiveQnA Pkg
Code Config
LiveQnAExtensions
Pkg
Application Type
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
Reliable Actors
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
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
Reliable Actors - Server side - Interfacepublic interface IMyActor : IActor{ Task<string> DoWorkAsync();}
Reliable Actors - Server side - Implementationpublic class MyActor : Actor, IMyActor{ public async Task<string> DoWorkAsync() { … return await Task.FromResult("result"); }}
Reliable Actors - Client side codevar app = "fabric:/HelloWorld";
var proxy = ActorProxy.Create<IMyActor> (ActorId.NewId(), app);
var result = proxy.DoWorkAsync().Result;
Actor Lifecycle
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
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
Live Q&A application with Reliable ActorsDemo
Reliable Services
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
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
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>
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
Lifecycle management
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
Application upgradeDemo
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
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
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
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
Welcome ChaosDemo
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
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.
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
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