Verify Multiple Server Behavior

Learn more about replication rather than the distribution of servers.

Add replication of Inventory events

Phoenix PubSub can be used for more than Channel messages. It lets any process subscribe to a particular event type at its core. We will use PubSub to power the replication events for our Inventory. We’ll need to spin up a new GenServer to handle the events, as well as a context to dispatch the events.

Replication is not without its own challenges—nodes can become out of sync from this replicated approach. For non-critical data, scalability benefits are often worth the trade-off of potential data incorrectness. In Sneakers23, we never use the replicated data as a source of truth for essential operations, such as the purchase process. Instead, we use the database to ensure that these operations are consistent.

We’ll first write the GenServer and then work our way up through the various layers.

Get hands-on with 1000+ tech skills courses.