This repository hosts a sample e-commerce platform demonstrating a microservices architecture using multiple Go services alongside a Python-based Recommender service. The project showcases:
- gRPC communication between services
- Kafka-based event streaming pipeline
- A unified GraphQL API gateway for clients
- Elasticsearch integration for product search
The system comprises several microservices:
- Account (Go): Manages user accounts, authentication, and authorization.
- Product (Go): CRUD for products; indexes product data in Elasticsearch.
- Order (Go): Handles order creation and persistence; publishes events to Kafka.
- Recommender (Python): Consumes Kafka events and builds product recommendations.
- API Gateway (Go): A GraphQL service exposing a unified API for front-end clients.
The entire ecosystem is containerized using Docker Compose. Datastores include PostgreSQL, Elasticsearch, and Kafka.
Below is a high-level overview of the system architecture:
-
API Gateway (GraphQL)
talks to:Account client
βAccount server
βPostgres
Product client
βProduct server
βElasticSearch
Order client
βOrder server
βPostgres
+ Kafka
(also communicates with Product service via gRPC)Recommender client
βRecommender server
(Python) βPostgres (Replica)
-
Event Flow:
Order
andProduct
services act as Kafka producers.Recommender
service is a Kafka consumer, ingesting order/product events and updating internal state for recommendations.
- Responsibilities: Register, login, fetch account data, generate JWT tokens.
- Database: PostgreSQL
- Responsibilities: Product CRUD operations, indexing to Elasticsearch, event publishing to Kafka.
- Database: Elasticsearch
- Responsibilities: Order creation, price calculation, data persistence, Kafka event publishing.
- Dependencies: Calls product service to retrieve product info.
- Responsibilities: Kafka consumer that builds recommendations based on product/order events.
- Tech Stack: Python + gRPC + PostgreSQL (replica of product DB)
- Responsibilities: Unified GraphQL endpoint at
/graphql
. - Implementation: Uses gRPC clients for all microservices and schema stitching.
Before running the project, ensure you have the following installed:
git clone https://github.com/rasadov/EcommerceAPI.git
cd ecommercemicroservices
To build and start all services using Docker Compose, run:
docker-compose up --build
This will start:
- Go microservices (
account
,order
,product
,graphql
) - Python-based
recommender
service - Databases: PostgreSQL, Elasticsearch
- Kafka + Zookeeper
- GraphQL gateway
Once everything is running, open your browser to:
-
GraphQL API endpoint:
http://localhost:8080/graphql -
GraphQL Playground (interactive testing):
http://localhost:8080/playground
Below are example GraphQL queries and mutations you can test in the GraphQL Playground.
mutation {
register(account: {
name: "Alice"
email: "[email protected]"
password: "secret123"
}) {
token
}
}
mutation {
login(account: {
email: "[email protected]"
password: "secret123"
}) {
token
}
}
mutation {
createProduct(product: {
name: "Camera"
description: "A digital camera"
price: 99.99
}) {
id
name
}
}
query {
product(pagination: { skip: 0, take: 10 }) {
id
name
price
}
}
mutation {
createOrder(order: {
products: [
{ id: "PRODUCT_ID", quantity: 2 }
]
}) {
id
totalPrice
products {
name
quantity
}
}
}
We welcome contributions! To contribute:
Fork the repository
Create a new branch
Commit and push your changes
Open a Pull Request
Rauf Asadov
GitHub: @rasadov
LinkedIn: Rauf Asadov
Email: [email protected]
This project is licensed under the Apache License 2.0.