Azure Service Fabric
...a gentle introduction
Alessandro Melchiori
Solution architect @ Particular Software
alessandro [dot] melchiori [at] particular [dot] net
twitter: @amelchiori
blog: http://melkio.codiceplastico.com
github: http://github.com/melkio
Alessandro Melchiori
• Why Service Fabric?
• Service Fabric overview
• What is a microservice?
 Actor model
 Stateless and Stateful
• Monitoring
 Service Fabric Explorer
• Upgrade application
Agenda
Why Service Fabric?
Where Service Fabric?
Why Service Fabric?
Why Service Fabric?
Service Fabric Architecture
Service Fabric architecture: cluster
• Cluster is a federation of machines
• Cluster can scale to 1000s of
machines
Service Fabric architecture: replication system
P
S S
S S
• Replica states
 None
 Idle secondary
 Active secondary
 Primary
Service Fabric architecture: replication system
P
S S
S S
• Reads are completed at the
primary
Service Fabric architecture: replication system
P
S S
S S
• Writes are replicated to the write
quorum of secondaries
Service Fabric architecture: replication system
P
S S
S S
• Writes are replicated to the write
quorum of secondaries
Service Fabric architecture: replication system
P
S S
S S
• Writes are replicated to the write
quorum of secondaries
Service Fabric architecture: replication system
P
S S
S S
• Writes are replicated to the write
quorum of secondaries
Service Fabric architecture: replication system
P
S S
S S
• Writes are replicated to the write
quorum of secondaries
Service Fabric architecture: replication system
P
S S
S S
• Writes are replicated to the write
quorum of secondaries
Service Fabric architecture: replication system reconfig
P
S S
S S
• Types of reconfiguration
 Primary failover
 Removing a failed secondary
 Adding recovered replica
 Building new secondary
Service Fabric architecture: replication system reconfig
P
S S
S S
• Types of reconfiguration
 Primary failover
 Removing a failed secondary
 Adding recovered replica
 Building new secondary
Service Fabric architecture: replication system reconfig
S P
S S
• Types of reconfiguration
 Primary failover
 Removing a failed secondary
 Adding recovered replica
 Building new secondary
Service Fabric architecture: replication system reconfig
S P
S S
• Types of reconfiguration
 Primary failover
 Removing a failed secondary
 Adding recovered replica
 Building new secondary
Service Fabric architecture: replication system reconfig
S P
S S
• Types of reconfiguration
 Primary failover
 Removing a failed secondary
 Adding recovered replica
 Building new secondary
Service Fabric architecture: replication system reconfig
P
S S
• Types of reconfiguration
 Primary failover
 Removing a failed secondary
 Adding recovered replica
 Building new secondary
Service Fabric architecture: replication system reconfig
P
P
S S
• Types of reconfiguration
 Primary failover
 Removing a failed secondary
 Adding recovered replica
 Building new secondary
Service Fabric architecture: replication system reconfig
S
P
S S
• Types of reconfiguration
 Primary failover
 Removing a failed secondary
 Adding recovered replica
 Building new secondary
Service Fabric architecture: replication system reconfig
S
P
S S
• Types of reconfiguration
 Primary failover
 Removing a failed secondary
 Adding recovered replica
 Building new secondary
Service Fabric architecture: replication system reconfig
S
P
S S
• Types of reconfiguration
 Primary failover
 Removing a failed secondary
 Adding recovered replica
 Building new secondary
B
Service Fabric architecture: replication system reconfig
S
S P
S S
• Types of reconfiguration
 Primary failover
 Removing a failed secondary
 Adding recovered replica
 Building new secondary
Service Fabric architecture: partitioning
• Allow data/computation to be spread across nodes
• A partition must fit in 1 node / 1 node can hold multiple partitions
• Cross-partitions operations requires network hops and different transactions
• SF balances partitions across nodes
Service Fabric architecture: partitioning
Service Fabric architecture: partitioning
Service Fabric application model
Service Fabric application model
DEMO
run your local cluster
• Encapsulate a business scenario
• Can be written in any programming language
• Consist of code and (optionally) state that is independently versioned, deployed
and scaled
• Has a unique name, used to resolve its location
• Remains consistent and available in the presence of failure
• Interacts with other microservices
What is a microservice?
The actor model in computer science is a mathematical model of
concurrent computation that treats "actors" as the universal primitives of
concurrent computation: in response to a message that it receives, an
actor can make local decisions, create more actors, send more
messages, and determine how to respond to the next message received
https://en.wikipedia.org/wiki/Actor_model
Actor model
The actor model in computer science is a mathematical model of
concurrent computation that treats "actors" as the universal primitives of
concurrent computation: in response to a message that it receives, an
actor can make local decisions, create more actors, send more
messages, and determine how to respond to the next message received
https://en.wikipedia.org/wiki/Actor_model
Actor model
Actor model
Actor model
• Actors are isolated, single-threaded components that encapsulate both state and
behavior
• Each such actor is uniquely identified by an actor ID
• Actors interact with rest of the system, including other actors, by passing
asynchronous messages using a request-response pattern
Service Fabric Reliable Actors API
public interface ICalculatorActor : IActor
{
Task Increment();
Task<Int32> GetValue();
}
Stateless actor: definition
public interface ICalculatorActor : IActor
{
Task Increment();
Task<Int32> GetValue();
}
Stateless actor: definition
public interface ICalculatorActor : IActor
{
Task Increment();
Task<Int32> GetValue();
}
Stateless actor: definition
public interface ICalculatorActor : IActor
{
Task Increment();
Task<Int32> GetValue();
}
public class CalculatorActor : StatelessActor, ICalculatorActor
{
...
}
Stateless actor: definition
public interface ICalculatorActor : IActor
{
Task Increment();
Task<Int32> GetValue();
}
public class CalculatorActor : StatelessActor, ICalculatorActor
{
...
}
Stateless actor: definition
public interface ICalculatorActor : IActor
{
Task Increment();
Task<Int32> GetValue();
}
Stateful actor: definition
public interface ICalculatorActor : IActor
{
Task Increment();
Task<Int32> GetValue();
}
public class CalculatorActor : StatefulActor<ActorState>,
ICalculatorActor
{
...
}
Stateful actor: definition
public interface ICalculatorActor : IActor
{
Task Increment();
Task<Int32> GetValue();
}
public class CalculatorActor : StatefulActor<ActorState>,
ICalculatorActor
{
...
}
Stateless actor: definition
var actorId = ActorId.NewId();
var applicationName = "fabric:/CalculatorActorApp";
var actor = ActorProxy.Create<ICalculatorActor>(actorId,
applicationName)
Actor communication: the actor proxy
var actorId = ActorId.NewId();
var applicationName = "fabric:/CalculatorActorApp";
var actor = ActorProxy.Create<ICalculatorActor>(actorId,
applicationName)
Actor communication: the actor proxy
DEMO
stateless actor vs stateful actor
Upgrade application (with zero downtime)
Upgrade application (with zero downtime)
Upgrade application (with zero downtime)
Upgrade application (with zero downtime)
DEMO
upgrade application
Free e-book available at:
http://go.particular.net/Liguria
Curiosi?

Azure service fabric: a gentle introduction

  • 1.
    Azure Service Fabric ...agentle introduction Alessandro Melchiori
  • 2.
    Solution architect @Particular Software alessandro [dot] melchiori [at] particular [dot] net twitter: @amelchiori blog: http://melkio.codiceplastico.com github: http://github.com/melkio Alessandro Melchiori
  • 3.
    • Why ServiceFabric? • Service Fabric overview • What is a microservice?  Actor model  Stateless and Stateful • Monitoring  Service Fabric Explorer • Upgrade application Agenda
  • 4.
  • 5.
  • 7.
  • 8.
  • 9.
  • 10.
    Service Fabric architecture:cluster • Cluster is a federation of machines • Cluster can scale to 1000s of machines
  • 11.
    Service Fabric architecture:replication system P S S S S • Replica states  None  Idle secondary  Active secondary  Primary
  • 12.
    Service Fabric architecture:replication system P S S S S • Reads are completed at the primary
  • 13.
    Service Fabric architecture:replication system P S S S S • Writes are replicated to the write quorum of secondaries
  • 14.
    Service Fabric architecture:replication system P S S S S • Writes are replicated to the write quorum of secondaries
  • 15.
    Service Fabric architecture:replication system P S S S S • Writes are replicated to the write quorum of secondaries
  • 16.
    Service Fabric architecture:replication system P S S S S • Writes are replicated to the write quorum of secondaries
  • 17.
    Service Fabric architecture:replication system P S S S S • Writes are replicated to the write quorum of secondaries
  • 18.
    Service Fabric architecture:replication system P S S S S • Writes are replicated to the write quorum of secondaries
  • 19.
    Service Fabric architecture:replication system reconfig P S S S S • Types of reconfiguration  Primary failover  Removing a failed secondary  Adding recovered replica  Building new secondary
  • 20.
    Service Fabric architecture:replication system reconfig P S S S S • Types of reconfiguration  Primary failover  Removing a failed secondary  Adding recovered replica  Building new secondary
  • 21.
    Service Fabric architecture:replication system reconfig S P S S • Types of reconfiguration  Primary failover  Removing a failed secondary  Adding recovered replica  Building new secondary
  • 22.
    Service Fabric architecture:replication system reconfig S P S S • Types of reconfiguration  Primary failover  Removing a failed secondary  Adding recovered replica  Building new secondary
  • 23.
    Service Fabric architecture:replication system reconfig S P S S • Types of reconfiguration  Primary failover  Removing a failed secondary  Adding recovered replica  Building new secondary
  • 24.
    Service Fabric architecture:replication system reconfig P S S • Types of reconfiguration  Primary failover  Removing a failed secondary  Adding recovered replica  Building new secondary
  • 25.
    Service Fabric architecture:replication system reconfig P P S S • Types of reconfiguration  Primary failover  Removing a failed secondary  Adding recovered replica  Building new secondary
  • 26.
    Service Fabric architecture:replication system reconfig S P S S • Types of reconfiguration  Primary failover  Removing a failed secondary  Adding recovered replica  Building new secondary
  • 27.
    Service Fabric architecture:replication system reconfig S P S S • Types of reconfiguration  Primary failover  Removing a failed secondary  Adding recovered replica  Building new secondary
  • 28.
    Service Fabric architecture:replication system reconfig S P S S • Types of reconfiguration  Primary failover  Removing a failed secondary  Adding recovered replica  Building new secondary B
  • 29.
    Service Fabric architecture:replication system reconfig S S P S S • Types of reconfiguration  Primary failover  Removing a failed secondary  Adding recovered replica  Building new secondary
  • 30.
    Service Fabric architecture:partitioning • Allow data/computation to be spread across nodes • A partition must fit in 1 node / 1 node can hold multiple partitions • Cross-partitions operations requires network hops and different transactions • SF balances partitions across nodes
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
    • Encapsulate abusiness scenario • Can be written in any programming language • Consist of code and (optionally) state that is independently versioned, deployed and scaled • Has a unique name, used to resolve its location • Remains consistent and available in the presence of failure • Interacts with other microservices What is a microservice?
  • 37.
    The actor modelin computer science is a mathematical model of concurrent computation that treats "actors" as the universal primitives of concurrent computation: in response to a message that it receives, an actor can make local decisions, create more actors, send more messages, and determine how to respond to the next message received https://en.wikipedia.org/wiki/Actor_model Actor model
  • 38.
    The actor modelin computer science is a mathematical model of concurrent computation that treats "actors" as the universal primitives of concurrent computation: in response to a message that it receives, an actor can make local decisions, create more actors, send more messages, and determine how to respond to the next message received https://en.wikipedia.org/wiki/Actor_model Actor model
  • 39.
  • 40.
  • 41.
    • Actors areisolated, single-threaded components that encapsulate both state and behavior • Each such actor is uniquely identified by an actor ID • Actors interact with rest of the system, including other actors, by passing asynchronous messages using a request-response pattern Service Fabric Reliable Actors API
  • 42.
    public interface ICalculatorActor: IActor { Task Increment(); Task<Int32> GetValue(); } Stateless actor: definition
  • 43.
    public interface ICalculatorActor: IActor { Task Increment(); Task<Int32> GetValue(); } Stateless actor: definition
  • 44.
    public interface ICalculatorActor: IActor { Task Increment(); Task<Int32> GetValue(); } Stateless actor: definition
  • 45.
    public interface ICalculatorActor: IActor { Task Increment(); Task<Int32> GetValue(); } public class CalculatorActor : StatelessActor, ICalculatorActor { ... } Stateless actor: definition
  • 46.
    public interface ICalculatorActor: IActor { Task Increment(); Task<Int32> GetValue(); } public class CalculatorActor : StatelessActor, ICalculatorActor { ... } Stateless actor: definition
  • 47.
    public interface ICalculatorActor: IActor { Task Increment(); Task<Int32> GetValue(); } Stateful actor: definition
  • 48.
    public interface ICalculatorActor: IActor { Task Increment(); Task<Int32> GetValue(); } public class CalculatorActor : StatefulActor<ActorState>, ICalculatorActor { ... } Stateful actor: definition
  • 49.
    public interface ICalculatorActor: IActor { Task Increment(); Task<Int32> GetValue(); } public class CalculatorActor : StatefulActor<ActorState>, ICalculatorActor { ... } Stateless actor: definition
  • 50.
    var actorId =ActorId.NewId(); var applicationName = "fabric:/CalculatorActorApp"; var actor = ActorProxy.Create<ICalculatorActor>(actorId, applicationName) Actor communication: the actor proxy
  • 51.
    var actorId =ActorId.NewId(); var applicationName = "fabric:/CalculatorActorApp"; var actor = ActorProxy.Create<ICalculatorActor>(actorId, applicationName) Actor communication: the actor proxy
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
    Free e-book availableat: http://go.particular.net/Liguria Curiosi?