TheMaikXX

TheMaikXX

Application design help needed (how to make use of genservers and ErlangVM processes)

Hello,
I’m making a demo app for bidding. It is a POC for channels and now I decided to try to persist data using Mnesia. First thing is that I’m struggling with decision whether to use Amnesia wrapper or Mnesia directly… (but thats off-topic)
The main thing is that before the idea of persisting data I designed the app so that each item that yet to be/is auctioned should rest in dedicated GenServer and users (via websockets) will place_bids from channels by issuing message to dedicated GenServer for given auction item. I thought this solution might be a good idea to leverage the parallelism of ErlangVM. But now with Mnesia I feel like I dont need individual GenServers because I can directly access Mnesia data… Am I correct? I also thought of preserving the idea of individual GenServers that would keep the state of the auction item but would periodically/by debounce “flush” the state to Mnesia… (but that would probably open space for potential loss of unsaved data) Is that dumb idea?
Or would any other approach fit here better?

Thanks in advance!

Marked As Solved

hauleth

hauleth

Parallelism of ERTS is accidental, not main concept of the Erlang. Concurrency is the main concept, and these two are quite different.

You are correct.

From my viewpoint - yes. What will happen if the process go down between the debounce period? You will lose some bids.

My approach to that would be as a stream of events - you place bid, it is saved right away, and then when someone overbids you then you will get a message. Additionally I wouldn’t use Mnesia there (unless that is requirement). While this DB is built in, its maintenance isn’t quite obvious and can be confusing for developers that aren’t familiar with Erlang and its quirks. I would go for PostgreSQL (or SQLite if it is meant to be super simple and hosted on one machine only), as it is more familiar for most of the people.

So in general, I wouldn’t use GenServer there, as in this application it doesn’t really makes much sense (unless I am missing something important there).

Where Next?

Popular in Questions Top

LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
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
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
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
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
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
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
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

We're in Beta

About us Mission Statement