Microsoft Orleans is a cross-platform framework .NET developers can use to build scalable (from a single on-premise server, silos, or highly available cloud applications) and robust, distributed applications (applications spanning more than single processes).
In this developer tool tutorial, we discuss what Microsoft Orleans is, how it works, and its benefits to C# and .NET developers.
Read: Best Build Tools for C#
Overview of Microsoft Orleans
Microsoft Orleans provides a set of patterns and APIs that make the complexities of developing distributed applications a lot easier. With Microsoft Orleans (commonly known as Distributed.NET), programmers can switch to building scalable, cloud-native services. It can run on any .NET environment, including Windows, Linux, and macOS.
Microsoft Orleans is based on an actor model, where each actor in the model is a lightweight, concurrent, immutable object enveloping a state and its behavior. These actors communicate with each other via the use of asynchronous messages. Actors are simply logical objects called grains (more on this later) that exist virtually, thus making them always addressable, even on failures of executing servers. More information on actors can be found here.
Grains are objects that consist of user-defined identities (keys making grains available to be invoked by other grains), states, and behaviors, and are the building block of actors. Some interfaces that gets implemented by grains include:
- IGrainWithGuidKey: Grains with guid keys
- IGrainWithIntegerKey: Grains with Int64 keys
- IGrainWithStringkey: Grains with string keys
Read: Project Management Software for .NET Developers
What is Microsoft Orleans Used For?
Below are some of the use cases and situations Microsoft Orleans is used for:
- Grain placement
- Grain versioning
- Call filters
- Request context
- Distributed ACID transaction
Persistence ensures that the state is available before processing a request and ensures consistency. Grains can contain multiple data objects. During the running state of a grain, its state is held in memory for serving requests, thus preventing access to storage.
Timers are non-durable and are used for high-frequency events that do not require any reliability.
Reminders are simply durable scheduling mechanisms for grains. Reminders are used to ensure the actions are completed even if the grain is not activated.
Grain placement is completely configurable, where developers can decide between random, prefer-local, and load-based types. Because of this, grain placement is flexible in regards to deciding where grains are created.
Microsoft Orleans supports filters which include authorizations, telemetry, and error handling for both outgoing and incoming calls.
By using the request context, metadata can be passed to grains. The request context is mainly used to hold distributed tracing information, as well as, any user-defined values.
Distributed ACID Transactions
Grains can make use of ACID (Atomic, Consistent, Isolated, Durable) transactions. These transactions are distributed, decentralized, and have serializable isolation.