Auth microservice for microservices architecture.
Added code: https://github.com/ndmen/auth-microservice/tree/main
- POST /auth/signup - Register user
- POST /auth/signin - Login user
If token exist in redis - return from redis If token not exist - sign new token
My response:
- We can use database sharding
- We can use caching
- We can use asynchronous functions (big tasks as email for example delegate to background jobs or queues)
- We can distribute incoming requests across multiple instances
My response:
- We can use redis for returning access token (caching)
- We can use throttling (ThrottlerModule in nest js)
- We can optimize database queries
-
Clone code: https://github.com/ndmen/auth-microservice/tree/main
-
Install packages: yarn install
-
Create file .env.development and copy environments from file .env.example
-
Run in docker container auth, redis and postgres using command: yarn docker:up (If will RECONNECT to redis inside docker container (See auth-microservice logs) - run only auth-microservice just through terminal on local machine)
-
Run migrations in database postgres: yarn migration:run
-
Open Swagger: http://localhost:3000/swagger#/auth/authSignUp
-
Run e2e test: yarn test:e2e
.env.development.local
.env.development
.env
$ yarn install
# development
$ yarn start
# watch mode
$ yarn start:dev
# development in docker
$ yarn docker:up
$ yarn docker:logs
# production mode
$ yarn start:prod
# unit tests
$ yarn test
# e2e tests
$ yarn test:e2e
# test coverage
$ yarn test:cov