How tusmasoma/go-microservice-k8s works
Project Type and Purpose
• This is a microservices application written in Go. It uses Kubernetes (Minikube for local development) to deploy multiple services – catalog, customer, order, and gateway – each of which is containerized using Docker.
• The README explains how to deploy these services on Minikube, indicating that the project is geared toward a cloud-native, containerized microservices architecture. The use of Kubernetes manifests (YAML files under the k8s directory) and Dockerfiles suggests a production-like deployment environment.
• The existence of gRPC protocol buffers (in the proto directory) indicates that the services may communicate via gRPC for high-performance RPC calls.
Analyzing the File Structure
• Top-Level Directories:
• "go/services": Contains individual microservices (catalog, customer, order, gateway) with separate folders for API handling, command-line entry points (main.go), database access (both real and mock), and entities.
• "docker": Includes Dockerfiles for each microservice and a shared MySQL instance, indicating containerized deployment for easy scaling and isolation.
• "k8s": Contains Kubernetes deployment and service YAMLs for each microservice, shared MySQL configuration, and ingress rules.
• "proto": Houses gRPC protocol definitions for all services, used to generate server and client stubs.
• Other folders like "go/pkg" and "migrations" indicate common libraries (for configuration, logging, request/response handling, etc.) and database initialization scripts.
Main Components
a. Microservices:
• Catalog Service (handles catalog items)
• Customer Service (manages customer data)
• Order Service (handles orders)
• Gateway Service (acts as the entry point – likely the API gateway – routing requests to other services)
b. Shared and External Components:
• MySQL Database: A shared stateful database running under Kubernetes (as seen in k8s/shared-mysql-statefulset.yaml and related files).
• Kubernetes Cluster: This encapsulates all deployments, service definitions, and ingress. Include the ingress controller (managed by Minikube addons) which facilitates external access.
Relationships and Interactions
• The Gateway Service is the external interface receiving incoming HTTP/gRPC requests. It routes these requests to the appropriate microservice (Catalog, Customer, or Order) based on the URL/path.
• Each microservice has its own API layer and interacts with its respective logic and data layers.
• All persistent data is stored in a shared MySQL instance, and each service’s database repository layer abstracts the connection to MySQL. Some services include a “mock” subdirectory for testing, indicating an abstraction layer.
• gRPC is used for inter-service or client-to-service communication, given the presence of protocol buffers and generated stubs in the proto folders.
Architectural Patterns and Design Principles
• Microservices: Individual services are decoupled, each handling domain-specific logic.
• API Gateway: The gateway service encapsulates web-level logic and provides a unified entry point.
• Containerization and Orchestration: Using Docker and Kubernetes to manage service deployments and scaling.
• Layering: Separation of concerns between API, business logic (entities and command handlers), and data access (database and repository layers).
• Testability: Provision of “mock” implementations in database packages points to an emphasis on unit and integration testing.