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:
- I am using the counter in GitHub - dwyl/phoenix-liveview-counter-tutorial: 🤯 beginners tutorial building a real time counter in Phoenix 1.7.14 + LiveView 1.0 ⚡️ Learn the fundamentals from first principals so you can make something amazing! 🚀 · GitHub as a basis.
- I’ve substituted the backend for a Durable Server.
There are some things that I would love to check that they are true:
- I am calling DurableServer.Superviror lookup before I call GenServer.
- 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.
- 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.
- 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
What you are building is way more complex than just using a database.
Use the right tools for the job.
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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








