- challenge-nodejs.postman_collection.json: Postman collection with the API requests.
To run this project successfully, ensure you have the following installed on your machine:
- Clone the repository or download the code.
- Open a terminal and navigate to the project directory.
- Docker needs to be running. Run
docker-compose up -d --buildThis command will:
- Start MongoDB, Redis, RabbitMQ, and Elasticsearch
- Build and start the Order Service , Logging Service and Queue Worker If you don't have the images locally, maybe
- Wait for the containers to start, ensuring all services are up and running.
- Ensure ports
3000,3001,5672,27017,6379, and9200are not in use by other applications.
- To stop the containers and remove the volumes, run
docker-compose down -v.
For any issues, check the logs with:
docker-compose logs -f
This service is responsible for creating and retrieving orders.
This endpoint is used to create a new order, save it to the database, and send it to the queue. It accepts a JSON payload with the following properties:
| Property | Type | Description |
|---|---|---|
| userId | string | The user ID associated with the order. |
| products | array | An array of objects representing the products and their quantities. |
Example:
{
"userId": "12345",
"products": [
{ "productId": "p1", "quantity": 2 },
{ "productId": "p2", "quantity": 1 }
]
}curl --location 'http://localhost:3000/api/v1/orders' \
--header 'Content-Type: application/json' \
--data '{
"userId": "1",
"products": [
{
"productId": "p1",
"quantity": 2
},
{
"productId": "p2",
"quantity": 1
}
]
}'
This endpoint retrieves the details of a specific order using its
orderId. It first checks the Redis cache; if the order is not found in the cache, it fetches it from the database and stores it in the cache for 5 minutes. Response headers includeX-Cache: HITif the order is found in the cache, andX-Cache: MISSif the order is not found in the cache.
Example:
{
"orderId": "12345",
"userId": "12345",
"products": [
{ "productId": "p1", "quantity": 2 },
{ "productId": "p2", "quantity": 1 }
],
"status": "PENDING"
}This service is responsible for logging application-related events. It provides an API to retrieve logs.
This endpoint retrieves all logs.
curl --location 'http://localhost:3001/logs'
This endpoint retrieves logs related to a specific order using its
orderId. If no matching order is found, it returns an empty array.
curl --location 'http://localhost:3001/logs/orders/o2104'
Example response:
[
{
"@timestamp": "2025-03-08T21:29:53.109Z",
"message": "Order sent to RabbitMQ",
"severity": "info",
"fields": {
"userId": "1",
"orderId": "o2104",
"status": "PENDING",
"service": "order-service"
}
}
]This service is responsible for consuming messages from the queue and processing them. It updates order statuses in the database and logs events to Elasticsearch.
- RabbitMQ:
Docker image - MongoDB:
Docker image - Redis:
Docker image - Elasticsearch:
Docker image - NodeJS:
node:18-alpine