Skip to content

tedkim-dev/go-event-driven-architecture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Go Event-Driven Tickets Booking System

A modern, event-driven microservice architecture for managing ticket bookings, built with Go and following Domain-Driven Design principles.

πŸ—οΈ Architecture Overview

This system implements an event-driven architecture using:

  • Event Sourcing with event-driven communication
  • CQRS (Command Query Responsibility Segregation)
  • Outbox Pattern for reliable message delivery
  • Domain-Driven Design with clear bounded contexts
  • Microservices communication via events and commands

πŸš€ Features

  • Ticket Booking Management: Complete lifecycle from booking to cancellation
  • VIP Bundle Processing: Complex multi-step booking workflows
  • Payment Integration: Secure payment processing
  • Receipt Generation: Automated receipt issuance
  • Transportation Booking: Flight and transportation coordination
  • Real-time Notifications: Event-driven updates
  • Observability: Comprehensive tracing, metrics, and logging
  • Reliability: Outbox pattern for guaranteed message delivery

πŸ› οΈ Technology Stack

Core Technologies

  • Go 1.24 - Primary programming language
  • PostgreSQL - Primary database with event sourcing
  • Redis - Message broker and caching
  • Watermill - Event-driven messaging library
  • Echo - HTTP framework

Observability & Monitoring

  • OpenTelemetry - Distributed tracing
  • Prometheus - Metrics collection
  • Grafana - Monitoring dashboards
  • Jaeger - Trace visualization

External Integrations

  • Dead Nation API - External booking system
  • Spreadsheets API - Data export and reporting
  • Files API - Document management
  • Payments Service - Payment processing
  • Transportation Service - Flight and transport booking

πŸ“ Project Structure

project/
β”œβ”€β”€ adapters/           # External service adapters
β”œβ”€β”€ db/                 # Database layer and repositories
β”œβ”€β”€ entities/           # Domain entities and events
β”œβ”€β”€ http/               # HTTP handlers and routing
β”œβ”€β”€ message/            # Event/command messaging
β”‚   β”œβ”€β”€ command/        # Command handlers
β”‚   β”œβ”€β”€ event/          # Event handlers
β”‚   └── outbox/         # Outbox pattern implementation
β”œβ”€β”€ service/            # Application service layer
β”œβ”€β”€ observability/      # Tracing and monitoring
β”œβ”€β”€ migrations/         # Database migrations
└── tests/              # Component tests

πŸƒβ€β™‚οΈ Quick Start

Prerequisites

  • Go 1.24+
  • Docker and Docker Compose
  • Make (optional)

Running the Application

  1. Clone the repository

    git clone <repository-url>
    cd project
  2. Start dependencies with Docker Compose

    docker-compose up -d
  3. Set environment variables

    export POSTGRES_URL="postgres://user:password@localhost:5432/db?sslmode=disable"
    export REDIS_ADDR="localhost:6379"
    export GATEWAY_ADDR="http://localhost:8888"
  4. Run the application

    go run main.go

Access Points

πŸ—οΈ Architecture Patterns

Event-Driven Communication

The system uses events and commands for inter-service communication:

Events (what happened):

  • TicketBookingConfirmed_v1
  • BookingMade_v1
  • TicketPrinted_v1
  • VipBundleFinalized_v1

Commands (what to do):

  • BookShowTickets
  • BookFlight
  • RefundTicket

Outbox Pattern

Ensures reliable message delivery by storing outgoing messages in the database before publishing to the message broker.

CQRS Implementation

  • Commands: Handle write operations and business logic
  • Queries: Optimized read models for different use cases
  • Event Sourcing: Store all state changes as events

πŸ”§ Development

Running Tests

go test ./...

Database Migrations

# Run migrations (handled automatically on startup)

Adding New Features

  1. Define Domain Events in entities/events.go
  2. Create Command Handlers in message/command/
  3. Implement Event Handlers in message/event/
  4. Add HTTP Endpoints in http/
  5. Update Database Schema in db/

Code Organization

Domain Layer (entities/)

  • Business entities and value objects
  • Domain events and commands
  • Business rules and invariants

Application Layer (service/, message/)

  • Application services
  • Command and event handlers
  • Orchestration logic

Infrastructure Layer (adapters/, db/, http/)

  • External service integrations
  • Database repositories
  • HTTP handlers and routing

πŸ“Š Monitoring & Observability

Metrics

  • Business metrics (bookings, revenue)
  • Technical metrics (response times, error rates)
  • Custom metrics for domain events

Tracing

  • Distributed tracing across services
  • Correlation IDs for request tracking
  • Performance analysis

Logging

  • Structured logging with correlation IDs
  • Different log levels for different environments
  • Centralized log aggregation

πŸ”’ Security

  • Input validation and sanitization
  • Secure payment processing
  • Rate limiting and throttling
  • Audit logging for sensitive operations

πŸš€ Deployment

Docker Deployment

docker build -t tickets-service .
docker run -p 8080:8080 tickets-service

Environment Variables

  • POSTGRES_URL: Database connection string
  • REDIS_ADDR: Redis connection address
  • GATEWAY_ADDR: API Gateway address
  • LOG_LEVEL: Logging level (debug, info, warn, error)

go-event-driven-architecture

About

event driven architecture in go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages