From 40f5015ac97faa1badb6858435a8482a1e75a49f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 22 Apr 2025 17:31:54 +0200 Subject: [PATCH] Add example of using library with Ecto --- README.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 69e66d3..3c85faa 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ config :libcluster, Then add it to your supervision tree: ```elixir -defmodule MyApp do +defmodule MyApp.Application do use Application def start(_type, _args) do @@ -74,6 +74,31 @@ defmodule MyApp do end end ``` + +If you are using Ecto, you may want to reuse your existing repo +configuration. For example: + +```elixir +defmodule MyApp.Application do + use Application + + def start(_type, _args) do + topology = [ + strategy: LibclusterPostgres.Strategy, + config: MyApp.Repo.config() + ] + + children = [ + # ... + {Cluster.Supervisor, [[app: topology]]}, + # ... + ] + + Supervisor.start_link(children, strategy: :one_for_one) + end +end +``` + ### Why do we need a distributed Erlang Cluster? At Supabase, we use clustering in all of our Elixir projects which include [Logflare](https://github.com/Logflare/logflare), [Supavisor](https://github.com/supabase/supavisor) and [Realtime](https://github.com/supabase/realtime). With multiple servers connected we can load shed, create globally distributed services and provide the best service to our customers so we’re closer to them geographically and to their instances, reducing overall latency.