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

What's hot (20)

PPTX
Global Azure Bootcamp: Azure service fabric
Luis Valencia
 
PDF
Microservices to Scale using Azure Service Fabric
Mukul Jain
 
PPTX
Azure Service Fabric Overview
João Pedro Martins
 
PPTX
MicroServices on Azure
Sergey Seletsky
 
PPTX
Azure servicefabric
Abhishek Sur
 
PPTX
Microservice.net by sergey seletsky
Sergey Seletsky
 
PPTX
Microservices and Azure App Services
Damir Dobric
 
PPTX
The Microservices world in. NET Core and. NET framework
Massimo Bonanni
 
PDF
Microservice and Service Fabric talk
Daniel Kreuzhofer
 
PDF
Distributed Computing made easy with Service Fabric
BizTalk360
 
PPTX
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
Javier García Magna
 
PPTX
Stephane Lapointe, Frank Boucher & Alexandre Brisebois: Les micro-services et...
MSDEVMTL
 
PPTX
Azure Service Fabric
WinWire Technologies Inc
 
PPTX
Tokyo Azure Meetup #4 - Build 2016 Overview
Tokyo Azure Meetup
 
PPTX
Microservices with Azure Service Fabric
Davide Benvegnù
 
ODP
micro services architecture (FrosCon2014)
smancke
 
PPTX
Tokyo Azure Meetup #6 - Azure Monthly Update - June
Tokyo Azure Meetup
 
PPTX
Micro Services in .NET Core and Docker
cjmyers
 
PPTX
Microservices in Azure
Doug Vanderweide
 
PPTX
.NET microservices with Azure Service Fabric
Davide Benvegnù
 
Global Azure Bootcamp: Azure service fabric
Luis Valencia
 
Microservices to Scale using Azure Service Fabric
Mukul Jain
 
Azure Service Fabric Overview
João Pedro Martins
 
MicroServices on Azure
Sergey Seletsky
 
Azure servicefabric
Abhishek Sur
 
Microservice.net by sergey seletsky
Sergey Seletsky
 
Microservices and Azure App Services
Damir Dobric
 
The Microservices world in. NET Core and. NET framework
Massimo Bonanni
 
Microservice and Service Fabric talk
Daniel Kreuzhofer
 
Distributed Computing made easy with Service Fabric
BizTalk360
 
.Net Microservices with Event Sourcing, CQRS, Docker and... Windows Server 20...
Javier García Magna
 
Stephane Lapointe, Frank Boucher & Alexandre Brisebois: Les micro-services et...
MSDEVMTL
 
Azure Service Fabric
WinWire Technologies Inc
 
Tokyo Azure Meetup #4 - Build 2016 Overview
Tokyo Azure Meetup
 
Microservices with Azure Service Fabric
Davide Benvegnù
 
micro services architecture (FrosCon2014)
smancke
 
Tokyo Azure Meetup #6 - Azure Monthly Update - June
Tokyo Azure Meetup
 
Micro Services in .NET Core and Docker
cjmyers
 
Microservices in Azure
Doug Vanderweide
 
.NET microservices with Azure Service Fabric
Davide Benvegnù
 

Viewers also liked (19)

PPTX
Azure Service Fabric - weaving services in hyper-scale
Sebastian Gebski
 
PPTX
Azure Service Fabric pour les développeurs
Microsoft
 
PDF
Using the Actor Model with Domain-Driven Design (DDD) in Reactive Systems - w...
Lightbend
 
PDF
Patterns & Practices of Microservices
Wesley Reisz
 
PPTX
Service Fabric Overview (Yves Goeleven)
Visug
 
PPTX
Docker + .NET Core Demos | Radu Vunvulea
Radu Vunvulea
 
PPTX
Graph Database workshop
Jeremy Deane
 
PPTX
Massively Scaleable .NET Web Services with Project Orleans
Newman Hunter
 
PDF
Patterns & Practices for Cloud-based Microservices
C4Media
 
PPTX
.NET Security (Radu Vunvulea)
Radu Vunvulea
 
PPTX
Empower your raspberry pi using Azure IoT suite, Radu Vunvulea
Radu Vunvulea
 
PPTX
Implement API Gateway using Azure API Management
Alexander Laysha
 
PPTX
What new in asp.net mvc, 5 visual studio 2015 and web tooling, radu vunvulea,...
Radu Vunvulea
 
PPTX
08 hopex v next service fabric
Michel Bruchet
 
PPTX
Project Orleans - Actor Model framework
Neil Mackenzie
 
PPTX
NS study8 DDD Microservices Azuer Service Fabric
貴志 上坂
 
PPTX
From a monolith to microservices with Azure Service Fabric
Stéphane ERBRECH
 
PDF
Developing Applications with a Micro Service Architecture - Chris Richardson
JAXLondon2014
 
PPTX
Миграция в Azure Service Fabric
Alexander Laysha
 
Azure Service Fabric - weaving services in hyper-scale
Sebastian Gebski
 
Azure Service Fabric pour les développeurs
Microsoft
 
Using the Actor Model with Domain-Driven Design (DDD) in Reactive Systems - w...
Lightbend
 
Patterns & Practices of Microservices
Wesley Reisz
 
Service Fabric Overview (Yves Goeleven)
Visug
 
Docker + .NET Core Demos | Radu Vunvulea
Radu Vunvulea
 
Graph Database workshop
Jeremy Deane
 
Massively Scaleable .NET Web Services with Project Orleans
Newman Hunter
 
Patterns & Practices for Cloud-based Microservices
C4Media
 
.NET Security (Radu Vunvulea)
Radu Vunvulea
 
Empower your raspberry pi using Azure IoT suite, Radu Vunvulea
Radu Vunvulea
 
Implement API Gateway using Azure API Management
Alexander Laysha
 
What new in asp.net mvc, 5 visual studio 2015 and web tooling, radu vunvulea,...
Radu Vunvulea
 
08 hopex v next service fabric
Michel Bruchet
 
Project Orleans - Actor Model framework
Neil Mackenzie
 
NS study8 DDD Microservices Azuer Service Fabric
貴志 上坂
 
From a monolith to microservices with Azure Service Fabric
Stéphane ERBRECH
 
Developing Applications with a Micro Service Architecture - Chris Richardson
JAXLondon2014
 
Миграция в Azure Service Fabric
Alexander Laysha
 
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...
MSDEVMTL
 
PPSX
Moderne backends mit dem aktor programmiermodell
Damir Dobric
 
PPTX
Discovering the Service Fabric's actor model
Massimo Bonanni
 
PPTX
Azure service fabric
Fernando Mejía
 
PPTX
Azure Service Fabric: notes from the field (Sam Vanhoute @Integrate 2016)
Codit
 
PPTX
Service fabric overview
Himanshu Desai
 
PPTX
Discovering the Service Fabric's actor model
Massimo Bonanni
 
PPTX
Developing Actors in Azure with .net
Marco Parenzan
 
PPTX
Azure Service Fabric: The road ahead for microservices
Microsoft Tech Community
 
PPTX
Pieter de Bruin (Microsoft) - Welke technologie gebruiken bij implementatie M...
AFAS Software
 
PPTX
Azure service fabric overview
Baskar rao Dsn
 
PPTX
Testing a Service Fabric solution and live happy!!
Massimo Bonanni
 
PPTX
Azure Microservices in Practice, Radu Vunvulea, ITCamp 2016
Radu Vunvulea
 
PPTX
Serhiy Kalinets "Embracing architectural challenges in the modern .NET world"
Fwdays
 
PDF
Introducing Akka
Jonas Bonér
 
PDF
Introducingakkajavazone2012 120914094033-phpapp02
Typesafe
 
PDF
Microsoft: Building a Massively Scalable System with DataStax and Microsoft's...
DataStax Academy
 
PPTX
ServiceFabric-Arch
Saravanan G
 
PPTX
Cooking Akka.net and Azure Service Fabric together
Alessandro Melchiori
 
PPTX
Designing distributed systems
Malisa Ncube
 
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
MSDEVMTL
 
Moderne backends mit dem aktor programmiermodell
Damir Dobric
 
Discovering the Service Fabric's actor model
Massimo Bonanni
 
Azure service fabric
Fernando Mejía
 
Azure Service Fabric: notes from the field (Sam Vanhoute @Integrate 2016)
Codit
 
Service fabric overview
Himanshu Desai
 
Discovering the Service Fabric's actor model
Massimo Bonanni
 
Developing Actors in Azure with .net
Marco Parenzan
 
Azure Service Fabric: The road ahead for microservices
Microsoft Tech Community
 
Pieter de Bruin (Microsoft) - Welke technologie gebruiken bij implementatie M...
AFAS Software
 
Azure service fabric overview
Baskar rao Dsn
 
Testing a Service Fabric solution and live happy!!
Massimo Bonanni
 
Azure Microservices in Practice, Radu Vunvulea, ITCamp 2016
Radu Vunvulea
 
Serhiy Kalinets "Embracing architectural challenges in the modern .NET world"
Fwdays
 
Introducing Akka
Jonas Bonér
 
Introducingakkajavazone2012 120914094033-phpapp02
Typesafe
 
Microsoft: Building a Massively Scalable System with DataStax and Microsoft's...
DataStax Academy
 
ServiceFabric-Arch
Saravanan G
 
Cooking Akka.net and Azure Service Fabric together
Alessandro Melchiori
 
Designing distributed systems
Malisa Ncube
 
Ad

More from João Pedro Martins (7)

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

Recently uploaded (20)

PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
Python basic programing language for automation
DanialHabibi2
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
July Patch Tuesday
Ivanti
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 

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 [email protected] 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)