This project implements a distributed stock price listener system using Elixir technologies such as GenServer, Agent, libcluster, and Phoenix.PubSub.
It also includes a stock price generator that simulates an external service sending price updates. When a price is received, it is propagated to all subscribed users in real time.
- Users can subscribe and unsubscribe to individual stock tickers or all at once.
- Supports crash simulation to test fault tolerance and automatic recovery.
- On recovery, the system restores previous subscriptions.
- Distributed across multiple nodes using
libcluster.
FB, AMZ, AAPL, NVDA, GOOG
Install asdf and run:
asdf installOpen four terminal instances and run the following commands in each:
iex --name [email protected] -S mix
iex --name [email protected] -S mix
iex --name [email protected] -S mix
iex --name [email protected] -S mixEnsure
epmdis running and nodes can connect via Erlang distribution.
StockPriceListenerClient.subscribe("AMZ")
StockPriceListenerClient.subscribe_all()StockPriceListenerClient.unsubscribe("GOOG")
StockPriceListenerClient.unsubscribe_all(){:ok, pid} = GenServer.start(StockPriceGenerator, 5000)
# The number is the update interval in millisecondsGenServer.stop(pid)StockPriceListenerServer.crash()At least one user must be subscribed to
"AMZ"for the crash to be meaningful.
Phoenix.PubSub.broadcast(StockPriceListener.PubSub, "AAPL", {"AAPL", 31245})- The system demonstrates how to build a resilient Elixir application that can handle failures and recover gracefully.
- Useful for learning supervision trees, clustering, process recovery, and real-time messaging.