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
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










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.