shortlyportly

shortlyportly

Hello.

I’m currently reading the beta version of Functional Web Development with OTP and Phoenix and I love the way that the book uses OTP to store state (using Agents and GenServer). I’m thinking about how I could use this technique in my next project but also thinking about failure and recovery (which isn’t in the book yet as it hasn’t been written :smile:)

As an example of the approach I’m thinking of - assume I have an Order which I’d like to model using a process BUT also when details of the order change I’d also want to persist to the database. If one of the attributes I persist to the database is the PID of the process that models the order then IF that process crashes the Supervisor for that process can simply read the last state from the database and recreate the process.

Does this make sense or am I overcomplicating my design. I appreciate that you shouldn’t over-use processes and that the standard way would be to simply use the database for everything but I’m intrigued by the use of process to model state.

I’d love to hear people’s views on the above approach.

many thanks (and have a great day).

Dave

Showing Posts 1 to 9

idi527

idi527

Might not be particularly relevant but have you seen this talk https://www.youtube.com/watch?v=fkDhU-2NWJ8? I remember them using something similar to the approach you are describing.

shortlyportly

shortlyportly OP

I did watch that that talk which is what got me thinking about this issue in the first place. Then I came across the Functional Web Development book and that REALLY got me thinking :smile:

It seems I’m not the only one as there is this thread that I’ve just come across…

I guess my question is more about IF I did follow this approach would the “store PID” approach be a reasonable one.

cheers

Dave

idi527

idi527

I don’t know. I would probably store the last good state of the crashed process in a ets table (in terminate callback if it’s a genserver) and have the supervisor read it from there.

shortlyportly

shortlyportly OP

Thanks for the suggestion. I thought ETS tables “disappeared” when the associated process died or am I completely wrong?

idi527

idi527

You are right. But I would suggest the ets table keeping the state of the crashed process to not be associated with the process itself, but with its supervisor or maybe even with a completely separate process.

kwando

kwando

I would use a :unique Elixir Registry for keeping track of my entities based on their ID.
This way I don’t have to juggle PIDs around.

I would not store the PID into the database, only the ID and state of the entity.

OvermindDL1

OvermindDL1

Only if there is no heir process. You can tell ets that when its parent table dies then pass it to its heir process, which gets a message alerting them (so that they can re-create its sibling and give it ets back to repeat the process again for example).

shortlyportly

shortlyportly OP

Thanks kwando - I didn’t think about Elixir Registry - great idea.

shortlyportly

shortlyportly OP

Ah thank you OvermindDL1.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews