A complete microservices architecture built with Go, PostgreSQL, KrakenD API Gateway, and Apache SkyWalking for Application Performance Monitoring (APM).
graph TB
subgraph "Client Layer"
C[Client Applications]
end
subgraph "API Gateway"
K[KrakenD Gateway<br/>:8000]
end
subgraph "Microservices"
U[User Service<br/>:8080]
P[Product Service<br/>:8081]
O[Order Service<br/>:8082]
end
subgraph "Data Layer"
DB1[(PostgreSQL<br/>userdb)]
DB2[(PostgreSQL<br/>productdb)]
DB3[(PostgreSQL<br/>orderdb)]
end
subgraph "Monitoring"
SW[SkyWalking OAP<br/>:11800/:12800]
UI[SkyWalking UI<br/>:8088]
end
C -->|HTTP Requests| K
K -->|Route /api/users| U
K -->|Route /api/products| P
K -->|Route /api/orders| O
U -->|GORM| DB1
P -->|GORM| DB2
O -->|GORM| DB3
U -.->|Traces| SW
P -.->|Traces| SW
O -.->|Traces| SW
SW -->|Data| UI
classDef serviceBox fill:#6a0dad,stroke:#fff,stroke-width:2px,color:#fff
classDef dbBox fill:#2d5aa0,stroke:#fff,stroke-width:2px,color:#fff
classDef monitorBox fill:#ff6b35,stroke:#fff,stroke-width:2px,color:#fff
classDef gatewayBox fill:#28a745,stroke:#fff,stroke-width:2px,color:#fff
class U,P,O serviceBox
class DB1,DB2,DB3 dbBox
class SW,UI monitorBox
class K gatewayBox
- π Microservices Architecture: Independent services for User, Product, and Order management
- π API Gateway: Centralized routing and load balancing with KrakenD
- π APM Monitoring: Complete observability with Apache SkyWalking
- πΎ Database Per Service: Dedicated PostgreSQL databases for each microservice
- π Distributed Tracing: End-to-end request tracing across services
- π³ Docker Compose: One-command deployment and orchestration
- ποΈ Clean Architecture: Repository pattern with layered design
- β‘ High Performance: Built with Go for optimal performance
Component | Technology | Purpose |
---|---|---|
Backend | Go 1.23 | Microservices implementation |
Database | PostgreSQL 13 | Data persistence |
ORM | GORM | Database abstraction |
Web Framework | Gin | HTTP server and routing |
API Gateway | KrakenD | Request routing and aggregation |
APM | Apache SkyWalking | Performance monitoring |
Containerization | Docker & Docker Compose | Service orchestration |
Tracing | Go2Sky | SkyWalking Go agent |
- Docker & Docker Compose
- Go 1.23+ (for development)
- Git
git clone <repository-url>
cd skywalking-basic
The project includes a .env
file with default configuration:
# Database Configuration
DATABASE_URL_USER=postgres://postgres:postgres@localhost:5432/userdb?sslmode=disable
DATABASE_URL_PRODUCT=postgres://postgres:postgres@localhost:5432/productdb?sslmode=disable
DATABASE_URL_ORDER=postgres://postgres:postgres@localhost:5432/orderdb?sslmode=disable
# SkyWalking Configuration
SKYWALKING_OAP=skywalking-oap:11800
# Start the entire stack
docker-compose up -d
# Check service status
docker-compose ps
# Test services
curl http://localhost:8080/health # User Service
curl http://localhost:8081/health # Product Service
curl http://localhost:8082/health # Order Service
curl http://localhost:8000/api/users # Via API Gateway
Method | Endpoint | Description |
---|---|---|
GET | /health |
Health check |
POST | /v1/users |
Create user |
GET | /v1/users |
List users |
GET | /v1/users/:id |
Get user by ID |
PUT | /v1/users/:id |
Update user |
DELETE | /v1/users/:id |
Delete user |
Method | Endpoint | Description |
---|---|---|
GET | /health |
Health check |
POST | /v1/products |
Create product |
GET | /v1/products |
List products |
GET | /v1/products/:id |
Get product by ID |
PUT | /v1/products/:id |
Update product |
DELETE | /v1/products/:id |
Delete product |
Method | Endpoint | Description |
---|---|---|
GET | /health |
Health check |
POST | /v1/orders |
Create order |
GET | /v1/orders |
List orders |
GET | /v1/orders/:id |
Get order by ID |
PUT | /v1/orders/:id |
Update order |
DELETE | /v1/orders/:id |
Delete order |
Method | Endpoint | Description |
---|---|---|
GET | /api/users |
Proxy to User Service |
GET | /api/products |
Proxy to Product Service |
GET | /api/orders |
Proxy to Order Service |
Access the SkyWalking UI at: http://localhost:8088
Features:
- Dashboard: System overview and key metrics
- Topology: Visual service dependency map
- Trace: Detailed request tracing
- Service: Individual service performance
- JVM: Runtime performance metrics
graph LR
subgraph "Service Mesh"
direction TB
A[API Gateway] -->|Discovers| B[User Service]
A -->|Discovers| C[Product Service]
A -->|Discovers| D[Order Service]
B -.->|Reports to| E[SkyWalking OAP]
C -.->|Reports to| E
D -.->|Reports to| E
E -->|Visualizes| F[SkyWalking UI]
end
classDef serviceNode fill:#6a0dad,stroke:#fff,stroke-width:2px,color:#fff
classDef monitorNode fill:#ff6b35,stroke:#fff,stroke-width:2px,color:#fff
class A,B,C,D serviceNode
class E,F monitorNode
skywalking-basic/
βββ cmd/ # Application entry points
β βββ userservice/main.go # User service main
β βββ productservice/main.go # Product service main
β βββ orderservice/main.go # Order service main
βββ internal/ # Private application code
β βββ userservice/ # User service implementation
β β βββ config/ # Configuration
β β βββ handler/ # HTTP handlers
β β βββ model/ # Data models
β β βββ repository/ # Data access layer
β β βββ service/ # Business logic
β βββ productservice/ # Product service implementation
β βββ orderservice/ # Order service implementation
βββ pkg/ # Shared libraries
β βββ database/ # Database utilities
βββ dockerfiles/ # Docker build files
β βββ userservice.Dockerfile
β βββ productservice.Dockerfile
β βββ orderservice.Dockerfile
βββ gateways/ # API Gateway configuration
β βββ krakend.json # KrakenD configuration
βββ scripts/ # Utility scripts
β βββ init-multiple-databases.sh
β βββ start-services.sh
β βββ stop-services.sh
β βββ test-services.sh
βββ docker-compose.yml # Service orchestration
βββ go.mod # Go module dependencies
βββ go.sum # Dependency checksums
βββ .env # Environment variables
- Start Dependencies:
# Start only databases and monitoring
docker-compose up -d postgres skywalking-oap skywalking-ui
- Run Services Locally:
# Terminal 1 - User Service
go run cmd/userservice/main.go
# Terminal 2 - Product Service
go run cmd/productservice/main.go
# Terminal 3 - Order Service
go run cmd/orderservice/main.go
# Run helper scripts
./scripts/test-services.sh
# Generate test data
curl -X POST http://localhost:8080/v1/users \
-H "Content-Type: application/json" \
-d '{"first_name":"John","last_name":"Doe","email":"john@example.com"}'
# Connect to user database
docker exec -it skywalking-basic_postgres_1 psql -U postgres -d userdb
# View tables
\dt
# Check data
SELECT * FROM users;
# Start all services
docker-compose up -d
# Stop all services
docker-compose down
# View logs
docker-compose logs -f userservice
# Scale services
docker-compose up -d --scale userservice=3
# Check all containers
docker-compose ps
# Health check script
./scripts/start-services.sh
- Connection Pooling: Optimized database connections
- Graceful Shutdown: Clean service termination
- Error Handling: Comprehensive error management
- Rate Limiting: Built-in request throttling
- Caching: Response caching strategies
- Load Balancing: Multi-instance support
- Input Validation: JSON schema validation
- SQL Injection Protection: GORM parameterized queries
- CORS Configuration: Cross-origin request handling
- Environment Variables: Secure configuration management
- Fork the repository
- Create a 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
This project is licensed under the MIT License - see the LICENSE file for details.
- Apache SkyWalking for APM capabilities
- KrakenD for API Gateway functionality
- GORM for elegant ORM support
- Gin for high-performance HTTP framework
β Star this repository if you find it helpful!
For questions and support, please open an issue or contribute to the project.