Save state for handoff in postgres

Erleans, GitHub - erleans/erleans: Erlang Orleans · GitHub, also supports Postgres for state storage for stateful grains.

I use binary term for this in the 2 provided state backends:

https://github.com/erleans/erleans_provider_pgo

https://github.com/erleans/erleans_provider_ecto

But the providers themselves decide whether to use a binary term or something else like json (or protobuf, etc). There certainly could be advantages to json, like if you for some reason wanted to query the state of grains (your processes) in the postgres table, but I think term_to_binary suits most needs.

The only issue with term_to_binary is technically you could run into problems when moving between versions of OTP. And definitely would if records were used (but since you are in Elixir you don’t have that worry). Which is why Orleans suggests JSON https://dotnet.github.io/orleans/Documentation/grains/grain_persistence/index.html#recommendations