sergio-ocon

sergio-ocon

Help with Durable Server counter demo as a first step

I have an idea to fully use DurableServer.

For a long time I had the idea of creating a management system using Phoenix, but there was some piece missing. I didn’t want to use a DB to maintain the state so I could get by with very low resource utilization and a simple infrastructure, but I also wanted to have HA and not lose the data when something breaks.

The idea of using Durable Server with EKV fits perfectly. I can have a single node management system that stores the data in EKV, and I can the expand to a dual active/passive node (using EKV observer mode to duplicate the data but manually changing the mode if I need to start a new server), or even 3-node cluster with HA.

Now I’ve started to explore if what I want is possible. I have created a DurableCounter application that will expand to cover what i need, and I would love some feedback on it:

There are some things that I would love to check that they are true:

  1. I am calling DurableServer.Superviror lookup before I call GenServer.
  2. I have two layers. The one to distribute the information, so you can have more than one browser and they will see the same counter, and another one that is the DurableCounterState. It feels right, but I am duplicating a lot of logic in both layers.
  3. I have configured the durable server with auto_sync: true. I tried without it but you could miss changes if you killed the server after a quick update.
  4. I have added a session_counter, that is a proxy for the transient metadata (i.e. the state of the managed node), but there a need for duplicated code when I convert the state to something digestible in the LiveView

I am happy with the result so far, but I would be very happy if you help me to get a cleaner solution, and make me feel confident that I am using it right.

My code is here:

Note: I will continue with the active/passive version next.

Most Liked

FlyingNoodle

FlyingNoodle

What you are building is way more complex than just using a database.

Use the right tools for the job.

sergio-ocon

sergio-ocon

I’ve used Claude to suggest some updates, and the code reflects that.

  • Now I share all the context for a key. This will allow me to have the metadata with different keys when I need to do so.
  • Added tests, including killing the server and restarting it so the session_counter is reset.

Now working on the HA for the server.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
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
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
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
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

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31265 143
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52673 488
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54120 245
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
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement