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?
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.