sc4224

sc4224

Using Agents or redis to store user sessions

Hi I’m new to session storage in the backend. Would you store a session in an agent or something like redis?

Most Liked

akoutmos

akoutmos

Author of Build a Weather Station with Elixir and Nerves

Like most things in software it’s a matter of tradeoffs. With ETS you’ll get a considerable performance bump when reading sessions (you can also refer to Plug.Session.ETS — Plug v1.20.2) if many requests come in from the same user and reference the same agent. And you also won’t have to worry much about spawning too many processes and taking down the BEAM (Erlang -- Advanced).

On the other hand, when mutating data in ETS, you may come across some race conditions as data persisted to ETS will depend on what process writes last to it. In other words, if multiple requests come in from the same user and changes need to be made to their session data, the process that mutates ETS last will be the state of the session.

It sounds like if you’re just experimenting with things and learning, the ETS session Plug should work just fine. If you want further reading into ETS vs Agents/GenServers this is a good blog post: Optimizing Your Elixir and Phoenix projects with ETS - DockYard

Last Post!

kokolegorille

kokolegorille

There is Plug.Session to manage this…

It can be configured to use ETS or Cookies. Here is official documentation.

https://phoenixframework.org/blog/sessions

The recommended way is not to use ETS in production.

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

We're in Beta

About us Mission Statement