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

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
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
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
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
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New

Other popular topics Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
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
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
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
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
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

Latest on Elixir Forum

We're in Beta

About us Mission Statement