EmerisHQ / demeris-backend

Monorepo containing all the Demeris backend code and infrastructure definitions.
GNU Affero General Public License v3.0
8 stars 1 forks source link

Split api-server "database" pkg using repositories pattern #787

Open Pitasi opened 2 years ago

Pitasi commented 2 years ago

api-server has a common package called database: https://github.com/EmerisHQ/demeris-api-server/tree/main/api/database.

The exported database.Database is used across every http handler, some examples:

In the optic of not sharing a single database someday, I keep this questions in mind:

That's why I think we should make it easier for us to change our "storage layer" implementation, and better separate it from the business logic (= the handlers). This would also allow us to write real unit tests that don't depend on any database.

DoD

tbruyelle commented 2 years ago

Currently, this shared database pattern allows us to join data easily. If we go for splitting the data into separate databases, that means we first have to query the different services to gather the required data, and then build our sql query. So after a full rewrite of the sql queries, we'll necessarily have a bad impact of performances, because of the network latency we didn't have before.

I'm OK with the idea that a shared database isn't ideal in a micro-service architecture, because it basically creates a big SPOF, and makes migrations more difficult. But then I have an other question, do we really need a micro-service architecture ? If for instance we consider cns and api-server, I'm not sure to get why they deserve their own service. Maybe they could be merged ?

In addition to the performance, I fear that once we split up the databases, it will slow down development, mainly because writing a single sql query is faster than fetching data in various services.

So conclusion I think we should consider the options carefully. WDYT @Pitasi ?

Pitasi commented 2 years ago

Ok let's put this ticket on hold, it actually is part of my "internal" roadmap for achieving a certain end state, but I understand we need to better discuss this end state with the team 😄