Shipr is a personal project aimed at helping folks understand distributed microservice architecture. It’s a simple, lightweight system designed to manage products, process orders, and handle payments.
The Inventory Service is the backbone of Shipr's infrastructure, responsible for tracking product availability and stock management.
-
Main Application (
main.py
): The core of the inventory service, powered by FastAPI. It exposes RESTful APIs for CRUD oeprations. -
Consumer (
consumer.py
): In conjunction with the main service, the consumer listens to Redis streams for updates on completed orders. When an order is processed, it adjusts inventory levels in real-time, ensuring that stock data is always accurate. In the event of an error, it triggers a refund process to maintain data integrity and customer satisfaction.
- Python 3.x
- Redis
As a best practice, it is advised to create a virtual environment to store this project's dependencies separately. You can install virtualenv with
-
Install virtualenv (optional)
pip install virtualenv
-
Create env (optional)
python -m venv .venv
-
Activate virtualenv (optional)
source env/bin/activate
-
Install depndencies
pip install -r requirements.txt
-
Make sure you have a
.env
file with following variables.# Redis configuration REDIS_HOST=xxx REDIS_PORT=xxx REDIS_DB=xxx # CORS configuration ALLOW_ORIGINS=xxx ALLOW_METHODS=xxx ALLOW_HEADERS=xxx
-
Run server
uvicorn main:app
-
Run message consumer
python consumer.py