Make your systems distributed, replicated, scaled well, easily.
This is an example of a replicated GenServer.
defmoduleStorage.KVdouseGenServerdefstart_link()doGenServer.start_link(__MODULE__,[initial_state: %{}],name: __MODULE__.process_id())enddefinit(opts\\[])do{:ok,Keyword.get(opts,:initial_state,%{})}enddefprocess_id()doStorage.KVenddefhandle_cast({:set,key,value},state)do{:noreply,Map.put(state,key,value)}enddefhandle_call({:get,key,default},_from,state)do{:reply,Map.get(state,key,default),state}enddefhandle_call({:has,key},_from,state)do{:reply,Map.has_key?(state,key),state}enddefhandle_call({:pop,key,default},_from,state)do{value,new_state}=Map.pop(state,key,default){:reply,value,new_state}enddefget(key,default\\nil)doDistributed.Scaler.GenServer.call(__MODULE__.process_id(),{:get,key,default})enddefset(key,value)do{_node_name,result}=Distributed.Replicator.GenServer.cast(__MODULE__.process_id(),{:set,key,value})|>List.first()resultenddefhas?(key)doDistributed.Scaler.GenServer.call(__MODULE__.process_id(),{:has,key})enddefpop(key,default\\nil)do{_node_name,result}=Distributed.Replicator.GenServer.call(__MODULE__.process_id(),{:pop,key,default})|>List.first()resultendendYou can see the example as a small project on ertgl/storage repository.
If you have Hex, the package can be installed
by adding :distributed to your list of dependencies in mix.exs:
defapplicationdo[extra_applications: [:distributed,],]enddefdepsdo[{:distributed,"~> 0.1.3"},]end