voughtdq

voughtdq

What is the "right way" to get data from another bounded context?

I have an Accounts application that manages core business logic. There is an Organization model in the Accounts application that represents a single instance of a real world client.

I’m now working on a Billing application, but I want it to be on a separate node. The Billing application will need to know the Organization’s name and its ID, but nothing else.

What is the “right way” to get the Organization information from the Accounts application to use it in the Billing application?

Should the billing application subscribe to Organization events on a bus and create its own instance of an Organization?

Or should I use :rpc to query the Organization data on the node that’s running the Accounts application?

Or something else?

Most Liked

Qqwy

Qqwy

TypeCheck Core Team

“it depends”.

Running something on a separate node can never be a goal on its own: Why would you want to split your application up into these two things and run that one on a different node?

If you do go ahead and run its on a separate node, the following are possible:

  • Connect the nodes directly using Distributed Erlang, and then indeed use :rpc or similar functions (If you restrict what runs on what node, using :rpc is not even necessary, since you can just use GenServer.call directly). Distributed Erlang is however not that well-suited for having the nodes in different data centers across the globe.
  • Connect them externally, either by directly communicating (only works when both nodes are available), or using a solution like RabbitMQ (keeps messages when receiver is down; can easily be extended once you add more instances of one of the nodes).
  • Connect both nodes to the same datastore, and have this be the ‘single source of truth’. Useful for some applications, but makes your datastore a single point of failure. (And if it is not a distributed datastore, it also might not be that scalable).

And there are other possibilities as well, probably.

easco

easco

Have a care about what events you distribute. It is easy to distribute events that are “too low level” and get unusual cross-service coupling that way. For example, if your ordering system broadcasts “order began”, “item added”, “item removed”, and “order completed” messages, and your inventory system had to respond to all those messages, then any change in the set of events, or their organization, could require changes to both components.

Instead of blindly broadcasting all events, components should have a curated set of semantic events that describe “milestones” for their domain. It’s no different than being careful to define the private or public interface of any other software component - just keep it in mind as you are looking at coupling service through domain events as well.

Where Next?

Popular in Questions Top

openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement