Microservices for any Ecommerce Backend
Imagine running an eCommerce store like a well-organized mall. Instead of having one giant, overwhelmed department store trying to sell everything and keep track of it all (a monolithic approach), you’ve got individual shops—each handling their own piece of the puzzle.
There’s the Auth Boutique, where only trusted customers are allowed in. Next, the Payments Emporium, which handles all the money stuff—no haggling, just smooth transactions. Then, you’ve got the Product Palace, filled with shelves of all the awesome things for sale, and of course, the Cart Corner, where customers can stack up their items.
Each of these “shops” (aka microservices) runs independently. If the Cart Corner is having a sale, the Product Palace doesn’t need to freak out—it continues to do its job. And, if the Payments Emporium needs an upgrade, you can swap it out without shutting down the whole mall!
This is way better than a monolithic setup, where everything’s tangled together. In a monolithic system, if one part crashes (like the payment system), the whole store has to close. But with microservices, each service is its own boss, so even if one service has issues, the others keep on working.
By splitting everything into manageable, specialized services, you keep things running smoothly and efficiently. It’s like having a perfectly organized mall where each store does its own thing, but they all work together to create an amazing shopping experience!
Each service requires specific environment variables to work properly, for that you need to create a .env file in the following locations and fill it with mentioned environment variables.
API-Gateway
auth-Services
product-Services
cart-Services
order-Services
payment-Services
git clone https://github.com/Prakhar301101/Ecommerce_Microservices.git
cd ecommerce-microservices
Ensure Docker is running on your machine.
Build and start the containers using Docker Compose:
docker-compose up --build
This command will build all the services, create containers for them, and start them.
After the build process, you should see the services running. Each service will be accessible at the following ports:
The API Gateway is responsible for routing client requests to the correct microservice. It simplifies communication by exposing a unified interface to clients while hiding the complexity of the microservices behind it. It has a Rate limiting feature which sets a limit to the number of API calls to the gateway in a time interval which prevents any abuse of the API.
Auth Services
Handles user authentication and authorization. It provides routes for login, registration, and token(JWT) management.
Endpoints
HTTP Method | URL | Description |
---|---|---|
POST |
http://localhost:5000/api/auth/register | Create new User |
POST |
http://localhost:5000/api/auth/login | Log-in User |
GET |
http://localhost:5000/api/auth/me | Get User details |
PATCH |
http://localhost:5000/api/users/me | Update User details |
POST |
http://localhost:5000/api/users/logout | Logout user |
GET |
http://localhost:5000/api/users/verify | Used for authorisation |
Product-services
Manages the catalog of products. It handles requests to view products, search for specific items, and manage product details (for admin users). It also uses redis for caching product details for faster API response time.
Endpoints
HTTP Method | URL | Description |
---|---|---|
GET |
http://localhost:5000/api/product/view | Display all products or by queries |
GET |
http://localhost:5000/api/product/view/:id | Display selected product |
GET |
http://localhost:5000/api/product/categories | Display categories |
POST |
http://localhost:5000/api/product/addProduct | Add a product |
POST |
http://localhost:5000/api/product/addCategory | Add a category |
PATCH |
http://localhost:5000/api/product/update/:id | Update details of products |
DELETE |
http://localhost:5000/api/product/delete/:id | Delete products |
Cart-services
Manages the shopping cart functionality, allowing users to add, remove, and view products in their cart.
Endpoints
HTTP Method | URL | Description |
---|---|---|
GET |
http://localhost:5000/api/cart/ | View the items in cart |
POST |
http://localhost:5000/api/cart/add | Add item to cart |
PATCH |
http://localhost:5000/api/cart/update | Update items in cart |
DELETE |
http://localhost:5000/api/cart/remove | Remove an item from cart |
DELETE |
http://localhost:5000/api/cart/clear | Clear the cart |
Order-services
Handles the creation of orders once a user completes their cart. It tracks the status of an order from creation to completion.
Endpoints
HTTP Method | URL | Description |
---|---|---|
POST |
http://localhost:5000/api/cart/ | Place Order and initiate payment |
GET |
http://localhost:5000/api/cart/ | Get Order details By orderID |
GET |
http://localhost:5000/api/cart/all | Get all orders for an user |
PATCH |
http://localhost:5000/api/cart/ | Update orderDetails |
Payment-services
Processes payments and interacts with payment providers (Stripe for our case). It confirms the transaction and links it to the order.
Endpoints
HTTP Method | URL | Description |
---|---|---|
POST |
http://localhost:5000/api/payment/check-out | Processes Payment through stripe and returns response |