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

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews