josefrichter
I have a simple todo app where users can create and share various todo lists (this thread). It’s a phoenix live view app with default ecto/postgress right now.
I am thinking of using Mnesia mainly for learning purposes, no other strong reasons. (Maybe also to avoid usual limits on free-tier postgres as a bonus.) I have some elementary questions:
- in postgres I’m storing all todos in single table and retreive them with select/where list_id (even though I have no lists table at all). in mnesia I am thinking of simply creating separate table for each todo list - does that even make sense and does it bring some additional benefits like loading to RAM only the currently used tables?
- every now and then I want to run a task that deletes old unused todo lists (i.e. mnesia tables in my intended schema) - does the mnesia table have some timestamps by default, based on which I could delete it, or do I need to take care of that separately?
- does mnesia have some autoincrement unique id, or do I need to handle it myself? I’ve noticed Amnesia wrapper takes care of that, but I’m thinking of going wrapper-free for those learning purposes… And don’t see that in mnesia docs
- can I mix different structures in same table? I.e. I would have todos with ids 1.2,3… but then maybe :created_at key with timestamp and :table_owner with user info - then to show just todos I’d do probably some pattern matching, does that make sense and does it work?
Thank you very much
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
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
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
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 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
josefrichter
I try to start answering my own questions, I have some partial answers, but there are gaps and not sure if my answers are correct, so I’m hoping for advice from someone more experienced, please:
I probably can’t mix different structures in the same table, as I define attributes in
create_table, so that’s pretty much the same as sql databases. I would probably create another table “lists” where I’d store also the owner and timestamp – so this would be basically the same as in postgresgeneric autoincrement id - not sure how to do that, but I’d probably work around that with some pseudo-unique randomized uid, or I might use a timestamp as id – is there actually a reason why a timestamp is not commonly used as id, when probably the most common way of ordering records is by time created/updated?
the cleanup task should be fairly easy if I do the schema as outlined in the first bullet..
lists as separate tables - I don’t know if there’s a benefit? for example I definitely wouldn’t do it in postgres, doesn’t make sense having a number of tables with same schema. but does it make sense in mnesia? There’s really no relation between individual todo lists, so it just feels kinda natural. (in a way I think of the lists as completely independent documents, kind of mongodb-style). so it feels like while in postgres it would be unnecessary pain to keep each list in separate table, in mnesia it would be unnecessary pain to keep them in one table… can someone shed some light to my gut feelings here, please?
Exadra37
I am also building Todo app with Mnesia, no Postgres at all from day 1.
If you have not read yet I would recommend you to read the excellent resource Mnesia and the Art of Remembering.
You can also take a look to Why isn’t mnesia the most preferred database for use in Elixir/Phoenix? - #20 by Exadra37 where you will see an interesting discussion and a summary of this video:
I know you said that you prefer to use Mnesia directly for learning purposes, but if at any time you decided to switch to use a wrapper, then you have:
Qqwy
I can at least answer that: Using ‘just’ a timestamp caps you to a certain number of maximum inserts per second, and requires you to pay good attention to your clock. However, there certainly are common approaches to create timestamp-base IDs. A common one is the Snowflake ID, for which there exists an Elixir implementation.
As to when it makes sense to use UUIDs vs auto-incrementing IDs: personally I agree with the arguments of this blog post that boil down to UUIDs are larger than traditional SQL auto-increment ID fields, but they have several benefits such as better scalability, they still work in a distributed setting, you can move to a different underlying database without having to create new ids, etc.
Yes and no. You cannot vary what fields exist in a Mnesia table. You can however vary what data is stored inside, and this data might be any Erlang/Elixir term including (nested) lists, maps (including structs), tuples, etc. This gives you flexibility to store varying data in a certain field.
The main disadvantage of storing denormalized data is that you cannot (at least not easily) query this data. Depending on what you want to store vs. what you want to search on, this is usually not a problem.
I’d say: start with the simplest thing that works and only make it more complex if you hit against its limits.
Exadra37
Memento wrapper for Mnesia does auto increment in ordered sets only, see it here:
In my Todo app I am using a unique id, that is an hash of a field in the changeset. Yes I am using Ecto Changesets with Mnesia
josefrichter
I generally follow this advice. In this case there’s zero technical need to replace existing postgres solution, it’s purely for my educational purposes
Re using timestamps as IDs - I understand your point, it kinda goes against the idea of highly-concurrent real-time systems where everything happens “at the same time”, so going for timestamps as unique IDs is kinda stupid
Re yes and no with mixed data in the same table - I think I understand in principle. So one case would be to have table with attributes key, payload, and maybe record_type where payload could be a map for some records and list for others, etc. The other I can think of is having something like this:
It’s a bit hacky, but should be easy to match and iterate, and maybe makes sense in some scenarios where you really need the in-memory speed of mnesia.