sc4224

sc4224

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

Showing Posts 1 to 7

kodepett

kodepett

It’s advisable to start with an elixir option before considering alternatives. If you don’t get the expected performance from Agents or ETS, then you can try other options.

sc4224

sc4224 OP

@kodepett on that note, why would we use ets over agents?

kokolegorille

kokolegorille

ETS is just much faster

kodepett

kodepett

Agent is basically a GenServer; due to this, concurrent calls are serialized, ETS implementation is quite different allowing concurrent read and write

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

sc4224

sc4224 OP

so which one is the best for storing user sessions

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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
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
kszambelanczyk
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
RemyXRenard
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
velrest
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
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
nseaSeb
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

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews