Code changes every week, stored data stays for years. And in a cluster, during every deploy, old and new silos run side by side for a few minutes and send each other messages. Both work out only if it is clear which changes to types are allowed and which are not.
From module 4.4 you know the rule for events: what is stored never changes, and new fields need a default value. This lesson carries the rule over to Orleans. In doing so you run into a surprise: Orleans serializes in two different ways, with two different sets of rules. In the end the Kladde has golden files of its stored state and a deliberate decision about which format it stores it in.
Two serializations
| Grain calls | Stored state | |
|---|---|---|
| What | arguments and return values of grain methods | State of IPersistentState<T> |
| How long it lives | milliseconds, until the response arrives | years |
| Who reads it | a silo of the same or the next version | every future version |
| Serializer | the Orleans serializer, binary, generated from [GenerateSerializer] |
an IGrainStorageSerializer, by default JSON with Newtonsoft.Json |
| What counts | the fields’ [Id] and the type’s [Alias] |
the names of the properties, and with the default the .NET name of the type |
The same class QuoteState from lesson 4.5.3 thus goes through two serializers, depending on whether Orleans is currently copying or storing it. The
attributes [Id] and [Alias] affect only the first.