budgie
Building something that uses realtime features with liveview. There’s state that’s managed and pushed to call participants. Right now I’m using Cachex but if I do a deploy while someone is in a call, all the state will be lost?
What’s the best way to have temporary in-memory storage that persists across restarts without resorting to an external service i.e. memcached or redis?
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
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
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
Got no answer for you at the moment but why are you using an ephemeral state that can be lost at any time (cache) as a source of truth / database?
budgie
It’s not a source of truth really. It’s for temporary call/session data that doesn’t really make sense to store after the call finishes.
Schultzer
Mnesia is the answer.
lud
Depends on how you deploy.
You can build a distributed cache that synchronizes agressively, and when you shut down a node to roll a new node, the stopping node stops accepting external input but will wait till all its currently processing cache items are synced on other nodes, and the new node will not start to accept input before being in sync with all other nodes.
k8s can help with that, but it’s probably a lot of pain to do properly.
Otherwise you can use PubSub : all cache writes go to pubsub and are distributed to all other nodes. When a new node start, it subscribes to pubsub without processing messages yet, it selects another node and gets a full copy of the cache to bootstrap the cache locally, and then processes incoming messages. Writes must be time-stamped to ignore old writes (aso because the node you are copying from is already listening to messages sent during the boostrap sequence and the new node will receive them too. If you start listening after copying the cache you will miss some messages.).
All of this looks hard to get right, are you sure you cannot use Redis?
nerdyworm
The route i would go is redis, memcached, or postgres. The alternatives are actually much more of a pain in comparison. They are quite fun though, so if your project needs a little pizzazz then read on.
If you are running more than one node:
GitHub - rabbitmq/khepri: Khepri is a tree-like replicated on-disk database library for Erlang and Elixir. · GitHub - raft replicated, happily syncs with all nodes, handles cluster restarts because it persists the data to disk. If the library’s tree style doesn’t suite your problem then you can use the raft library directly: GitHub - rabbitmq/ra: A Multi-Raft implementation for Erlang and Elixir that strives to be efficient and make it easier to use multiple Raft clusters in a single system. · GitHub There is a simple key/value store example in the docs.
The next option is mnesia. This option works well it you have like two nodes and are not doing rolling k8s style deploys. It’s easy to get started, but I put it in the more difficult to handle real world disaster issues. See rabbitmq’s docs/history/issues on how mnesia fails in production to give a better understanding of the… rabbit hole
Another option is to just dump your cache to disk or s3 storage before the machine stops and then restore it from disk/s3 when a new machine starts. Simple, but the down side is that you’ll eventually have some inconsistent data to deal with. I’d consider this route if your cache size is small.
It could also be possible to just use Phoenix.Presence — Phoenix v1.8.8 or Phoenix.Tracker — Phoenix.PubSub v2.1.3. Pretty sure if you do a rolling deploy you’ll be able to maintain any active cache state there… but you’d have to see if that works for your use case.
If you are running a single server or the caches don’t really need to be synced between two physically different nodes then sqlite may be a good fit for surviving restarts.
This is actually one of those, “elixir/erlang should make this problem simple”, but what happens is that elixir just fast forwards us to the realization that it’s very difficult problem with no on size fits all solution.
Let me know if this was helpful. I’m throwing a bunch of stuff at the wall to see what sticks.
Cheers,
Ben
budgie
@nerdyworm @lud
Yeah thanks for the reality check guys. I think redis is ultimately what I’ll go with. Love the idea of having them replicated cluster-internally but don’t want to have to add persistent block storage or a volume mount to the app containers. Keep Cachex for read-through queries to the DB probably.