SlideShare a Scribd company logo
Azure Service Fabric and the Actor
Model: when did we forget Object
Orientation?
João Pedro “jota”Martins
03.September.2016
João Pedro “jota” Martins
Cloud Solution Architect @ Microsoft UK
Co-founder - GASP (architecture UG) + APPU (usability prof. assoc.)
TechEd 2006 – “Iron Architect” competition winner
BizTalk Server MVP 2006-2011
Former CTO @ |create|it| - Premium S.I./MSFT Partner @ Lisbon, Portugal
Ground Rules and Expectations
Murphy’s law:
there will [probably] be problems in the demos 
This is a different way of architecting software:
there will be disagreements 
There is a lot to say:
there won’t be enough time 
What’s this session about?
MicrosoftAzureServiceFabric
=A platform for reliable, hyperscale, microservice-based applications
=“PaaS v2”+ Stateless+Stateful Services/Actors
=Platform for applications BORNFORTHECLOUD,not Lift&Shift’ed
ActorModel@ ServiceFabric
=model of concurrent computation that treats "actors"astheprimitivesofconcurrentcomputation.
Actors can implement logic, create more actors, send messages, and determine how to respond to a
message received. Actors only modify private state.
=use Service Fabric for hosting
~= Object Orientation with state persistence +communication through messaging passing
the platform
Public Cloud Other CloudsOn Premises
Private cloud
Your laptop
MicrosoftAzure Service Fabric
A platformfor reliable,hyperscale,microservice-basedapplications
Microservices
Service Fabric
Battle-hardened for over 5 years
Windows OS
Windows OS Windows OS
Windows OS
Windows OS
Windows OS
Fabric
Node
Fabric
Node
Fabric
Node
Fabric
Node
Fabric
Node
Fabric
Node
Set of OS instances grouped to form a pool of resources
Cluster can scale to 1000s of machines, is self repairing, and scales-up or down
Acts as environment-independent abstraction layer [note:canspreadgeographicregions]
Service Fabric Cluster
= VM scale set running special services in it
Azure ServiceFabricCapabilities
High density service hosting
Partitioningsupport
Load balancing
Placement constraints
Consistent state replication framework
Reliable distributed key/value store,
collections and queues
Actor Model
Application deployment services:
 Rolling update with rollback
 Strong versioning
 Side-by-side support
Leadership election
Name service for discovery
= enterprise-ready computational environment to run things at scale
Service Fabric Microservices
A microservice is whatever you want itto be:
 ASP.NET,node.js,JavaVMs,anarbitrary .exe(*Linuxversioncomingsoon)
 WhatwedeploytoService Fabric
Statelessmicroservice
 Haseithernostateoritcanberetrieved fromanexternalstore
 TherecanbeNinstances inmultiplenodes
 e.g.webfrontends,protocolgateways,loadbalancers,etc.
 Mostofwhatwe’vebeendoinginthelast10years
Statefulmicroservice
 Maintainhard,authoritativestate
 Nconsistent/reliablecopies achieved throughreplicationandlocalpersistence
 Reducesthecomplexity andnumberofcomponents intraditional three-tier architecture
 e.g.webusersession,documents,workflow,userprofile,shoppingcart,IoTdevices,multiplayergames,etc.
App1 App2
Handling Machine Failures
App Type Packages Service Fabric Cluster VMs
Upgrading Services withzero downtime
FD – Failure Domain; UD – Upgrade Domain
Node 5Node 4Node 3 Node 6Node 2Node 1
Service partitioning
P2
S
S
S
P4
S
P1
S
P3S
S
S
• Services can be partitioned for scale-out.
• You can choose your own partitioning scheme.
• Service partitions are striped across machines in the cluster.
• Replicas automatically scale out & in on cluster changes
Basics for devs
Download from WebPI
Sets up local dev cluster
with 5 nodes by default
Includes service fabric
explorer + powershell
cmdlets
Same code that runs on
Azure
the programming model
What is a microservice in Service Fabric?
Is (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” node
Can be written in any language/framework
Developed by a small engineering team
Reliable Services API
Build stateless services using existing technologies such as ASP.NET WebAPI
Build stateful services using reliable collections
• ReliableDictionary<T>, ReliableQueue<T>
• Data Contract Serializer
Manage the concurrency and granularity of state changes using transactions
Communicate with services using the technology of your choice
• e.g. WebAPI , WCF Collections
• Single machine
• Single threaded
Concurrent
Collections
• Single machine
• Multi threaded
Reliable Collections
•Multi machine
•Multi threaded
•Replicated (HA)
•Persistence
•Asynchronous
•Transactional
Queues Storage
“Classical” 3-Tier service pattern
Front End
(Stateless
Web)
Stateless
Middle-tier
Compute
Cache
Scale with partitioned storage
Increase reliability with queues
Reduce read latency with
caches
Manage your own transactions
for state consistency
… Many moving parts each
managed differently
Load Balancer
Stateful
Middle-tier
Compute
Stateful services: Simplifydesign, reduce latency
Front End
(Stateless
Web)
data stores used for analytics and disaster recovery
Application state lives in the
compute tier
Low Latency reads and writes
Partitions are first class for
scale-out
Built in transactions
Fewer moving parts
Load Balancer
Statefulservice+AutomaticFailover
demo
Reliable Actors
Public Cloud Other CloudsOn Premises
Private cloud
ServiceFabric Programming Models
Your laptop
What is the actor model?
Independent entities
… holding their own attributes
… with their own behaviour
… making decisions based on their knowledge
… sending messages
… and responding to messages.
 can be modelled with actor pattern/model.
Service Fabric Reliable Actors
• Asynchronous and single-threaded programming model
• API to build stateless and stateful objects through the virtual actor
programming model
• Support polymorphism/inheritance
• Proxy for actor-to-actor and client-to-actor communication
• Runtime automatically maintains lifecycle of actors, and handles
failovers, scales, upgrades, partitioning, etc.
StatefulActors:creatinganactorservice
demo
StatefulActors:managing aconference
demo
Demo: “classdiagram”
Defining an actor class
Creating an actor instance / Sending messages
ActorProxy.Create – creates an Actor with a given Id and returns a proxy
to it, or returns a proxy to existing actor
As there are no constructors, initializing or sending messages is the same
Actor initialization
Just create a method and call it via a message (there are no constructors),
for example:
Actor/Client-to-Actor messaging
Remember this requires network communication, including serialization
and deserialization of payloads.
ActorProxy retries in case of communication failure or actor failover…
At-least-once message delivery
 … use idempotence
Order is not guaranteed
Only one method of an actor instance is executed at any given time.
Turn-based concurrency
Only applies to each specific actor instance . Multiple actor instances run inparallel in the same host .
Reentrancy
By default actors allow re-entrance
in the same logical call-chain context.
This can be disabled for specific actor types with:
ReentrancyMode = ActorReentrancyMode.Disallowed
in ActorConcurrencySettings when the actor type is registered with Service Fabric
Reading and updating state inside na actor
StateManager instance, inherited from Actor superclass
Reads and writes that actor instance’s private data:
- SetStateAsync(“name”, object) // name = object;
- GetStateAsync<T>(“name”) || TryGetState<T> // return name;
- AddStateAsync(“name”, object) || TryAddStateAsync<T>
- AddOrUpdateStateAsync(“name”, object, delegate)
- RemoveStateAsync(“name”) || TryRemoveStateAsync
Values are persisted at the end of the actor method (all-or-nothing).
Lifetimeand garbage collection
Actoractivation
-When a callcomes for an actor
and one is not already active, a
newactoris created
-The actor's state is loaded ifit's
maintaining state.
- The OnActivateAsync method
is called.
Activation =instantiate aCLR
object in memory +loading its
State if it exits
Actordeactivation
- Whenanactoris notusedfor
someperiodof time(60min),itis
removed from the Active Actors
table
- The OnDeactivateAsync
method is called
Being used =method call or
reminder method executed
GarbageCollection
When an actor is deactivated,
references to the actor object are
released and itcan be garbage
collected normally by the CLR GC
(1x/min)
Thisonlycleansuptheactor
object;itdoes not removestate
storedintheactor'sState
Manager.
The next time the actor is
activated, a newactorobjectis
createdandits stateisrestored.
«ACTORSAREMEANTTOABSTRACTAWAYTHELIFETIMEOFANOBJECT'SINSTANCE.JUSTCALLONEWHENYOUNEEDIT,ANDITWILLBETHERE.»
Timers
- Schedule regular
execution of a callback
on an actor.
- Time doesn’t count
during execution.
- Doesn’t prevent GC.
- Respects turn-based
concurrency.
- Use UnregisterTimer
to remove.
Reminders
Similar to Timers, but:
- Are persisted with
Actor state
- Execute even if actor is
deactivated/failover
- Can prevent GC
- Only one callback
method
- Use
UnregisterReminder to
remove
Events
Designed for
Actor to Client
communication
Recreated incase
of failovers
1-Defineaninterfacethatdescribes the
eventspublished bytheactor.
4-Ontheclient, createaproxytotheactor
thatpublishestheeventandsubscribetoits
events.
2-Declaretheeventspublished bythe
actorintheactorinterface.
3-Ontheclient side,
implement theevent handler
5-Ontheactor,publishtheevents
In conclusion…
Service Fabric Actors…
• Have behaviour + state
• Bring back the Object Orientation + statefulnes concepts we had lost
• Run in a performant enterprise-ready scalable environment
• Especially suited for web session state, shopping cart, iot devices, or any scenarios
with independent objects with own lifetime/state/behaviour
But…
• Requires re-architecting existing apps
• API can still be improved
References
Azure Service Fabric - http://aka.ms/ServiceFabric
Azure Service Fabric Documentation - http://aka.ms/ServiceFabricdocs
Orleans: Distributed Virtual Actors for Programmability and Scalability - https://www.microsoft.com/en-
us/research/publication/orleans-distributed-virtual-actors-for-programmability-and-scalability/
Book: Programming Microsoft Azure Service Fabric by Haishi Bai (Microsoft Press)
Azure Service Fabric Samples - http://aka.ms/ServiceFabricSamples
Akka.net (alternative .Net implementation of the Actor Model) - http://getakka.net/
Actor Model (1973) - https://en.wikipedia.org/wiki/Actor_model
Martin Fowler on Microservices - http://martinfowler.com/articles/microservices.html
Signup for Service Fabric on Linux - http://aka.ms/SFlinuxpreview
Try a Party Cluster (it’s free!):
http://aka.ms/TryServiceFabric
João Pedro “jota” Martins
JoaoPedro.Martins@Microsoft.com
blog.joaopedromartins.net
@lokijota
pt.linkedin.com/in/joaopedromartins/
thanks! questions?

More Related Content

PPTX
Devteach 2016: A practical overview of actors in service fabric
PPTX
Service Fabric – building tomorrows applications today
PPTX
Usage of Reliable Actors in Azure Service Fabric
PPTX
Tokyo azure meetup #12 service fabric internals
PPTX
Deep dive into service fabric after 2 years
PDF
Azure paa s v2 – microservices, microsoft (azure) service fabric, .apps and o...
PPTX
Azure service fabric: a gentle introduction
PPTX
Tokyo Azure Meetup #5 - Microservices and Azure Service Fabric
Devteach 2016: A practical overview of actors in service fabric
Service Fabric – building tomorrows applications today
Usage of Reliable Actors in Azure Service Fabric
Tokyo azure meetup #12 service fabric internals
Deep dive into service fabric after 2 years
Azure paa s v2 – microservices, microsoft (azure) service fabric, .apps and o...
Azure service fabric: a gentle introduction
Tokyo Azure Meetup #5 - Microservices and Azure Service Fabric

What's hot (20)

PPTX
Global Azure Bootcamp: Azure service fabric
PDF
Microservices to Scale using Azure Service Fabric
PPTX
Azure Service Fabric Overview
PPTX
MicroServices on Azure
PPTX
Azure servicefabric
PPTX
Microservice.net by sergey seletsky
PPTX
Microservices and Azure App Services
PPTX
The Microservices world in. NET Core and. NET framework
PDF
Microservice and Service Fabric talk
PDF
Distributed Computing made easy with Service Fabric
PPTX
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
PPTX
Stephane Lapointe, Frank Boucher & Alexandre Brisebois: Les micro-services et...
PPTX
Azure Service Fabric
PPTX
Tokyo Azure Meetup #4 - Build 2016 Overview
PPTX
Microservices with Azure Service Fabric
ODP
micro services architecture (FrosCon2014)
PPTX
Tokyo Azure Meetup #6 - Azure Monthly Update - June
PPTX
Micro Services in .NET Core and Docker
PPTX
Microservices in Azure
PPTX
.NET microservices with Azure Service Fabric
Global Azure Bootcamp: Azure service fabric
Microservices to Scale using Azure Service Fabric
Azure Service Fabric Overview
MicroServices on Azure
Azure servicefabric
Microservice.net by sergey seletsky
Microservices and Azure App Services
The Microservices world in. NET Core and. NET framework
Microservice and Service Fabric talk
Distributed Computing made easy with Service Fabric
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
Stephane Lapointe, Frank Boucher & Alexandre Brisebois: Les micro-services et...
Azure Service Fabric
Tokyo Azure Meetup #4 - Build 2016 Overview
Microservices with Azure Service Fabric
micro services architecture (FrosCon2014)
Tokyo Azure Meetup #6 - Azure Monthly Update - June
Micro Services in .NET Core and Docker
Microservices in Azure
.NET microservices with Azure Service Fabric
Ad

Viewers also liked (19)

PPTX
Azure Service Fabric - weaving services in hyper-scale
PPTX
Azure Service Fabric pour les développeurs
PDF
Using the Actor Model with Domain-Driven Design (DDD) in Reactive Systems - w...
PDF
Patterns & Practices of Microservices
PPTX
Service Fabric Overview (Yves Goeleven)
PPTX
Docker + .NET Core Demos | Radu Vunvulea
PPTX
Graph Database workshop
PPTX
Massively Scaleable .NET Web Services with Project Orleans
PDF
Patterns & Practices for Cloud-based Microservices
PPTX
.NET Security (Radu Vunvulea)
PPTX
Empower your raspberry pi using Azure IoT suite, Radu Vunvulea
PPTX
Implement API Gateway using Azure API Management
PPTX
What new in asp.net mvc, 5 visual studio 2015 and web tooling, radu vunvulea,...
PPTX
08 hopex v next service fabric
PPTX
Project Orleans - Actor Model framework
PPTX
NS study8 DDD Microservices Azuer Service Fabric
PPTX
From a monolith to microservices with Azure Service Fabric
PDF
Developing Applications with a Micro Service Architecture - Chris Richardson
PPTX
Миграция в Azure Service Fabric
Azure Service Fabric - weaving services in hyper-scale
Azure Service Fabric pour les développeurs
Using the Actor Model with Domain-Driven Design (DDD) in Reactive Systems - w...
Patterns & Practices of Microservices
Service Fabric Overview (Yves Goeleven)
Docker + .NET Core Demos | Radu Vunvulea
Graph Database workshop
Massively Scaleable .NET Web Services with Project Orleans
Patterns & Practices for Cloud-based Microservices
.NET Security (Radu Vunvulea)
Empower your raspberry pi using Azure IoT suite, Radu Vunvulea
Implement API Gateway using Azure API Management
What new in asp.net mvc, 5 visual studio 2015 and web tooling, radu vunvulea,...
08 hopex v next service fabric
Project Orleans - Actor Model framework
NS study8 DDD Microservices Azuer Service Fabric
From a monolith to microservices with Azure Service Fabric
Developing Applications with a Micro Service Architecture - Chris Richardson
Миграция в Azure Service Fabric
Ad

Similar to Azure Service Fabric and the Actor Model: when did we forget Object Orientation? (20)

PPTX
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
PPSX
Moderne backends mit dem aktor programmiermodell
PPTX
Discovering the Service Fabric's actor model
PPTX
Azure service fabric
PPTX
Azure Service Fabric: notes from the field (Sam Vanhoute @Integrate 2016)
PPTX
Service fabric overview
PPTX
Discovering the Service Fabric's actor model
PPTX
Developing Actors in Azure with .net
PPTX
Azure Service Fabric: The road ahead for microservices
PPTX
Pieter de Bruin (Microsoft) - Welke technologie gebruiken bij implementatie M...
PPTX
Azure service fabric overview
PPTX
Testing a Service Fabric solution and live happy!!
PPTX
Azure Microservices in Practice, Radu Vunvulea, ITCamp 2016
PPTX
Serhiy Kalinets "Embracing architectural challenges in the modern .NET world"
PDF
Introducing Akka
PDF
Introducingakkajavazone2012 120914094033-phpapp02
PDF
Microsoft: Building a Massively Scalable System with DataStax and Microsoft's...
PPTX
ServiceFabric-Arch
PPTX
Cooking Akka.net and Azure Service Fabric together
PPTX
Designing distributed systems
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
Moderne backends mit dem aktor programmiermodell
Discovering the Service Fabric's actor model
Azure service fabric
Azure Service Fabric: notes from the field (Sam Vanhoute @Integrate 2016)
Service fabric overview
Discovering the Service Fabric's actor model
Developing Actors in Azure with .net
Azure Service Fabric: The road ahead for microservices
Pieter de Bruin (Microsoft) - Welke technologie gebruiken bij implementatie M...
Azure service fabric overview
Testing a Service Fabric solution and live happy!!
Azure Microservices in Practice, Radu Vunvulea, ITCamp 2016
Serhiy Kalinets "Embracing architectural challenges in the modern .NET world"
Introducing Akka
Introducingakkajavazone2012 120914094033-phpapp02
Microsoft: Building a Massively Scalable System with DataStax and Microsoft's...
ServiceFabric-Arch
Cooking Akka.net and Azure Service Fabric together
Designing distributed systems

More from João Pedro Martins (7)

PPTX
The new Azure App Service Architecture
PPTX
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
PDF
Architecting a Large Software Project - Lessons Learned
PPTX
20140520 Microsoft WebCamp - DataBinding with KnockoutJS
PDF
Power your website with Windows Azure
PPTX
Software Estimation - A Step Closer to the Silver Bullet
PPTX
eCommerce Solutions on Windows Azure
The new Azure App Service Architecture
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
Architecting a Large Software Project - Lessons Learned
20140520 Microsoft WebCamp - DataBinding with KnockoutJS
Power your website with Windows Azure
Software Estimation - A Step Closer to the Silver Bullet
eCommerce Solutions on Windows Azure

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Machine learning based COVID-19 study performance prediction
PPTX
A Presentation on Artificial Intelligence
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
cuic standard and advanced reporting.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Modernizing your data center with Dell and AMD
PPTX
Big Data Technologies - Introduction.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Electronic commerce courselecture one. Pdf
Network Security Unit 5.pdf for BCA BBA.
Machine learning based COVID-19 study performance prediction
A Presentation on Artificial Intelligence
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Diabetes mellitus diagnosis method based random forest with bat algorithm
Spectral efficient network and resource selection model in 5G networks
Encapsulation_ Review paper, used for researhc scholars
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
cuic standard and advanced reporting.pdf
Empathic Computing: Creating Shared Understanding
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Modernizing your data center with Dell and AMD
Big Data Technologies - Introduction.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Understanding_Digital_Forensics_Presentation.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

Azure Service Fabric and the Actor Model: when did we forget Object Orientation?

  • 1. Azure Service Fabric and the Actor Model: when did we forget Object Orientation? João Pedro “jota”Martins 03.September.2016
  • 2. João Pedro “jota” Martins Cloud Solution Architect @ Microsoft UK Co-founder - GASP (architecture UG) + APPU (usability prof. assoc.) TechEd 2006 – “Iron Architect” competition winner BizTalk Server MVP 2006-2011 Former CTO @ |create|it| - Premium S.I./MSFT Partner @ Lisbon, Portugal
  • 3. Ground Rules and Expectations Murphy’s law: there will [probably] be problems in the demos  This is a different way of architecting software: there will be disagreements  There is a lot to say: there won’t be enough time 
  • 4. What’s this session about? MicrosoftAzureServiceFabric =A platform for reliable, hyperscale, microservice-based applications =“PaaS v2”+ Stateless+Stateful Services/Actors =Platform for applications BORNFORTHECLOUD,not Lift&Shift’ed ActorModel@ ServiceFabric =model of concurrent computation that treats "actors"astheprimitivesofconcurrentcomputation. Actors can implement logic, create more actors, send messages, and determine how to respond to a message received. Actors only modify private state. =use Service Fabric for hosting ~= Object Orientation with state persistence +communication through messaging passing
  • 6. Public Cloud Other CloudsOn Premises Private cloud Your laptop MicrosoftAzure Service Fabric A platformfor reliable,hyperscale,microservice-basedapplications Microservices Service Fabric
  • 8. Windows OS Windows OS Windows OS Windows OS Windows OS Windows OS Fabric Node Fabric Node Fabric Node Fabric Node Fabric Node Fabric Node Set of OS instances grouped to form a pool of resources Cluster can scale to 1000s of machines, is self repairing, and scales-up or down Acts as environment-independent abstraction layer [note:canspreadgeographicregions] Service Fabric Cluster = VM scale set running special services in it
  • 9. Azure ServiceFabricCapabilities High density service hosting Partitioningsupport Load balancing Placement constraints Consistent state replication framework Reliable distributed key/value store, collections and queues Actor Model Application deployment services:  Rolling update with rollback  Strong versioning  Side-by-side support Leadership election Name service for discovery = enterprise-ready computational environment to run things at scale
  • 10. Service Fabric Microservices A microservice is whatever you want itto be:  ASP.NET,node.js,JavaVMs,anarbitrary .exe(*Linuxversioncomingsoon)  WhatwedeploytoService Fabric Statelessmicroservice  Haseithernostateoritcanberetrieved fromanexternalstore  TherecanbeNinstances inmultiplenodes  e.g.webfrontends,protocolgateways,loadbalancers,etc.  Mostofwhatwe’vebeendoinginthelast10years Statefulmicroservice  Maintainhard,authoritativestate  Nconsistent/reliablecopies achieved throughreplicationandlocalpersistence  Reducesthecomplexity andnumberofcomponents intraditional three-tier architecture  e.g.webusersession,documents,workflow,userprofile,shoppingcart,IoTdevices,multiplayergames,etc.
  • 11. App1 App2 Handling Machine Failures App Type Packages Service Fabric Cluster VMs
  • 12. Upgrading Services withzero downtime FD – Failure Domain; UD – Upgrade Domain
  • 13. Node 5Node 4Node 3 Node 6Node 2Node 1 Service partitioning P2 S S S P4 S P1 S P3S S S • Services can be partitioned for scale-out. • You can choose your own partitioning scheme. • Service partitions are striped across machines in the cluster. • Replicas automatically scale out & in on cluster changes
  • 14. Basics for devs Download from WebPI Sets up local dev cluster with 5 nodes by default Includes service fabric explorer + powershell cmdlets Same code that runs on Azure
  • 16. What is a microservice in Service Fabric? Is (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” node Can be written in any language/framework Developed by a small engineering team
  • 17. Reliable Services API Build stateless services using existing technologies such as ASP.NET WebAPI Build stateful services using reliable collections • ReliableDictionary<T>, ReliableQueue<T> • Data Contract Serializer Manage the concurrency and granularity of state changes using transactions Communicate with services using the technology of your choice • e.g. WebAPI , WCF Collections • Single machine • Single threaded Concurrent Collections • Single machine • Multi threaded Reliable Collections •Multi machine •Multi threaded •Replicated (HA) •Persistence •Asynchronous •Transactional
  • 18. Queues Storage “Classical” 3-Tier service pattern Front End (Stateless Web) Stateless Middle-tier Compute Cache Scale with partitioned storage Increase reliability with queues Reduce read latency with caches Manage your own transactions for state consistency … Many moving parts each managed differently Load Balancer
  • 19. Stateful Middle-tier Compute Stateful services: Simplifydesign, reduce latency Front End (Stateless Web) data stores used for analytics and disaster recovery Application state lives in the compute tier Low Latency reads and writes Partitions are first class for scale-out Built in transactions Fewer moving parts Load Balancer
  • 22. Public Cloud Other CloudsOn Premises Private cloud ServiceFabric Programming Models Your laptop
  • 23. What is the actor model? Independent entities … holding their own attributes … with their own behaviour … making decisions based on their knowledge … sending messages … and responding to messages.  can be modelled with actor pattern/model.
  • 24. Service Fabric Reliable Actors • Asynchronous and single-threaded programming model • API to build stateless and stateful objects through the virtual actor programming model • Support polymorphism/inheritance • Proxy for actor-to-actor and client-to-actor communication • Runtime automatically maintains lifecycle of actors, and handles failovers, scales, upgrades, partitioning, etc.
  • 29. Creating an actor instance / Sending messages ActorProxy.Create – creates an Actor with a given Id and returns a proxy to it, or returns a proxy to existing actor As there are no constructors, initializing or sending messages is the same
  • 30. Actor initialization Just create a method and call it via a message (there are no constructors), for example:
  • 31. Actor/Client-to-Actor messaging Remember this requires network communication, including serialization and deserialization of payloads. ActorProxy retries in case of communication failure or actor failover… At-least-once message delivery  … use idempotence Order is not guaranteed Only one method of an actor instance is executed at any given time.
  • 32. Turn-based concurrency Only applies to each specific actor instance . Multiple actor instances run inparallel in the same host .
  • 33. Reentrancy By default actors allow re-entrance in the same logical call-chain context. This can be disabled for specific actor types with: ReentrancyMode = ActorReentrancyMode.Disallowed in ActorConcurrencySettings when the actor type is registered with Service Fabric
  • 34. Reading and updating state inside na actor StateManager instance, inherited from Actor superclass Reads and writes that actor instance’s private data: - SetStateAsync(“name”, object) // name = object; - GetStateAsync<T>(“name”) || TryGetState<T> // return name; - AddStateAsync(“name”, object) || TryAddStateAsync<T> - AddOrUpdateStateAsync(“name”, object, delegate) - RemoveStateAsync(“name”) || TryRemoveStateAsync Values are persisted at the end of the actor method (all-or-nothing).
  • 35. Lifetimeand garbage collection Actoractivation -When a callcomes for an actor and one is not already active, a newactoris created -The actor's state is loaded ifit's maintaining state. - The OnActivateAsync method is called. Activation =instantiate aCLR object in memory +loading its State if it exits Actordeactivation - Whenanactoris notusedfor someperiodof time(60min),itis removed from the Active Actors table - The OnDeactivateAsync method is called Being used =method call or reminder method executed GarbageCollection When an actor is deactivated, references to the actor object are released and itcan be garbage collected normally by the CLR GC (1x/min) Thisonlycleansuptheactor object;itdoes not removestate storedintheactor'sState Manager. The next time the actor is activated, a newactorobjectis createdandits stateisrestored. «ACTORSAREMEANTTOABSTRACTAWAYTHELIFETIMEOFANOBJECT'SINSTANCE.JUSTCALLONEWHENYOUNEEDIT,ANDITWILLBETHERE.»
  • 36. Timers - Schedule regular execution of a callback on an actor. - Time doesn’t count during execution. - Doesn’t prevent GC. - Respects turn-based concurrency. - Use UnregisterTimer to remove.
  • 37. Reminders Similar to Timers, but: - Are persisted with Actor state - Execute even if actor is deactivated/failover - Can prevent GC - Only one callback method - Use UnregisterReminder to remove
  • 38. Events Designed for Actor to Client communication Recreated incase of failovers 1-Defineaninterfacethatdescribes the eventspublished bytheactor. 4-Ontheclient, createaproxytotheactor thatpublishestheeventandsubscribetoits events. 2-Declaretheeventspublished bythe actorintheactorinterface. 3-Ontheclient side, implement theevent handler 5-Ontheactor,publishtheevents
  • 39. In conclusion… Service Fabric Actors… • Have behaviour + state • Bring back the Object Orientation + statefulnes concepts we had lost • Run in a performant enterprise-ready scalable environment • Especially suited for web session state, shopping cart, iot devices, or any scenarios with independent objects with own lifetime/state/behaviour But… • Requires re-architecting existing apps • API can still be improved
  • 40. References Azure Service Fabric - http://aka.ms/ServiceFabric Azure Service Fabric Documentation - http://aka.ms/ServiceFabricdocs Orleans: Distributed Virtual Actors for Programmability and Scalability - https://www.microsoft.com/en- us/research/publication/orleans-distributed-virtual-actors-for-programmability-and-scalability/ Book: Programming Microsoft Azure Service Fabric by Haishi Bai (Microsoft Press) Azure Service Fabric Samples - http://aka.ms/ServiceFabricSamples Akka.net (alternative .Net implementation of the Actor Model) - http://getakka.net/ Actor Model (1973) - https://en.wikipedia.org/wiki/Actor_model Martin Fowler on Microservices - http://martinfowler.com/articles/microservices.html Signup for Service Fabric on Linux - http://aka.ms/SFlinuxpreview Try a Party Cluster (it’s free!): http://aka.ms/TryServiceFabric
  • 41. João Pedro “jota” Martins JoaoPedro.Martins@Microsoft.com blog.joaopedromartins.net @lokijota pt.linkedin.com/in/joaopedromartins/ thanks! questions?

Editor's Notes

  • #4: The demos are based in software that is in preview. Problems are to be expected. The programming model underlying this approach is different from what has been the best practice in the age of SOA. Questions: [Hands raised] Who has used Azure Web and Worker Roles? Who has developed services-driven systems with stateless services?
  • #5: Service Fabric enables you to build and manage scalable and reliable applications composed of microservices running at very high density on a shared pool of machines (commonly referred to as a Service Fabric cluster). Powers a huge set of Microsoft Services: Azure SQL Database, Azure DocumentDB, Cortana, Power BI, Microsoft Intune, Azure Event Hubs, Skype for Business and others It provides a sophisticated runtime for building distributed, scalable stateless and stateful microservices. Also provides comprehensive application management capabilities for provisioning, deploying, monitoring, upgrading/patching, and deleting deployed applications. Service Fabric is tailored to creating “born in the cloud” services that can start small, as needed, and grow to massive scale with hundreds or thousands of machines, creating Service Fabric clusters across availability sets in a region or across regions. Fundamental concepts The Actor model adopts the philosophy that everything is an actor. This is similar to the everything is an object philosophy used by some object-oriented programming languages. An actor is a computational entity that, in response to a message it receives, can concurrently: - send a finite number of messages to other actors; - create a finite number of new actors; - designate the behavior to be used for the next message it receives. There is no assumed sequence to the above actions and they could be carried out in parallel. Decoupling the sender from communications sent was a fundamental advance of the Actor model enabling asynchronous communication and control structures as patterns ofpassing messages.[8] Recipients of messages are identified by address, sometimes called "mailing address". Thus an actor can only communicate with actors whose addresses it has. It can obtain those from a message it receives, or if the address is for an actor it has itself created. The Actor model is characterized by inherent concurrency of computation within and among actors, dynamic creation of actors, inclusion of actor addresses in messages, and interaction only through direct asynchronous message passing with no restriction on message arrival order.
  • #7: Executables Any exe, in any language and programming model. Packaged as Application, it gets versioning, upgrade, monitoring, health, etc. Reliable Services Stateless & stateful services Uses SDK Reliable Actors Stateless & stateful actor objects Uses SDK
  • #18: https://azure.microsoft.com/en-us/documentation/articles/service-fabric-reliable-services-reliable-collections/ Reliable Collections can be thought of as the natural evolution of the System.Collectionsclasses: a new set of collections that are designed for the cloud and multi-computer applications without increasing complexity for the developer. As such, Reliable Collections are: Replicated: State changes are replicated for high availability. Persisted: Data is persisted to disk for durability against large-scale outages (for example, a datacenter power outage). Asynchronous: APIs are asynchronous to ensure that threads are not blocked when incurring IO. Transactional: APIs utilize the abstraction of transactions so you can manage multiple Reliable Collections within a service easily. Reliable Collections provide strong consistency guarantees out of the box in order to make reasoning about application state easier. Strong consistency is achieved by ensuring transaction commits finish only after the entire transaction has been applied on a quorum of replicas, including the primary. To achieve weaker consistency, applications can acknowledge back to the client/requester before the asynchronous commit returns. The Reliable Collections APIs are an evolution of concurrent collections APIs (found in theSystem.Collections.Concurrent namespace): Asynchronous: Returns a task since, unlike concurrent collections, the operations are replicated and persisted. No out parameters: Uses ConditionalResult to return a bool and a value instead of out parameters. ConditionalResult is like Nullable but does not require T to be a struct. Transactions: Uses a transaction object to enable the user to group actions on multiple Reliable Collections in a transaction.
  • #21: http://stackoverflow.com/questions/34308701/service-fabric-deactivate-pause-vs-deactivate-restart
  • #23: Executables Any exe, in any language and programming model. Packaged as Application, it gets versioning, upgrade, monitoring, health, etc. Reliable Services Stateless & stateful services Uses SDK Reliable Actors Stateless & stateful actor objects Uses SDK
  • #24: The easiest way to visualize the Actor pattern at work is to look at human society . Each human (actor) is an independent entity . We all hold our own attributes, and we make decisions based on our knowledge (state and behaviour) and in reaction to the surrounding stipulates (messages) . We communicate with (send messages to) each other . Similarly, if a system can be described by a number of independent, interactive actors, it can be modelled using the Actor pattern . For example, in a multiplayer game, each player can be considered as an actor; in an e-commerce system, each shopping cart can be considered as an actor; in an Internet of Things (IoT) scenario, a sensor can be considered as an actor . A player, a shopping cart, and a sensor don’t seem to have anything in common, yet because they all have states, they all demonstrate some behaviours, and they all represent independent entities, they can be abstracted as actors . Good for representing discrete, independent entities e.g. IoT devices, workflow actions, shopping carts, domain entities, etc.
  • #25: - The Actor concept was originated in the early 70 in order to do large scale parallel processing and is becoming more popular with the advent of cloud computing. It’s meant to make writing distributed applications easier by dividing the problem in multiple units of state and computation that can run in parallel. Each unit in a simple single-threaded. Actors are actually very similar to objects in the way they represent state with some logic that operates on that state. These actors communicates with each other using asynchronous messages. - Running the actors on top of Service Fabric, you get the reliability of code as well as state and all other benefits of Service Fabric platform, like security, placement and resource balancing, zero downtime upgrade, locally replicated stores. What is an actor? - An independent unit of compute and [persistent] state with large number of them executing in parallel: an instance of a class - Communicates with other actors using asynchronous messaging - Has single threaded execution - turn based concurrency - Good for representing discrete, independent entities e.g. IoT devices, workflow actions, shopping carts, domain entities, etc. Actors are virtual, which means logically they always exist . You don’t need to create or destroy an actor . When you need to talk to an actor, you just use the actor proxy to send a message to it, Service Fabric will activate the actor if it hasn’t been activated or if it has been deactivated . After an actor hasn’t been used for a while, Service Fabric automatically will deactivate the actor to reduce resource consumption .
  • #36: https://azure.microsoft.com/en-us/documentation/articles/service-fabric-reliable-actors-lifecycle/ http://stackoverflow.com/questions/38271377/azure-service-fabric-how-to-find-out-if-an-actor-already-exists
  • #37: https://azure.microsoft.com/en-us/documentation/articles/service-fabric-reliable-actors-timers-reminders/
  • #38: https://azure.microsoft.com/en-us/documentation/articles/service-fabric-reliable-actors-timers-reminders/
  • #39: https://azure.microsoft.com/en-us/documentation/articles/service-fabric-reliable-actors-timers-reminders/
  • #42: Logo font: Monserrat Regular Logo color: #9a8e5e (154,142,94)