A scalable, cloud-native e-commerce platform built with microservices architecture using Go, gRPC, GraphQL, and Docker.
This is a production-ready e-commerce microservices application that demonstrates modern backend architecture patterns. The system is composed of four independent services that communicate via gRPC, unified behind a GraphQL API gateway:
- Account Service: Manages user account creation and retrieval
- Catalog Service: Handles product management with advanced search capabilities
- Order Service: Processes and manages customer orders
- GraphQL Gateway: Provides a unified API endpoint for client applications
Each microservice is independently deployable, scalable, and maintains its own database following the database-per-service pattern.
-
Microservices Architecture
- Independent service deployment and scaling
- Fault isolation - failure in one service doesn't crash the entire system
- Technology flexibility - each service can use optimal technologies
- Easier maintenance and testing of smaller codebases
-
Polyglot Persistence
- PostgreSQL for transactional data (Account & Order services)
- Elasticsearch for product search and catalog (Catalog service)
- Each service uses the database best suited for its needs
-
API Gateway Pattern
- Single entry point for clients via GraphQL
- Reduces client complexity by aggregating multiple service calls
- Provides flexible querying capabilities with GraphQL
-
Service Communication
- gRPC for efficient inter-service communication
- Protocol Buffers for strongly-typed contracts
- High performance with HTTP/2 and binary serialization
- Docker & Docker Compose
- Go 1.25.1 or higher (for local development)
- Protocol Buffer compiler (for modifying .proto files)
-
Clone the repository
git clone <repository-url> cd ecom-microservice
-
Start all services with Docker Compose
docker-compose up --build
-
Access the GraphQL Playground
Open your browser and navigate to:
http://localhost:8000/playground
┌─────────────┐
│ Clients │
└──────┬──────┘
│
▼
┌─────────────────┐
│ GraphQL Gateway │ :8000
│ (Port 8080) │
└────────┬────────┘
│
┌────┴─────┬──────────┐
▼ ▼ ▼
┌─────────┐ ┌──────────┐ ┌────────┐
│ Account │ │ Catalog │ │ Order │
│ Service │ │ Service │ │Service │
│ :8080 │ │ :8080 │ │ :8080 │
└────┬────┘ └────┬─────┘ └───┬────┘
│ │ │
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│PostgreSQL│ │Elastic- │ │PostgreSQL│
│ DB │ │ search │ │ DB │
└──────────┘ └──────────┘ └──────────┘
| Service | Internal Port | External Port | Protocol |
|---|---|---|---|
| GraphQL Gateway | 8080 | 8000 | HTTP/GraphQL |
| Account Service | 8080 | - | gRPC |
| Catalog Service | 8080 | - | gRPC |
| Order Service | 8080 | - | gRPC |
Create an Account
mutation {
createAccount(account: { name: "John Doe" }) {
id
name
}
}Create a Product
mutation {
createProduct(product: {
name: "Laptop"
description: "High-performance laptop"
price: 999.99
}) {
id
name
price
}
}Create an Order
mutation {
createOrder(order: {
accountId: "account-id-here"
products: [
{ id: "product-id-here", quantity: 2 }
]
}) {
id
totalPrice
createdAt
products {
name
quantity
price
}
}
}Query Products with Search
query {
products(query: "laptop", pagination: { skip: 0, take: 10 }) {
id
name
description
price
}
}Query Account with Orders
query {
accounts(id: "account-id-here") {
id
name
orders {
id
totalPrice
createdAt
products {
name
quantity
}
}
}
}| Technology | Purpose | Version |
|---|---|---|
| Go | Primary programming language | 1.25.1 |
| gRPC | Inter-service communication | v1.75.1 |
| Protocol Buffers | Service contract definitions | v1.36.6 |
| GraphQL | Client-facing API | - |
| Docker | Containerization | Latest |
| Docker Compose | Multi-container orchestration | Latest |
| Database | Service | Purpose |
|---|---|---|
| PostgreSQL | Account, Order | Relational data storage |
| Elasticsearch | Catalog | Product search and indexing |
- gqlgen (v0.17.78) - GraphQL server generation
- lib/pq (v1.10.9) - PostgreSQL driver
- go-elasticsearch (v9.1.0) - Elasticsearch client
- kelseyhightower/envconfig (v1.4.0) - Environment variable configuration
- segmentio/ksuid (v1.0.4) - Unique ID generation
- tinrab/retry (v1.0.0) - Retry logic for database connections
- Protocol Buffer Compiler (protoc) - Generate Go code from .proto files
- gqlgen - Generate GraphQL resolvers and models
ecom-microservice/
├── account/ # Account microservice
│ ├── account.proto # gRPC service definition
│ ├── cmd/account/ # Service entry point
│ ├── pb/ # Generated protobuf code
│ ├── repository.go # Database layer
│ ├── service.go # Business logic
│ ├── server.go # gRPC server
│ ├── client.go # gRPC client
│ ├── up.sql # Database schema
│ └── .Dockerfile # Container definitions
│
├── catalog/ # Catalog microservice
│ ├── catalog.proto # gRPC service definition
│ ├── cmd/catalog/ # Service entry point
│ ├── pb/ # Generated protobuf code
│ ├── repository.go # Elasticsearch layer
│ ├── service.go # Business logic
│ ├── server.go # gRPC server
│ └── client.go # gRPC client
│
├── order/ # Order microservice
│ ├── order.proto # gRPC service definition
│ ├── cmd/order/ # Service entry point
│ ├── pb/ # Generated protobuf code
│ ├── repository.go # Database layer
│ ├── service.go # Business logic
│ ├── server.go # gRPC server
│ ├── client.go # gRPC client
│ └── up.sql # Database schema
│
├── graphql/ # GraphQL API Gateway
│ ├── schema.graphql # GraphQL schema
│ ├── main.go # Gateway entry point
│ ├── graph.go # GraphQL server setup
│ ├── _resolver.go # Resolver implementations
│ └── models.go # GraphQL models
│
├── docker-compose.yml # Development environment
├── docker-compose.prod.yml # Production environment
└── go.mod # Go dependencies
When you modify .proto files:
cd account
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
account.protoWhen you modify schema.graphql:
cd graphql
go run github.com/99designs/gqlgen generateEach service can be run independently:
# Account Service
cd account/cmd/account
DATABASE_URL=postgres://postgres:admin@localhost:5432/postgres?sslmode=disable go run main.go
# Catalog Service
cd catalog/cmd/catalog
ELASTICSEARCH_URL=http://localhost:9200 go run main.go
# Order Service
cd order/cmd/order
DATABASE_URL=postgres://postgres:admin@localhost:5432/postgres?sslmode=disable \
ACCOUNT_SERVICE_URL=localhost:8080 \
CATALOG_SERVICE_URL=localhost:8080 go run main.go
# GraphQL Gateway
cd graphql
ACCOUNT_SERVICE_URL=localhost:8080 \
CATALOG_SERVICE_URL=localhost:8080 \
ORDER_SERVICE_URL=localhost:8080 go run main.goDATABASE_URL- PostgreSQL connection string
ELASTICSEARCH_URL- Elasticsearch endpoint
DATABASE_URL- PostgreSQL connection stringACCOUNT_SERVICE_URL- Account service gRPC endpointCATALOG_SERVICE_URL- Catalog service gRPC endpoint
ACCOUNT_SERVICE_URL- Account service gRPC endpointCATALOG_SERVICE_URL- Catalog service gRPC endpointORDER_SERVICE_URL- Order service gRPC endpoint
- ✅ Microservices architecture with domain-driven design
- ✅ gRPC for efficient inter-service communication
- ✅ GraphQL API with playground for easy testing
- ✅ Database per service pattern
- ✅ Full-text search with Elasticsearch
- ✅ Docker containerization
- ✅ Automatic retry logic for database connections
- ✅ Environment-based configuration
- ✅ Unique ID generation with KSUID
- ✅ Pagination support for listing operations
Aditya Pandey