This project demonstrates a microservice architecture implemented in Go, consisting of multiple services that communicate with each other to provide a complete e-commerce solution.
A RESTful API service responsible for managing orders. It communicates with the Inventory Service to check and reserve product stock.
- Tech Stack: Go, Gin, PostgreSQL
- API Type: REST
- Default Port: 8080
View Order Service Documentation
A gRPC service responsible for managing product inventory.
- Tech Stack: Go, gRPC, PostgreSQL
- API Type: gRPC
- Default Port: 9090
View Inventory Service Documentation
The system follows a microservice architecture pattern:
- Order Service: Handles order creation and management
- Inventory Service: Manages product inventory and stock reservation
Services communicate using gRPC for efficient inter-service communication.
┌─────────────────┐ ┌─────────────────┐
│ │ │ │
│ Order Service │◄─────┤ Inventory Service│
│ (REST API) │ │ (gRPC) │
│ │ │ │
└────────┬────────┘ └────────┬────────┘
│ │
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ │ │ │
│ Order Database │ │Inventory Database│
│ (PostgreSQL) │ │ (PostgreSQL) │
│ │ │ │
└─────────────────┘ └─────────────────┘
-
Client Request Flow:
- Client sends HTTP request to Order Service
- Order Service processes the request
- If inventory check is needed, Order Service calls Inventory Service via gRPC
- Order Service responds to client with HTTP response
-
Inter-Service Communication:
- Order Service acts as a gRPC client
- Inventory Service acts as a gRPC server
- Protocol Buffers are used for data serialization
- Service discovery is handled via environment variables
- Database per Service: Each microservice has its own database
- API Gateway: Order Service acts as an entry point for clients
- Service-to-Service Communication: gRPC is used for efficient communication between services
- Event-Driven Architecture: Services communicate asynchronously when appropriate
Each service has its own PostgreSQL database to ensure service independence and data isolation.
- Go 1.16+
- Docker and Docker Compose
- PostgreSQL
# Start all services and databases
docker-compose up
# Start specific service
docker-compose up order-serviceThe docker-compose configuration includes auto seeding for the inventory service. When you start the services using docker-compose, the inventory database will be automatically populated with sample data. This feature is enabled by setting the RUN_SEEDER=true environment variable in the docker-compose.yml file.
To disable auto seeding, edit the docker-compose.yml file and set RUN_SEEDER=false or remove the environment variable.
# Start Order Service
cd order-service
go run cmd/main.go
# Start Inventory Service
cd inventory-service
go run cmd/main.go# Run tests for all services
make test
# Build all services
make build
# Seed inventory database with sample data
make seed-inventory├── order-service/ # Order management service
├── inventory-service/ # Inventory management service
├── proto/ # Protocol Buffers definitions
├── docker-compose.yml # Docker Compose configuration
└── Makefile # Build and development commands