Skip to content

Adityatorgal17/go-micro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Go Microservices Architecture

A comprehensive microservices application built with Go, featuring multiple communication patterns including HTTP, RPC, gRPC, and message queuing with RabbitMQ.

πŸ—οΈ Architecture Overview

This project demonstrates a complete microservices ecosystem where users interact through a browser with a central Broker Service that orchestrates communication with various specialized microservices. The architecture showcases multiple inter-service communication patterns including HTTP/JSON, RPC, gRPC, and asynchronous messaging via RabbitMQ.

Communication Flow:

🌐 User (Browser) β†’ Broker Service (Docker) β†’ Microservices

The Broker Service acts as an API Gateway, routing requests to appropriate services using:

  • πŸ”„ JSON/HTTP: Direct REST API calls to Auth and Mail services
  • ⚑ RPC: Traditional Remote Procedure Calls to Logger service
  • πŸš€ gRPC: High-performance Protocol Buffer communication to Logger service
  • πŸ“¨ RabbitMQ: Asynchronous message queuing to Listener service

External Dependencies:

  • PostgreSQL: User authentication data
  • MongoDB: Centralized logging storage
  • RabbitMQ: Message queue for asynchronous processing
  • MailHog: SMTP testing and email delivery

πŸš€ Services

Core Services

Service Port Description Communication
Frontend Service 8081 Web interface with HTML templates HTTP to Broker
Broker Service 8080 API Gateway and service orchestrator HTTP, RPC, gRPC, RabbitMQ
Authentication Service 8081 User authentication and authorization HTTP, PostgreSQL
Logger Service - Centralized logging with multiple interfaces RPC (5001), gRPC (50001), MongoDB
Mail Service 8082 Email sending service HTTP, MailHog
Listener Service 8083 RabbitMQ message consumer RabbitMQ Consumer

Infrastructure Services

Service Port Description
PostgreSQL 5432 Database for authentication service
MongoDB 27017 Database for logging service
RabbitMQ 5672, 15672 Message queue and management UI
MailHog 1025, 8025 SMTP testing tool

πŸ”„ Communication Patterns

1. HTTP REST API

  • Frontend ↔ Broker Service
  • Broker ↔ Authentication Service
  • Broker ↔ Mail Service

2. RPC (Remote Procedure Call)

  • Broker β†’ Logger Service (Port 5001)
  • Traditional Go net/rpc implementation

3. gRPC (Google RPC)

  • Broker β†’ Logger Service (Port 50001)
  • Protocol Buffer based communication

4. Message Queue (RabbitMQ)

  • Broker β†’ RabbitMQ β†’ Listener Service
  • Asynchronous message processing
  • Event-driven architecture

πŸ› οΈ Technologies Used

  • Language: Go 1.23+
  • Web Framework: Chi Router
  • Databases: PostgreSQL, MongoDB
  • Message Queue: RabbitMQ
  • Communication: HTTP, RPC, gRPC, AMQP
  • Containerization: Docker & Docker Compose
  • Build Tool: Make

πŸ“‹ Available Make Commands

Command Description
make up Start all containers in background
make up_build Build and start all containers
make down Stop all containers
make build_broker Build broker service binary
make build_auth Build authentication service binary
make build_logger Build logger service binary
make build_mail Build mail service binary
make build_listener Build listener service binary
make build_front Build frontend service binary
make start Start frontend in development mode
make stop Stop frontend development server

πŸ” Service Endpoints

Frontend Service (http://localhost:8081)

  • GET /: Main application interface

Broker Service (http://localhost:8080)

  • POST /: Main broker endpoint
  • POST /handle: Route requests to appropriate services
  • POST /log-grpc: Test gRPC logging

Authentication Service (http://localhost:8081)

  • POST /authenticate: User login
  • Validates credentials against PostgreSQL database

Mail Service (http://localhost:8082)

  • POST /send: Send email via MailHog

RabbitMQ Management (http://localhost:15672)

  • Username: guest
  • Password: guest
  • Email testing interface

πŸ”„ Request Flow Examples

1. User Authentication

Frontend β†’ Broker Service β†’ Authentication Service β†’ PostgreSQL

2. Logging (Multiple Options)

Frontend β†’ Broker Service β†’ Logger Service (HTTP)
Frontend β†’ Broker Service β†’ Logger Service (RPC)
Frontend β†’ Broker Service β†’ Logger Service (gRPC)

3. Asynchronous Logging

Frontend β†’ Broker Service β†’ RabbitMQ β†’ Listener Service β†’ Logger Service

4. Email Sending

Frontend β†’ Broker Service β†’ Mail Service β†’ MailHog

πŸ—„οΈ Database Schemas

PostgreSQL (Authentication)

  • Database: users
  • Table: users (id, email, password_hash, created_at, updated_at)

MongoDB (Logging)

  • Database: logs
  • Collection: logs (name, data, created_at)

πŸ”§ Environment Configuration

Key environment variables used across services:

# Database connections
DSN="host=postgres port=5432 user=postgres password=password dbname=users sslmode=disable"
MONGO_URL="mongodb://mongo:27017"

# Mail configuration
MAIL_HOST=mailhog
MAIL_PORT=1025
FROM_ADDRESS=noreply@example.com
FROM_NAME="Aditya Torgal"

# RabbitMQ
RABBITMQ_URL="amqp://guest:guest@rabbitmq"

πŸ§ͺ Testing the Application

  1. Start all services:

    cd project && make up_build
  2. Access the frontend: Open http://localhost:8081 in your browser

  3. Test different communication patterns:

  4. View logs:

    docker-compose logs -f [service-name]

πŸ“Š Monitoring & Debugging

πŸ‘¨β€πŸ’» Author

Aditya Torgal

This project demonstrates modern microservices architecture patterns using Go, showcasing different inter-service communication methods and containerized deployment strategies.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors