egze
Save state for handoff in postgres
I’m using horde for distributed supervision and registry. My current challenge is to implement state handoff. I want to avoid any external systems like redis and use the tools I already have: either the BEAM or Postgres.
I’m thinking to use postgres like a KV store and store the state as binary. https://medium.com/@kaisersly/storing-any-elixir-data-in-postgres-e8f93367f473
Is this a crazy idea, or I should use json instead of binary? Or not use Postgres at all?
Most Liked
tristan
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
dimitarvp
Having a Postgres table with just id and metadata field (jsonb Postgres type for maps) worked quite fine for me in the past.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








