Products microservices
September 2024
Microservices
This is the first time I work with microservices and I decided to build a basic architecture to manage the products of an online store. Part of the code of this project is based on the NestJS + Microservices course.
Key Components
- API Gateway - Acts as the entry point of the application, it routes the requests to the corresponding microservice and it is responsible for the validation of the requests.
- Auth Microservice - Manages the authentication and authorization of the users making use of JWT tokens. It also manages the users using MongoDB as the database.
- Products Microservice - Manages the products of the application, allowing the users to create, update, delete and list the products. It uses SQLite as the database.
- Orders Microservice - This service is responsible for creating the orders and manage their status. It uses PostgreSQL as the database.
- Payments Microservice - Manages the payments of the application, using Stripe as the payment gateway. This service is hybrid, it has one REST endpoint that is used.
Technologies
- NestJS: Node.js framework used for building for building efficient, reliable and scalable server-side applications.
- Nats: Message broker used for the communication between the microservices.
- Docker: For containerizing the services, facilitating deployment in any environment in a consistent and reproducible way.
- PostgreSQL: Relational database selected for its reliability and ability to handle large volumes of data.
- MongoDB: NoSQL database used for the users in the auth microservice.
- Stripe: Payment gateway used for the payments microservice.
- Prisma: ORM used in OrdersMS, AuthMS and ProductsMS.
Architecture
The architecture of the application is based on the microservices architecture pattern. Each microservice is a separate entity that is responsible for a specific part of the application. The communication between the microservices and the API Gateway is done using the NATS message broker.
All the services are containerized using Docker, which allows them to be encapsulated in a private network allowing only the necessary services to be exposed to the outside. The only services exposed to the outside are the API Gateway and the webhook endpoint of the Payments Microservice.