mesuutt
Some questions about working with multiple connected processes, linking and app structure
Imagine such a scenario:
There are 2 companies(dealer and supplier), each one using their own websites.
I want to create a service between them.
My service will periodically fetch new product request from the dealer’s API and send the product request to the supplier’s API. Also, the service will periodically check sent product requests from supplier’s API and if there is a change about the sent products on the supplier’s website the service will send related changes to dealer’s API.
I don’t know exactly what is the best way of handling this type of scenario.
What do you think about building a structure like this:
Start 2 GenServers for each dealer<=>supplier binary when application started.
I think creating two separate genserver will provide me separation of dealer/supplier related code from each other.
DealerClient:
- Fetch new products from dealer API(periodically)
- Send product changes sent by supplier genserver to dealer API.
SupplierClient:
- Fetch product changes from supplier API(periodically).
- Send the changes to dealer genserver.
So data flow will be like this:
DealerAPI <-> DealerClient <-> SupplierClient <-> SupplierAPI
Also there are multiple dealers and multiple suppliers(OneToOne relation), so each dealer process should know
her supplier’s process to send or fetch data from.
Questions:
- This structure is good? If not what would you do if you were me? What kind of structure would you build?
- How to handle dynamic process linking? How does dealer process know her supplier’s process?
- Should I create a supervisor for each dealer<=>supplier binary?
Sorry about my poor English.
Most Liked
kokolegorille
Hello, welcome to the forum.
That is a nice project, let me have my 2 cents opinion…
GenServer are not object, the closest You might find in Elixir is a struct. A struct is like an object without method, what You would call methods, are Module functions…
You can learn about good usage of GenServer here https://www.theerlangelist.com/article/spawn_or_not.
What about a GenServer called LinkService, where You would pass dealer and supplier as params Structs?
You have probably many ways to do it, but I don’t think You should model your business directly with GenServer 
lud
Welcome there ![]()
I think you misuses GenServer for objects (as in OO). Kind of what @kokolegorille said.
I think it would be easier to desing and to test with Task, or other short lived processes.
My service will periodically fetch new product request from the dealer’s API and send the product request to the supplier’s API
When you say “periodically” and then Should come 10 product per second sometimes … How is a fetch triggered ? Is it from external input or do you have a process that triggers the fetch every X seconds ?
I think I would just write the code that does 1) fetch a new product request and 2) send it to the supplier. When it works, then
I would just wrap that in a Task.
If your fetch returns multiple products, I would spawn a Task for each one or use Task.async_stream to limit concurrency and to be gentle with the external endpoint.
What about a GenServer called LinkService, where You would pass dealer and supplier as params Structs?
This GenServer could be the one that does the fetch every N seconds or listens for external inputs ; and spawn tasks.







