Developerx
Developerx

Reputation: 596

Creating a Gateway in JHipster microservice arhitecture without database

I am trying out JHipster based on the supported Microservice architecture. I have created a Registry, Gateway, and a Microservice (based on JWT authentication) as described in documentation and everything works. However I am not sure why a Gateway in JHispter need to have a database. Questions that are still unanswered for me: 1- Why does a Gateway need a database? In which scenarios would you create a Gateway with/without a database? 2- Do the Gateway and Microservice use the same database? Or should they use separate database instances?

Upvotes: 3

Views: 1102

Answers (2)

Developerx
Developerx

Reputation: 596

Ok, I did a bit more research on JHipster-Gateway and the inner workings of it. Below is a summary, related to my question:

1- A Gateway using a JWT or Oauth2 type only needs a database if the User related entities and backend code are also generated in the Gateway codebase. This is the case for a default JHipster Gateway, but does not have to be like this. As indicated in JHipster documentation a JHipster Gateway is actually a monolithic application and can be used as a monolithic application:

You will have the choice either to generate an new entity normally (a gateway is also a standard JHipster application, so this would work like for a monolith application), or use an existing JHipster configuration from a microservice.

When you create a JHipster Gateway, it creates the User entity related backend in Gateway codebase as default. But you can choose to have all the Backend code (including User) be placed/generated in Microservice codebase.

In such case there is no need of a database in JHipster Gateway application. Gateway working purely as a gateway to pass requests to microservices only needs to have the /api configurations properly set.

In the default case of a JHipster Gateway the User entity backend code is also generated in Gateway part, that is the reason why a database is needed. But you can move the backend code to Microservice and replace it by a proper /api configuration.

Upvotes: 2

Jon Ruddell
Jon Ruddell

Reputation: 6352

1) A gateway using JWT or OAuth2 auth types need a database to store users and their account details. A gateway using UAA auth type does not need a database, because the UAA microservice handles users and authentication.

2) Gateways and microservices should use their own database instances. You can use the same database instance in dev, but in prod each should have their own.

You can generate a docker-compose or kubernetes config for your gateway/microservices with the JHipster subgenerators, and in the generated YML files you will see each app has its own database instance.

Upvotes: 1

Related Questions