Search code examples
.netorleansdata-persistence

Data Persistence in Microsoft Orleans


I'm new in Microsoft Orleans and when reading the documentation I found this :

... Grain persistence uses an extensible plugin model so that storage providers for any database can be used. This persistence model is designed for simplicity and is not intended to cover all data access patterns. Grains can also access databases directly, without using the grain persistence model. here

But in the rest of the documentation, is only described means to use Storage Providers for grain persistence. But with these providers I'm still wondering how to perform complex requests as in relational databases (with JOIN, GROUP BY, ORDER BY etc..).

So my concern is the following :

What could be the advantages and the disadvantages of using direct access to a relational database for Grain persistence?


Solution

  • Orleans is not opinionated on how you store your data: do what's right for your application. In response to your question, here are some advantages and disadvantages of taking the manual route and interfacing directly with a database instead of using the out-of-the-box persistence model.

    Advantages:

    • Precise control over when and how data is accessed, including how it is serialized
    • Ability to perform queries over your data

    Disadvantages:

    • Less automated - you become responsible for ensuring that your grain reads the data that it needs (grain persistence performs a read during activation)
    • You become responsible for managing connection pools, storage calls, etc
    • No automatic concurrency control - it is up to the developer to prevent concurrent access from resulting in data being incorrectly overwritten. The grain persistance providers typically use ETag checks to ensure consistency, so you can implement a similar scheme when doing this manually.

    Those advantages can be compelling, depending on your needs.

    You can also take a hybrid approach and write a custom storage provider which gives you some control over how your data is stored, and because you control that, you can then also access the database directly to perform queries.