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
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
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.
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









