Question about application boundaries and Ecto Sandbox.mode

I have a question about application boundaries that is maybe a bit complicated, but I will try to explain my thinking so someone wiser than me can tell me if this is a good or bad idea.

There are 2 applications relevant:

  • App X uses gen_stage and has primary focus of getting data (from APIs files etc).
  • App Y is a hex dependency and has primary focus of storing the data.

Application X does not need to know how app Y stores the data. X gets some data maybe does some things like merging or notifications and then does dispatch to app Y: “here, please store this.” App X has protocol definition so always we know how to store different structs.

At first I thought this makes sense: app X does not worry about how app Y stores the data. However, then I started thinking about the tests. The tests in app X use Ecto.Adapters.SQL.Sandbox to help test the protocol impl to make sure things actually do get stored as expected. But now the boundary is not clear because the tests must know how app Y is storing data.

I hope this is clear my explaining. Is this too much thinking? My idea is that the application boundary would be cleaner if app Y (not app X) defined the protocol for how to store. That way app X would not need Ecto.Adapters.SQL.Sandbox ever – that could be moved to app Y and tests for app X would only need to assert_receive to make sure that the data message was sent to app Y. But then integration tests are more difficult.

Does anyone have some thoughts they can share to help my confusion? Thank you in advance!

1 Like