egze

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

tristan

Rebar3 Core Team

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

dimitarvp

Having a Postgres table with just id and metadata field (jsonb Postgres type for maps) worked quite fine for me in the past.

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

We're in Beta

About us Mission Statement