README
ΒΆ
gRPC Ticket Management System
A distributed ticket management system built with gRPC, Go, and PostgreSQL. This project demonstrates a complete microservices architecture with protocol buffers for service definitions, Docker containerization, and database persistence.
ποΈ Architecture
βββββββββββββββββββ gRPC βββββββββββββββββββ SQL βββββββββββββββββββ
β gRPC Client β ββββββββββΊ β Ticket Service β βββββββββΊ β PostgreSQL β
β (Port 50052) β β (Port 50051) β β (Port 5432) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
Components
- gRPC Server (
ticket-service-db/): Core ticket management service with PostgreSQL integration - gRPC Client (
grpc-client/): Example client demonstrating API usage - PostgreSQL Database: Persistent storage for tickets with proper indexing
- Protocol Buffers (
proto/): Service definitions and data contracts
π Features
- CRUD Operations: Create, Read, Update, Delete tickets
- Ticket Management:
- Multiple status levels (Open, In Progress, Resolved, Closed)
- Priority levels (Low, Medium, High, Critical)
- Assignee and reporter tracking
- Tagging system with JSON support
- Database Integration: PostgreSQL with optimized indexes
- Containerization: Full Docker Compose setup
- Type Safety: Protocol Buffers for strongly-typed API contracts
π οΈ Technology Stack
- Language: Go 1.23.2
- RPC Framework: gRPC with Protocol Buffers
- Database: PostgreSQL 15
- Containerization: Docker & Docker Compose
- Key Dependencies:
google.golang.org/grpc- gRPC frameworkgoogle.golang.org/protobuf- Protocol Buffersgithub.com/lib/pq- PostgreSQL drivergithub.com/google/uuid- UUID generation
π Prerequisites
- Docker and Docker Compose
- Go 1.23+ (for local development)
- Make (optional, for development scripts)
π Quick Start
Using Docker Compose (Recommended)
-
Clone the repository:
git clone <repository-url> cd gRPC -
Start all services:
docker-compose up --build -
Verify services are running:
- gRPC Server:
localhost:50051 - gRPC Client:
localhost:50052 - PostgreSQL:
localhost:5432
- gRPC Server:
Local Development
-
Install dependencies:
go mod download -
Start PostgreSQL (using Docker):
docker-compose up ticket_db -d -
Set environment variables:
export DB_HOST=localhost export DB_PORT=5432 export DB_USER=ayushpandya export DB_PASSWORD=postgres export DB_NAME=ticketdb export DB_SSLMODE=disable -
Run the server:
go run ticket-service-db/main.go -
Run the client (in another terminal):
go run grpc-client/main.go
π‘ API Reference
Service Definition
The TicketService provides the following RPC methods:
service TicketService {
rpc CreateTicket(CreateTicketRequest) returns (CreateTicketResponse);
rpc GetTicket(GetTicketRequest) returns (GetTicketResponse);
rpc ListTickets(ListTicketsRequest) returns (ListTicketsResponse);
rpc UpdateTicket(UpdateTicketRequest) returns (UpdateTicketResponse);
rpc DeleteTicket(DeleteTicketRequest) returns (DeleteTicketResponse);
}
Ticket Model
message Ticket {
string id = 1;
string title = 2;
string description = 3;
TicketStatus status = 4;
TicketPriority priority = 5;
string assignee_id = 6;
repeated string tags = 7;
google.protobuf.Timestamp created_at = 8;
google.protobuf.Timestamp updated_at = 9;
}
Enums
TicketStatus: OPEN, IN_PROGRESS, RESOLVED, CLOSED
TicketPriority: LOW, MEDIUM, HIGH, CRITICAL
ποΈ Database Schema
CREATE TABLE tickets (
id VARCHAR(255) PRIMARY KEY,
title VARCHAR(500) NOT NULL,
description TEXT,
status VARCHAR(50) NOT NULL DEFAULT 'OPEN',
priority VARCHAR(50) NOT NULL DEFAULT 'MEDIUM',
assignee_id VARCHAR(255),
tags JSONB DEFAULT '[]',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
reporter_id VARCHAR(255) NOT NULL
);
π§ Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
DB_HOST |
PostgreSQL host | ticket_db |
DB_PORT |
PostgreSQL port | 5432 |
DB_USER |
Database user | ayushpandya |
DB_PASSWORD |
Database password | postgres |
DB_NAME |
Database name | ticketdb |
DB_SSLMODE |
SSL mode | disable |
Docker Compose Services
- grpc-server: Ticket service (port 50051)
- grpc-client: Example client (port 50052)
- ticket_db: PostgreSQL database (port 5432)
π§ͺ Testing
Using the Client
The included gRPC client demonstrates all available operations:
# Run the client to see example operations
docker-compose up grpc-client
Manual Testing with grpcurl
# List all tickets
grpcurl -plaintext localhost:50051 ticket.TicketService/ListTickets
# Get a specific ticket
grpcurl -plaintext -d '{"id": "ticket-id"}' localhost:50051 ticket.TicketService/GetTicket
π Project Structure
gRPC/
βββ docker-compose.yaml # Docker Compose configuration
βββ go.mod # Go module definition
βββ go.sum # Go module checksums
βββ init.sql # Database initialization script
βββ proto/
β βββ ticket.proto # Protocol Buffer definitions
βββ ticket-service-db/
β βββ Dockerfile # Server container configuration
β βββ main.go # gRPC server implementation
βββ grpc-client/
β βββ Dockerfile # Client container configuration
β βββ main.go # Example gRPC client
βββ database/
βββ postgres.go # Database repository layer
π Development Workflow
Regenerating Protocol Buffers
After modifying proto/ticket.proto:
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
proto/ticket.proto
Building and Running
# Build all containers
docker-compose build
# Run in development mode
docker-compose up
# Run in background
docker-compose up -d
# View logs
docker-compose logs -f grpc-server
π€ Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
π License
This project is licensed under the MIT License - see the LICENSE file for details.