Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distributed Caching in Elixir

I am writing an Elixir app that requires a registry to store the mapping of which pid belongs to which user. I will have an GenServer per user in the app that will be supervised. I have the basic example working with one node using ETS but with 2+ nodes, I can't use ETS since it does not support clustering/replication. What are some other options for having a distributed cache? From doing some research, my options are using Database such as Redis or use Amensia.

like image 300
ed1t Avatar asked Oct 18 '22 13:10

ed1t


1 Answers

Assuming you don't want duplicates across your cluster, you could simply register each GenServer globally.

GenServer.start_link(__MODULE__, args, [name: {:global, user_id}]

Then you can simply lookup :global.whereis_name(user_id) to get the pid. If the process dies, it's automatically unregistered. Here's the documentation for Erlang's global module.

like image 88
Cody Poll Avatar answered Oct 21 '22 06:10

Cody Poll