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.