# Let libraries be libraries

**URL:** <https://forum.elixirforum.com/t/let-libraries-be-libraries/75921>\
**Category:** Blog Posts\
**Tags:** best-practices, anti-patterns, blogs-by-jola\
**Created:** [July 7, 2026, 12:50pm UTC](https://forum.elixirforum.com/t/let-libraries-be-libraries/75921 "2026-07-07T12:50:38Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![hauleth](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hauleth/32/18942_2.png) [@hauleth](https://forum.elixirforum.com/u/hauleth)\
**Post date:** [July 8, 2026, 10:54am UTC](https://forum.elixirforum.com/t/let-libraries-be-libraries/75921/7 "2026-07-08T10:54:15Z")

</div>

> [@Asd](#):
>
> I can’t just connect to different databases in runtime, because database connections pool is tied to the Repo module (the one which calls `use Ecto.Repo` in it), and Repo module is required because Ecto uses global application state in order to set up pools of connections.

That is not true. You can 100% connect to different DBs using the same module. It is not common practice, because that is not the common problem, but it is fully supported and [documented](https://ecto.hexdocs.pm/replicas-and-dynamic-repositories.html#dynamic-repositories).

```elixir
MyApp.Repo.start_link(
  name: :some_client,
  hostname: "client.example.com",
  username: "...",
  password: "...",
  pool_size: 1
)

```

It is not fully ergonomic, I agree, but at the same time that is not a common situation when you need such thing.

* * *

About the topic, I mostly agree with @jola. There are however grey areas sometimes. If you use `Application` just for env, then yeah, it is dumb, but there are situations when there is no point in having multiple instances of the processes provided by the library. Like in my [systemd](https://github.com/hauleth/erlang-systemd) library, where there is no point in having multiple instances, and moving that to the user-side to manage processes for this would only make it worse wrt. UX.

Another thing is that sometimes the process running in the background should be transparent to the user. Like in my [aww](https://tangled.org/hauleth.dev/aww) library. Some may argue, that cache there is a wrong approach and user should cache on their own. But at the same time, when you are using (most of the time indirectly) Erlang’s DNS resolver do you think that there is a cache for A and AAAA responses? Because there is one.

Another thing that uses their own supervision tree, but people do not think about it at all, is Telemetry. Yeah, really, there is [supervision tree](https://github.com/beam-telemetry/telemetry/blob/main/src/telemetry_app.erl). To be fair, it would be impossible to implement without that tree (at least if we want to use ETS, after you fire `:telemetry.persist()` it is not needed anymore).

So I would say that it is a complex topic, but when in doubt - do not spawn your own supervision tree, you ain’t gonna need one probably.

---

_[View the full topic](https://forum.elixirforum.com/t/let-libraries-be-libraries/75921)._
