Drinking
from the
Firehose
With Virtual Streams & Virtual Actors
Sergey Bykov
Microsoft, @sergeybykov
Event Streaming
Compute
Storage
Typical Workloads
User X
Event
User X
State
Updated
User X
State
User X
Event
User X
Event
Processing an Event
Challenges
Y X X Z X Z Y Z
C A C B B B A C
D E F F DD D E
B A C E F D Z A
Z X X Z X Z Y X
A A B C C C B A
E D E F F F E D
A Y Z C F D B A
Storage
High volume of events
▪Need multiple servers
Each event requires context
▪Load state from storage
▪Write results to storage
Uncoordinated IO is expensive
▪Caching
▪Write conflicts
Servers may go down
▪Clustering / coordination needed
User X
Event
User X
Event
Processing an Event
User X
Event
User X
State
Updated
User X
State
User X
Event
User X
State
Updated
User X
State
Benefits of Single Processor
User X
Event
User X
Event
User Y
Event
User Y
Event
User Y
Event
User Z
Event
User Z
Event
User Z
Event
Orleans Architecture
Frontends Orleans Cluster Storage
Grain
Persisted
Activating
Active
in memory
Deactivating
Challenges
Y X X Z X Z Y Z
C A C B B B A C
D E F F DD D E
B A C E F D Z A
Z X X Z X Z Y X
A A B C C C B A
E D E F F F E D
A Y Z C F D B A
Storage
High volume of events
▪Need multiple servers
Each event requires context
▪Load state from storage
▪Write results to storage
Uncoordinated IO is expensive
▪Caching
▪Write conflicts
Servers may go down
▪Clustering / coordination needed
PA PA PA PA
Messaging
Cluster Membership
Grain Directory
PA PA PA PA
Messaging
Cluster Membership
Grain Directory
Pulling Agents
Y X X Z X Z Y Z
C A C B B B A C
D E F F DD D E
B A C E F D Z A
Z X X Z X Z Y X
A A B C C C B A
E D E F F F E D
A Y Z C F D B A
Virtual Streams
A A A A A A A A
B B B B B B B B
C C C C C C C C
A A A A A A A A
B B B B B B B B
C C C C C C C C
A B B C B C A A A B B C A B B B C A A C A B B A
DD E F E E D F D E F F DD E E F F E F D E DD
X Y Y Z Y Z X X X Y Y Z X Y Y Y Z X X Z X Y Y X
A
B
C
D
D
Logical (Virtual) Streams
1000s to Ms to Bs
Physical Persistent Queues
10s to 1000s
Programming Model
public class UserGrain : Grain, IAsyncObserver<GameEvent>
{
public async Task Initialize()
{
var provider = GetStreamProvider(“EventHub Provider”);
var stream = provider.GetStream<GameEvent>(userId, “PlayerEvents”);
await stream.Subscribe(this);
}
public async Task OnNext(GameEvent event)
{
// Processing logic
...
await AwardAchievement(Achievements.MasterChief);
}
...
public async Task AwardAchievement(Achievements achievement)
{
var stream = provider.GetStream<Achievements>(streamId, “Achievements”);
await stream.OnNext(achievement);
}
}
// Rx-like interface to implement
public interface IAsyncObserver<T>
{
Task OnNext(T event);
Task OnComplete();
Task OnError();
}
Event Streaming is a powerful paradigm
Routing events to affected entity’s state is much better
▪ Reduces read and write load on storage
▪ Can serve RPC calls from same in-memory state
Virtual Actors are natural fit for processing events
▪ Cluster objects with stable identities
▪ Automatic resource management
Virtual Streams provide a simple but powerful model
▪ Orleans code is open source (MIT license)
▪ Runs on Windows, Linux, MacOS (via .NET Core)
Takeaways
Muchas Gracias!
Sergey Bykov
Microsoft, @sergeybykov

Drinking from the firehose, with virtual streams and virtual actors

  • 1.
    Drinking from the Firehose With VirtualStreams & Virtual Actors Sergey Bykov Microsoft, @sergeybykov
  • 3.
  • 4.
  • 5.
    User X Event User X State Updated UserX State User X Event User X Event Processing an Event
  • 6.
    Challenges Y X XZ X Z Y Z C A C B B B A C D E F F DD D E B A C E F D Z A Z X X Z X Z Y X A A B C C C B A E D E F F F E D A Y Z C F D B A Storage High volume of events ▪Need multiple servers Each event requires context ▪Load state from storage ▪Write results to storage Uncoordinated IO is expensive ▪Caching ▪Write conflicts Servers may go down ▪Clustering / coordination needed
  • 7.
    User X Event User X Event Processingan Event User X Event User X State Updated User X State
  • 8.
    User X Event User X State Updated UserX State Benefits of Single Processor User X Event User X Event User Y Event User Y Event User Y Event User Z Event User Z Event User Z Event
  • 9.
    Orleans Architecture Frontends OrleansCluster Storage Grain Persisted Activating Active in memory Deactivating
  • 10.
    Challenges Y X XZ X Z Y Z C A C B B B A C D E F F DD D E B A C E F D Z A Z X X Z X Z Y X A A B C C C B A E D E F F F E D A Y Z C F D B A Storage High volume of events ▪Need multiple servers Each event requires context ▪Load state from storage ▪Write results to storage Uncoordinated IO is expensive ▪Caching ▪Write conflicts Servers may go down ▪Clustering / coordination needed
  • 11.
    PA PA PAPA Messaging Cluster Membership Grain Directory PA PA PA PA Messaging Cluster Membership Grain Directory Pulling Agents Y X X Z X Z Y Z C A C B B B A C D E F F DD D E B A C E F D Z A Z X X Z X Z Y X A A B C C C B A E D E F F F E D A Y Z C F D B A
  • 12.
    Virtual Streams A AA A A A A A B B B B B B B B C C C C C C C C A A A A A A A A B B B B B B B B C C C C C C C C A B B C B C A A A B B C A B B B C A A C A B B A DD E F E E D F D E F F DD E E F F E F D E DD X Y Y Z Y Z X X X Y Y Z X Y Y Y Z X X Z X Y Y X A B C D D Logical (Virtual) Streams 1000s to Ms to Bs Physical Persistent Queues 10s to 1000s
  • 13.
    Programming Model public classUserGrain : Grain, IAsyncObserver<GameEvent> { public async Task Initialize() { var provider = GetStreamProvider(“EventHub Provider”); var stream = provider.GetStream<GameEvent>(userId, “PlayerEvents”); await stream.Subscribe(this); } public async Task OnNext(GameEvent event) { // Processing logic ... await AwardAchievement(Achievements.MasterChief); } ... public async Task AwardAchievement(Achievements achievement) { var stream = provider.GetStream<Achievements>(streamId, “Achievements”); await stream.OnNext(achievement); } } // Rx-like interface to implement public interface IAsyncObserver<T> { Task OnNext(T event); Task OnComplete(); Task OnError(); }
  • 14.
    Event Streaming isa powerful paradigm Routing events to affected entity’s state is much better ▪ Reduces read and write load on storage ▪ Can serve RPC calls from same in-memory state Virtual Actors are natural fit for processing events ▪ Cluster objects with stable identities ▪ Automatic resource management Virtual Streams provide a simple but powerful model ▪ Orleans code is open source (MIT license) ▪ Runs on Windows, Linux, MacOS (via .NET Core) Takeaways
  • 16.