Skip to main content
add image and note of variations on the theme
Source Link
jleach
  • 2.7k
  • 13
  • 27

I like option 1. Your apps are then ignorant of their underlying persistence schema and the persistence management is done by the API (or layers below/within).

A common route would be your #1 option, with a repository pattern that has an interface like "get this", "get that", and the repository implementation deals with pulling the info from (and saving the info to) the correct database.

Alternatively, a separate API for each app, where each API has a repository somewhere below that does the same thing.

I would avoid the apps "talking to" the database directly as indicated in options 2 and 3.

Remember that (generally) each component should not generally be concerned with details of the services below it.

Generally speaking, the more segregated your services/layers are, the easier they tend to be to maintain over the long term, at the cost of a more complex initial setup. On the other hand, starting with a very simple architecture can be extremely difficult to deal with later on, so if there's any sort of expected longevity in the project, I'm much more apt to go with the architecture investment.

There's many variations on it (and if you're doing something like microservices you're in a much different realm), but here's a quick visual that gets the basic point across:

enter image description here

I like option 1. Your apps are then ignorant of their underlying persistence schema and the persistence management is done by the API (or layers below/within).

A common route would be your #1 option, with a repository pattern that has an interface like "get this", "get that", and the repository implementation deals with pulling the info from (and saving the info to) the correct database.

Alternatively, a separate API for each app, where each API has a repository somewhere below that does the same thing.

I would avoid the apps "talking to" the database directly as indicated in options 2 and 3.

Remember that (generally) each component should not generally be concerned with details of the services below it.

I like option 1. Your apps are then ignorant of their underlying persistence schema and the persistence management is done by the API (or layers below/within).

A common route would be your #1 option, with a repository pattern that has an interface like "get this", "get that", and the repository implementation deals with pulling the info from (and saving the info to) the correct database.

Alternatively, a separate API for each app, where each API has a repository somewhere below that does the same thing.

I would avoid the apps "talking to" the database directly as indicated in options 2 and 3.

Remember that (generally) each component should not generally be concerned with details of the services below it.

Generally speaking, the more segregated your services/layers are, the easier they tend to be to maintain over the long term, at the cost of a more complex initial setup. On the other hand, starting with a very simple architecture can be extremely difficult to deal with later on, so if there's any sort of expected longevity in the project, I'm much more apt to go with the architecture investment.

There's many variations on it (and if you're doing something like microservices you're in a much different realm), but here's a quick visual that gets the basic point across:

enter image description here

Source Link
jleach
  • 2.7k
  • 13
  • 27

I like option 1. Your apps are then ignorant of their underlying persistence schema and the persistence management is done by the API (or layers below/within).

A common route would be your #1 option, with a repository pattern that has an interface like "get this", "get that", and the repository implementation deals with pulling the info from (and saving the info to) the correct database.

Alternatively, a separate API for each app, where each API has a repository somewhere below that does the same thing.

I would avoid the apps "talking to" the database directly as indicated in options 2 and 3.

Remember that (generally) each component should not generally be concerned with details of the services below it.