To run the stack locally, you will need to have Docker and Docker Compose installed.
- Clone the repository:
git clone https://github.com/mhmadamrii/fullstack-challenge- Navigate to the project directory:
cd fullstack-challenge- Run the stack:
docker-compose up --buildThis will spin up the following services:
product-service: A NestJS service for managing products.order-service: A Go service for managing orders.postgres: A PostgreSQL database for storing data.redis: a Redis instance for caching.rabbitmq: A RabbitMQ instance for messaging.
This project is a microservices-based application that consists of two services:
product-service: A NestJS service that is responsible for managing products. It exposes a REST API for creating, retrieving, updating, and deleting products. It also uses Redis for caching and RabbitMQ for asynchronous communication with theorder-service.order-service: A Go service that is responsible for managing orders. It exposes a REST API for creating and retrieving orders. It communicates with theproduct-servicevia RabbitMQ to update the product stock when an order is created.
POST /products→ create product (product service)GET /products/:id→ fetch product cached using redis (product service)GET /orders→ get all orders (product service)POST /orders→ create order for existing product (order service)GET /orders/product/:productId→ fetch product’s orders (cached) (order service)DELETE /orders→ delete all created orders (order service)
- Get all products:
curl http://localhost:3000/products- Create a new product:
curl -X POST -H "Content-Type: application/json" -d '{"name": "Macbook Pro M3", "price": 2000, "qty": 100}' http://localhost:3000/products- Get product by id:
curl http://localhost:3000/products/<product-id>- Create a new order:
curl -X POST -H "Content-Type: application/json" -d '{"productId": "<product-id>"}' http://localhost:8080/orders- Get orders by product id:
curl http://localhost:8080/orders/product/<product-id>Creating order took around ~900RPS
Before running the test, make sure you have:
- k6 installed locally.
- A product available in the
productstable. - Increased the product quantity to a high number, for instance, 50000.
- Install k6:
brew install k6- Run the tests:
k6 run ./__test__/k6/load-test.js