Manzanit0

Manzanit0

Hey all!

I’m currently working on pushing a bunch of different applications I have running in the cloud into an Umbrella, mostly so I can manage them as a whole.

One of the things I’ve been mulling over is that I would also like to use the same Postgres instance: at the end of the day it’s not a lot of data and it would make my life infinitely easier. However, since they ARE different applications (for example, a cooking web app and a telegram todo bot), I would like to seggregate the data into different Postgres schemas.

With my current knowledge, how I would do this is configure an Ecto.Repo per application and in each repo set the after_connect property such as: after_connect: {Postgrex, :query!, ["SET search_path TO cooking_app", []]}. This allows me to not have to deal with prefixes on a daily basis and have it isolated there as well as it just simply working out of the box with migrations and everything.

However, the main drawbacks I see to this approach are that (1) as I create more Ecto.Repo instances, I’m creating more connection pools, while I might want to share the same pool between all repos, and also that (2) I still haven’t figured out how to create the schemas easily before running the migrations from each Application.

How would you folks frame this problem? I’m interested in any thought, even if it isn’t necessarily a solution :slight_smile:

Cheers,
Javier

Showing Posts 1 to 5

dmitrykleymenov

dmitrykleymenov

Why do you want to use the same pools? Cache is the main goal of pooling, and with completely different data it doesn’t matter one connect handles two different requests of two connects do the same. If total pool size is ok, ofc. I think so.

Manzanit0

Manzanit0 OP

Good point — I haven’t really looked into how pooling works, the only thing I was concerned about was that if each Repo’s pool opens up 10 connections, I might end up having 80 connections open and Postgres might not like it too much. But other than that, I haven’t looked into that topic to much yet.

dmitrykleymenov

dmitrykleymenov

I think it’s even worse since your apps will use their own connections, so cache hit will be 8 times more for 10 per app, than 80 for “share-pooling-umbrella”. Even for 40, or less.

Manzanit0

Manzanit0 OP

There is always the possibility of implementing a custom pool, like this, which seems fairly lightweight.

And of course, there’s the option to use a shared Repo and create wrappers for each umbrella application which simply leverage the prefix option… but I’d like something a but less verbose.

cjbottaro

cjbottaro

We have a multi-tenanted application which has a similar problem, but even a little worse (we have like 800 Postgres schemas across 5 servers).

What we do is have 5 normal Ecto.Repo modules, one for each server. Then we wrote our own MultitenantRepo that (nearly) implements the Ecto.Repo behavior. Then we send our queries to that.

Ecto.Query.from(...)
|> MultitenantRepo.all()

Each function in MultitenantRepo figures out which normal repo to delegate to and how to set the proper :prefix if applicable.

It’s kind of a PITA because there are a lot of functions in the Ecto.Repo behaviour to implement, but with a little bit of clever metaprogramming, it’s not too bad.

I tried the custom pool route to do this, and this way is much simpler IMO.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
New
Stef-Verniers
Hello I’ve been coding in Elixir for almost two years now because of my current job where we implemented Elixir in our application. But ...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews