JoeZMar

JoeZMar

Separating the DB in an Umbrella project

I am making my first umbrella project right now and I want to separate the database into it’s own application. I am trying to understand how to appropriately break up an umbrella project.

Here is what I am thinking so far:

My app has two web interfaces: user_web & admin_web

In addition I have an app to handle the backend logic: app

Right now my two web interfaces talk to the one backend logic app that I plan on connecting the rest of the micro-service apps to.

Here is where things get dicey for me. I’ve seen a few videos where the app was broken down even further into several micro-services. I haven’t found a decent/modern example that shows how small these micro-services should be. If I was adding authentication to my app I could create a micro-service for Authorizing users and have that as a separate app. I feel like I kind of understand this concept (or can at least figure it out) until I started to introduce the concept of separating the database.

From what I’ve read it seems like creating a separate application to serve the database logic is the way to go and have that app connected to the only database in the umbrella project. Does that mean when I introduce the ability to create users within my umbrella project the schema is stored within the database logic app or the app responsible for implementing the users?

I think if I understood the layer that manipulates the database application and how it i should implement the db api I can figure out how each piece of my app should fall together.

My app is eventually going to be very large including several services for different agencies and a few different native mobile applications so I really like the idea of having well thought out applications that are small and functional so they can be easily plugged into our future apps we create.

First 8 of 8 Posts Switch mode

maz

maz

Take a look at this thread:

I suggest just start with that. It’s easy to get into ‘analysis paralysis’

cohawk

cohawk

The CaptainFact API might be a good example project for what you are trying to accomplish.

mbuhot

mbuhot

One of the great features of Ecto is that the schema structs don’t need to map directly to tables. This allows each umbrella app to manage its own schemas, and the shared DB app just defines the repo module, migrations and configuration.

JoeZMar

JoeZMar OP

This was my original thought was that each app would hold its own schema (a great example is my users and admins have two separate schemas, but are used for the same table). If I created a Db app, what responsibilities should it have?

Right now here is how I am thinking about structuring my umbrella project:

user_interface ----                 |---- Auth
                   |- app_name -----|
admin_interface ---                 |--- (Additional Micro-services that create the app)
                                    |---- Elixir App hooked up with Ecto and a DB

Does the database application only contain functions within its Context to help the other microservice applications in the umbrella create records?

For example within the Database application a function in the context might look something like:

def create_record(table, schema, attrs) do
   ...
end

and each application has it’s own schemas and makes the request to the database app this way.

mbuhot

mbuhot

Not sure if create_record is a great example, since there’s usually Changeset validations associated with record creation.

But other generic helpers like adding Pagination clauses to a Query, or multi-tenancy concerns might belong in a DB application.

I’d avoid wrapping the Repo API, since a Repo is already a fine DB abstraction layer. :slight_smile:

JoeZMar

JoeZMar OP

Okay thanks for the help. This answers my question because I hadn’t thought of the possible helper functions that a db app could hold.

zubairshokh

zubairshokh

Did you go with the single Repo or multiple Repo(each app with its own repo) structure.

@mbuhot what is better in this situation. a single repo or the multiple repo? if the structure is decoupled already.

mbuhot

mbuhot

I’d start with one Repo then split it into multiple when you want to isolate access to the tables using postgresql Schemas (aka namespaces) and separate roles/ permissions for each Repo.

— All posts loaded —

Where Next?

Trending in Questions Top

jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
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
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement