Bazar.com is a simple bookstore web application designed with a two-tier microservices architecture. The application supports basic functionalities for book management, including search, viewing, and purchasing books.
This project employs a two-tier architecture with microservices. The application consists of the following main components:
- Frontend Service: Manages user requests and interacts with backend services (tested via Postman).
- Catalog Service: Manages the book inventory, including details and stock availability.
- Order Service: Processes purchase requests and updates the stock for each order.
- Search: Search books by topic and view available options.
- Info: Get detailed information about specific books, such as stock and price.
- Purchase: Purchase a book, which updates stock and order details.
- API Documentation: Interactive API documentation via Swagger UI.
- Caching: Redis is used to cache frequently accessed book information to improve performance.
- Load Balancing: Load balancer implemented using Nginx to distribute requests evenly across instances of Catalog and Order services.
- Node.js with Express.js for backend services.
- Sequelize ORM for database management.
- SQLite as a lightweight database.
- Redis for caching to enhance performance.
- Nginx for load balancing.
- Swagger UI for API documentation.
- Docker for containerization.
The application follows a microservices architecture:
-
Frontend Service:
- Receives client requests and relays them to Catalog and Order services through REST APIs.
-
Catalog Service:
- Manages book catalog and stock.
- Caches frequently accessed data using Redis to reduce database calls.
-
Order Service:
- Processes book purchases.
- Updates the stock in the catalog and records orders.
-
Nginx Load Balancer:
- Distributes incoming requests across instances of Catalog and Order services to improve scalability and handle high traffic.
-
GET
/catalog/search/:topic- Retrieves a list of books by topic.[ { "id": 1, "title": "How to get a good grade in DOS in 40 minutes a day" }, { "id": 2, "title": "RPCs for Noobs" } ] -
GET
/catalog/info/:itemNumber- Retrieves detailed information for a specific book.{ "title": "RPCs for Noobs", "quantity": 5, "price": 50 } -
PUT
/catalog/update/:itemNumber- Updates book details, including cost or quantity.
-
POST
/order/purchase/:id- Processes a book purchase and reduces stock.{ "message": "Book purchased successfully", "order": { "bookId": 1, "quantity": 1 } } -
PUT
/order/update-stock/:id- Updates the stock for a specific book.
| Column | Type | Description |
|---|---|---|
| id | INTEGER | Primary key for each book |
| title | TEXT | Title of the book |
| quantity | INTEGER | Quantity in stock |
| price | REAL | Price of each book |
| topic | TEXT | Topic of the book |
| Column | Type | Description |
|---|---|---|
| id | INTEGER | Primary key for each order |
| bookId | INTEGER | ID of the book ordered |
| quantity | INTEGER | Quantity purchased |
- Frequently accessed data, such as book details and availability, are stored in Redis to improve response time and reduce load on the SQLite database.
- Redis caching is applied on endpoints like
/catalog/info/:itemNumberto return results faster for repeated requests.
- Nginx is configured as a load balancer to evenly distribute requests across multiple instances of the Catalog and Order services.
- This setup allows the application to handle higher traffic efficiently, ensuring better uptime and scalability.
- Clone the repository:
git clone https://github.com/your-username/bazar-com.git cd bazar-com