A secure, scalable, and modular E-commerce backend system using a microservices-based architecture. The system is developed in Go and leverages modern tools like gRPC, GraphQL, Docker, PostgreSQL, and ElasticSearch.
The application is divided into distinct services:
account: Manages user authentication and profilecatalog: Handles product listings and searchorder: Manages orders and transactions
Each service is containerized using Docker and communicates efficiently over gRPC. A centralized GraphQL gateway provides a unified API interface to clients, enabling flexible querying and streamlined frontend integration.
Go – Core backend language for all microservicesgRPC – Fast and type-safe service-to-service communication
GraphQL – Centralized API gateway
Docker – Containerization of services
Docker Compose – Local orchestration
PostgreSQL – Relational data storage
- Microservices Architecture: Account, Catalog, and Order services, each with clear boundaries
- gRPC Communication: Enables high-performance and efficient communication
- GraphQL Gateway: Serves as the single API entry point for all clients
- Containerization with Docker: Simplifies deployment and testing of individual services
- Database Integration:
PostgreSQLfor structured relational dataElasticsearchfor product search in the catalog
- Docker Compose: Streamlines local development by orchestrating all services
The project consists of the following main components:
- Account Service
- Catalog Service
- Order Service
- GraphQL API Gateway
Each service has its own database:
- Account and Order services use PostgreSQL
- Catalog service uses Elasticsearch
-
Clone the repository:
git clone <repository-url> cd <project-directory> -
Start the services using Docker Compose:
docker compose up -
Access the GraphQL playground at
http://localhost:8000/playground
To generate Go code from your .proto files, run:
protoc --go_out=./pb --go-grpc_out=./pb account.proto
To install protoc:
brew install protoc
You need these plugins installed:
protoc-gen-goprotoc-gen-go-grpc
Run these commands:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
Make sure your Go binaries path is in your PATH environment variable. Add this line to your shell profile (~/.bashrc or ~/.zshrc):
export PATH="$PATH:$(go env GOPATH)/bin"
Reload your shell or run source ~/.bashrc (or your profile) after adding the line.
Now protoc can find the plugins and generate Go and gRPC code correctly.
The GraphQL API provides a unified interface to interact with all the microservices.
query {
accounts {
id
name
}
}mutation {
createAccount(account: { name: "New Account" }) {
id
name
}
}query {
products {
id
name
price
}
}mutation {
createProduct(
product: { name: "New Product", description: "A new product", price: 19.99 }
) {
id
name
price
}
}mutation {
createOrder(
order: {
accountId: "account_id"
products: [{ id: "product_id", quantity: 2 }]
}
) {
id
totalPrice
products {
name
quantity
}
}
}query {
accounts(id: "account_id") {
name
orders {
id
createdAt
totalPrice
products {
name
quantity
price
}
}
}
}query {
products(pagination: { skip: 0, take: 5 }, query: "search_term") {
id
name
description
price
}
}query {
accounts(id: "account_id") {
name
orders {
totalPrice
}
}
}After the app is up and running, ElasticSearch DB can be accessed at:
http://localhost:9200
To check all indices visit:
http://localhost:9200/_cat/indices?v
To check all documents in the catalog index:
http://localhost:9200/catalog/_search?pretty
PostgreSQL can be accessed and used via CLI (Command Line Interface) After the app is up and running, in the terminal follow the below commands:
docker exec -it <container_id_for_accountDB> psql -U <db_username> -d <db_name>
Once you are in the PostgreSQL CLI, use the following commands:
To view tables:
\dt
To view accounts information:
SELECT * FROM accounts;
PostgreSQL can be accessed and used via CLI (Command Line Interface) After the app is up and running, in the terminal follow the below commands:
docker exec -it <container_id_for_orderDB> psql -U <db_username> -d <db_name>
Once you are in the PostgreSQL CLI, use the following commands:
To view tables:
\dt
To view orders information:
SELECT * FROM order;