Demonstrates a fundamental Microservices Architecture. Instead of one monolithic FastAPI app containing all features, we split the application into two entirely separate services:
- Users Service (Port 8001): Manages user data.
- Orders Service (Port 8002): Manages orders. When an order is requested, it uses
httpxto synchronously communicate over the network with the Users service to fetch the user's details and stitch the data together.
Includes a unified frontend to query the Orders service and see the stitched data.
68-fastapi-microservices/
users_service/
main.py # Port 8001 server
orders_service/
main.py # Port 8002 server (calls 8001)
shared/
models.py # Pydantic models shared across services (conceptual)
index.html # Unified Frontend hitting Port 8002
requirements.txt # Dependencies
README.md # This file
pip install -r requirements.txtIn a new terminal:
cd users_service
uvicorn main:app --port 8001In a new terminal:
cd orders_service
uvicorn main:app --port 8002Open index.html directly in your browser.
{
"order": {
"order_id": 101,
"user_id": 1,
"items": [{"product": "Laptop", "price": 999.99}]
},
"customer": {
"id": 1,
"name": "Alice Inwonderland",
"email": "alice@example.com"
}
}- Service Separation: Complete isolation of domains.
- Service-to-Service Communication: The Orders service acts as a client to the Users service using Python's async
httpxlibrary. - Data Aggregation: The Orders service stitches together its internal order data with the external user data before returning it to the browser.