fast-cart is a microservices-based e-commerce backend designed for high performance and scalability.
The project is designed to consist of two microservices:
-
Inventory Service: This service manages product inventory, including stock levels, product details, and updates. It interacts with a redis database for storage, using redis for caching as well.
-
Payment Service: This service handles payment processing, order validation, and transaction management, stored in postgresql. It also interacts with the Inventory Service to validate stock availability before processing payments. It also uses redis for caching as well.
-
Inventory Frontend This service provides a user interface for managing inventory. It allows users to:
- View product details and stock levels.
- Add, update, or delete products.
- Monitor inventory changes in real-time.
The frontend is built using React for a responsive and dynamic user experience. It communicates with the Inventory Service via RESTful APIs to fetch and update data.
- Navigate to the
inventory-frontend
directory. - Install dependencies:
npm install
- Start the development server:
npm run dev
- Access the application at
http://localhost:3000
.
-
Payment Frontend
in progress
-
Event Driven Architecture
Event-driven architecture enables seamless communication between the Payment and Inventory services using Redis Streams. When a payment is processed, the Payment Service publishes an event to a Redis stream. The Inventory Service subscribes to this stream, listens for payment events, and updates stock levels accordingly. This decoupled approach ensures scalability, real-time updates, and fault tolerance in the system. Also makes it easier to catch rare edge cases.
- FastAPI: For building high-performance APIs with Python.
- Redis: For caching and message brokering between microservices.
- Redis Stream: Used for event driven architecture.
- SQL Database: For persistent storage of inventory and payment data.
- Docker: For containerizing the microservices for easy deployment and scalability.
- GitHub Actions: For CI/CD pipelines to ensure code quality and automated testing.
- Pre-commit Hooks: For enforcing code formatting and linting standards.
The two microservices will communicate with each other using RESTful APIs with FastAPI
. Redis
will be used as a message broker for asynchronous tasks, such as updating inventory after a successful payment: part of event driven architecture.
[x] Use SQL for persistant storage and redis for caching. [ ] Add authentication and authorization mechanisms. [x] Implement monitoring and logging for better observability. [ ] Explore deployment options such as Kubernetes for scaling the microservices.
This project aims to serve as a robust starting point for building scalable and maintainable microservices with Python.
Note
Check Milestones below to track project progress.
Being developed on: python 3.10.16
To build and run the application using Docker, follow these steps:
Ensure you have Docker installed on your machine. You can download it from here.
Important
Docker Daemon
or Docker Desktop
must be running while building Docker Image.
Navigate to the root directory of the repo where the Dockerfile
is located and run the following command to build the Docker image:
docker build -t fastcart:latest .
After building the Docker image, you can run it using the following command:
docker run -dp 8000:8000 <fastcart>:latest
or give the container a name:
docker run -dp 8000:8000 --name <fastcart>-latest <fastcart>:latest
This will start the application in a Docker container. The application can be accessed at http://localhost:8000
e.g. 127.0.0.1:8000
Note
-dp
(-d
& -p
) tag runs the container in detached mode (in the background, terminal is available to use right away) and container port 8000
is mapped to local port 8000
.
To stop the running container, first find the container ID using:
docker ps
Then stop the container using:
docker stop <container_id>
this part is yet to be updated with repo structure
- [optional but recommended] create a venv and activate it
- Install dependencies:
pip install -r requirements.txt
- start Uvicorn server:
uvicorn app.main:app --reload
ctrl+c
to break the server.
- develop inventory api π€
- develop payment api β¨
- Interact between the microservices π
- unit testing π§ͺ
- write comprehensive readme π
- write readme-dev π
- dockerize the repo π³
- Code Auto-formatting & Linting with Pre-commit (check-yaml, end-of-file-fixer, trailing-whitespace, black, isort, mypy, flake8, bandit) π¨
- add GitHub Action for format checks β
- Study deploy requirement and deploy! π
Bug reports, issues, forks and pull requests are always welcome!
This project is available as open source under the MIT License. See the LICENSE file for details.