Skip to content

A complete microservices architecture built with Go, PostgreSQL, KrakenD API Gateway, and Apache SkyWalking for Application Performance Monitoring (APM).

License

Notifications You must be signed in to change notification settings

ozturkeniss/Skywalking-Basic-Topology

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Go Microservices with SkyWalking APM

A complete microservices architecture built with Go, PostgreSQL, KrakenD API Gateway, and Apache SkyWalking for Application Performance Monitoring (APM).

πŸ—οΈ Architecture

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
Loading

✨ Features

  • πŸ”„ 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

πŸ› οΈ Tech Stack

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

πŸš€ Quick Start

Prerequisites

  • Docker & Docker Compose
  • Go 1.23+ (for development)
  • Git

1. Clone Repository

git clone <repository-url>
cd skywalking-basic

2. Environment Setup

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

3. Start All Services

# Start the entire stack
docker-compose up -d

# Check service status
docker-compose ps

4. Verify Deployment

# 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

πŸ“‘ API Endpoints

User Service (Port 8080)

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

Product Service (Port 8081)

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

Order Service (Port 8082)

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

API Gateway (Port 8000)

Method Endpoint Description
GET /api/users Proxy to User Service
GET /api/products Proxy to Product Service
GET /api/orders Proxy to Order Service

πŸ“Š Monitoring & Observability

SkyWalking Dashboard

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

Service Discovery

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
Loading

πŸ—οΈ Project Structure

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

πŸ”§ Development

Local Development Setup

  1. Start Dependencies:
# Start only databases and monitoring
docker-compose up -d postgres skywalking-oap skywalking-ui
  1. 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

Testing

# 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"}'

Database Management

# Connect to user database
docker exec -it skywalking-basic_postgres_1 psql -U postgres -d userdb

# View tables
\dt

# Check data
SELECT * FROM users;

🐳 Docker Operations

Service Management

# 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

Health Checks

# Check all containers
docker-compose ps

# Health check script
./scripts/start-services.sh

πŸ“ˆ Performance Features

  • 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

πŸ”’ Security

  • Input Validation: JSON schema validation
  • SQL Injection Protection: GORM parameterized queries
  • CORS Configuration: Cross-origin request handling
  • Environment Variables: Secure configuration management

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments


⭐ Star this repository if you find it helpful!

For questions and support, please open an issue or contribute to the project.

About

A complete microservices architecture built with Go, PostgreSQL, KrakenD API Gateway, and Apache SkyWalking for Application Performance Monitoring (APM).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published