A production-grade microservice-based e-commerce platform built with Go, featuring gRPC inter-service communication, GraphQL API gateway, PostgreSQL & Elasticsearch databases, all orchestrated with Docker Compose.
- Executive Summary
- Architecture Overview
- Tech Stack
- Service Breakdown
- Getting Started
- API Reference
- Project Structure
- Configuration
- Development Guide
- Risks & Considerations
This project demonstrates a cloud-native microservices architecture implementing an e-commerce domain with:
| Component | Technology |
|---|---|
| API Gateway | GraphQL (gqlgen) |
| Inter-Service Communication | gRPC with Protocol Buffers |
| Account Database | PostgreSQL |
| Catalog Database | Elasticsearch |
| Order Database | PostgreSQL |
| Containerization | Docker Compose |
The system follows Domain-Driven Design (DDD) principles with clear service boundaries, ensuring scalability, maintainability, and independent deployment capabilities.
flowchart TB
subgraph Client Layer
WEB[π Web Client]
MOBILE[π± Mobile Client]
end
subgraph API Gateway
GQL[π‘ GraphQL Gateway<br/>Port: 8000]
end
subgraph Microservices
ACC[π€ Account Service<br/>gRPC :8080]
CAT[π¦ Catalog Service<br/>gRPC :8080]
ORD[π Order Service<br/>gRPC :8080]
end
subgraph Data Layer
PG_ACC[(π PostgreSQL<br/>Account DB)]
ES[(π Elasticsearch<br/>Catalog DB)]
PG_ORD[(π PostgreSQL<br/>Order DB)]
end
WEB --> GQL
MOBILE --> GQL
GQL -->|gRPC| ACC
GQL -->|gRPC| CAT
GQL -->|gRPC| ORD
ORD -->|gRPC| ACC
ORD -->|gRPC| CAT
ACC --> PG_ACC
CAT --> ES
ORD --> PG_ORD
classDef gateway fill:#e1f5fe,stroke:#01579b
classDef service fill:#f3e5f5,stroke:#4a148c
classDef database fill:#e8f5e9,stroke:#1b5e20
class GQL gateway
class ACC,CAT,ORD service
class PG_ACC,ES,PG_ORD database
sequenceDiagram
autonumber
participant C as Client
participant G as GraphQL Gateway
participant A as Account Service
participant P as Catalog Service
participant O as Order Service
participant DB as Databases
rect rgb(240, 248, 255)
Note over C,G: Query Flow
C->>G: GraphQL Query
G->>A: GetAccount (gRPC)
A->>DB: SELECT FROM accounts
DB-->>A: Account Data
A-->>G: Account Response
G-->>C: GraphQL Response
end
rect rgb(255, 248, 240)
Note over C,O: Order Creation Flow
C->>G: createOrder Mutation
G->>O: PostOrder (gRPC)
O->>A: Validate Account
A-->>O: Account Valid
O->>P: Get Product Details
P-->>O: Product Data
O->>DB: INSERT INTO orders
DB-->>O: Order Created
O-->>G: Order Response
G-->>C: GraphQL Response
end
flowchart LR
subgraph Docker Network
subgraph Services
GQL[graphql<br/>:8000β:8080]
ACC[account<br/>:8080]
CAT[catalog<br/>:8080]
ORD[order<br/>:8080]
end
subgraph Databases
ACC_DB[(account_db<br/>PostgreSQL)]
CAT_DB[(catalog_db<br/>Elasticsearch)]
ORD_DB[(order_db<br/>PostgreSQL)]
end
end
EXT[External<br/>:8000] --> GQL
GQL -.-> ACC
GQL -.-> CAT
GQL -.-> ORD
ORD -.-> ACC
ORD -.-> CAT
ACC --> ACC_DB
CAT --> CAT_DB
ORD --> ORD_DB
erDiagram
ACCOUNT {
string id PK
string name
}
PRODUCT {
string id PK
string name
string description
float price
}
ORDER {
string id PK
string account_id FK
timestamp created_at
timestamp updated_at
float total_price
}
ORDER_PRODUCT {
string order_id FK
string product_id FK
int quantity
}
ACCOUNT ||--o{ ORDER : places
ORDER ||--o{ ORDER_PRODUCT : contains
PRODUCT ||--o{ ORDER_PRODUCT : included_in
| Layer | Technology | Purpose |
|---|---|---|
| Language | Go 1.24.4 | Core service implementation |
| API Gateway | gqlgen v0.17.85 | GraphQL schema-first development |
| RPC Framework | gRPC + Protobuf | High-performance service-to-service communication |
| Account DB | PostgreSQL | ACID-compliant relational data storage |
| Catalog DB | Elasticsearch 6.2.4 | Full-text search & product catalog |
| Order DB | PostgreSQL | Transactional order processing |
| Container | Docker Compose | Multi-container orchestration |
| ID Generation | KSUID | Sortable, unique identifiers |
The API Gateway exposes a unified GraphQL endpoint for all client interactions.
Key Features:
- Schema-first GraphQL design
- Playground available at
/playground - Aggregates data from all microservices
- Connection pooling to backend services
Exposed Endpoints:
| Endpoint | Description |
|---|---|
POST /graphql |
GraphQL API endpoint |
GET /playground |
GraphQL Playground IDE |
GraphQL Schema:
type Query {
accounts(pagination: PaginationInput, id: String): [Account!]!
products(pagination: PaginationInput, query: String, id: String): [Product!]!
}
type Mutation {
createAccount(input: AccountInput!): Account
createProduct(input: ProductInput!): Product
createOrder(input: OrderInput!): Order
}Manages user account lifecycle with PostgreSQL persistence.
Architecture Pattern: Repository Pattern with Service Layer
flowchart LR
CLIENT[gRPC Client] --> SERVER[gRPC Server]
SERVER --> SERVICE[Account Service]
SERVICE --> REPO[PostgreSQL Repository]
REPO --> DB[(PostgreSQL)]
API Operations:
| RPC Method | Description |
|---|---|
PostAccount |
Create new account |
GetAccount |
Retrieve account by ID |
GetAccounts |
List accounts with pagination |
Data Model:
type Account struct {
ID string `json:"id"`
Name string `json:"name"`
}Product catalog management powered by Elasticsearch for full-text search.
Key Features:
- Full-text product search
- Batch product retrieval by IDs
- Pagination support
API Operations:
| RPC Method | Description |
|---|---|
PostProduct |
Add new product |
GetProduct |
Get product by ID |
GetProducts |
Search/list products with filters |
Data Model:
type Product struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Price float64 `json:"price"`
}Orchestrates order processing with cross-service coordination.
Key Features:
- Account validation via Account Service
- Product enrichment via Catalog Service
- Order persistence in PostgreSQL
- Total price calculation
API Operations:
| RPC Method | Description |
|---|---|
PostOrder |
Create new order |
GetOrdersForAccount |
Get all orders for an account |
Order Flow:
flowchart TD
A[Receive Order Request] --> B{Validate Account}
B -->|Invalid| C[Return Error]
B -->|Valid| D[Fetch Product Details]
D --> E[Calculate Total Price]
E --> F[Persist Order]
F --> G[Return Order Response]
- Docker & Docker Compose
- Go 1.24+ (for development)
- Protocol Buffer Compiler (for proto changes)
# Clone the repository
git clone https://github.com/suryanshp1/go-microservice.git
cd go-microservice
# Start all services
docker-compose up --build
# Access GraphQL Playground
open http://localhost:8000/playgroundflowchart TD
A[account_db] --> B[account]
C[catalog_db] --> D[catalog]
E[order_db] --> F[order]
B --> G[graphql]
D --> G
F --> G
mutation {
createAccount(input: { name: "John Doe" }) {
id
name
}
}mutation {
createProduct(input: {
name: "Laptop"
description: "High-performance laptop"
price: 999.99
}) {
id
name
price
}
}mutation {
createOrder(input: {
accountId: "2KxQjP7mGqSz8tB1n4v3wR"
products: [
{ id: "product-id-1", quantity: 2 }
{ id: "product-id-2", quantity: 1 }
]
}) {
id
totalPrice
products {
name
quantity
price
}
}
}query {
accounts(id: "account-id") {
id
name
orders {
id
totalPrice
createdAt
products {
name
price
quantity
}
}
}
}query {
products(query: "laptop", pagination: { skip: 0, take: 10 }) {
id
name
description
price
}
}go-microservice/
βββ π account/ # Account Microservice
β βββ account.proto # gRPC service definition
β βββ app.dockerfile # Service container
β βββ db.dockerfile # PostgreSQL container
β βββ client.go # gRPC client
β βββ server.go # gRPC server
β βββ service.go # Business logic
β βββ repository.go # Data access layer
β βββ up.sql # Database migrations
β βββ cmd/ # Service entrypoint
β βββ pb/ # Generated protobuf code
β
βββ π catalog/ # Catalog Microservice
β βββ catalog.proto # gRPC service definition
β βββ app.dockerfile # Service container
β βββ client.go # gRPC client
β βββ server.go # gRPC server
β βββ service.go # Business logic
β βββ repository.go # Elasticsearch repository
β βββ cmd/ # Service entrypoint
β βββ pb/ # Generated protobuf code
β
βββ π order/ # Order Microservice
β βββ order.proto # gRPC service definition
β βββ app.dockerfile # Service container
β βββ db.dockerfile # PostgreSQL container
β βββ client.go # gRPC client
β βββ server.go # gRPC server + orchestration
β βββ service.go # Business logic
β βββ repository.go # Data access layer
β βββ up.sql # Database migrations
β βββ cmd/ # Service entrypoint
β βββ pb/ # Generated protobuf code
β
βββ π graphql/ # GraphQL Gateway
β βββ schema.graphql # GraphQL schema
β βββ main.go # HTTP server entrypoint
β βββ graph.go # GraphQL server setup
β βββ *_resolver.go # GraphQL resolvers
β βββ models_gen.go # Generated models
β βββ generated.go # Generated runtime
β βββ gqlgen.yml # Code generation config
β
βββ π diagrams/ # Architecture diagrams
βββ π vendor/ # Go dependencies
βββ docker-compose.yaml # Container orchestration
βββ go.mod # Go module definition
βββ go.sum # Dependency checksums
| Service | Variable | Description | Default |
|---|---|---|---|
| account | DATABASE_URL |
PostgreSQL connection string | - |
| catalog | DATABASE_URL |
Elasticsearch URL | - |
| order | DATABASE_URL |
PostgreSQL connection string | - |
| order | ACCOUNT_SERVICE_URL |
Account service gRPC address | - |
| order | CATALOG_SERVICE_URL |
Catalog service gRPC address | - |
| graphql | ACCOUNT_SERVICE_URL |
Account service gRPC address | - |
| graphql | CATALOG_SERVICE_URL |
Catalog service gRPC address | - |
| graphql | ORDER_SERVICE_URL |
Order service gRPC address | - |
# Install protoc plugins
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# Regenerate Go code (example for account service)
cd account
protoc --go_out=./ --go-grpc_out=./ account.protocd graphql
go run github.com/99designs/gqlgen generate# Account Service
DATABASE_URL=postgres://user:pass@localhost/db go run ./account/cmd
# Catalog Service
DATABASE_URL=http://localhost:9200 go run ./catalog/cmd
# Order Service
DATABASE_URL=postgres://user:pass@localhost/db \
ACCOUNT_SERVICE_URL=localhost:8080 \
CATALOG_SERVICE_URL=localhost:8081 \
go run ./order/cmd| Risk | Impact | Mitigation |
|---|---|---|
| Single Point of Failure (GraphQL Gateway) | High | Deploy multiple instances with load balancer |
| No Authentication/Authorization | Critical | Implement JWT/OAuth2 before production |
| Hardcoded Credentials | Critical | Use secrets management (Vault, K8s secrets) |
| No Rate Limiting | Medium | Add rate limiting at gateway level |
| Elasticsearch v6.2.4 EOL | Medium | Upgrade to Elasticsearch 8.x |
| No Distributed Tracing | Medium | Integrate OpenTelemetry/Jaeger |
| No Health Checks | Medium | Implement /health endpoints |
| No Circuit Breaker | Medium | Add resilience patterns (hystrix, go-kit) |
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request