A modern, event-driven microservice architecture for managing ticket bookings, built with Go and following Domain-Driven Design principles.
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
- 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
- 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
- OpenTelemetry - Distributed tracing
- Prometheus - Metrics collection
- Grafana - Monitoring dashboards
- Jaeger - Trace visualization
- 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/
βββ 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
- Go 1.24+
- Docker and Docker Compose
- Make (optional)
-
Clone the repository
git clone <repository-url> cd project
-
Start dependencies with Docker Compose
docker-compose up -d
-
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"
-
Run the application
go run main.go
- Application: http://localhost:8080
- Gateway: http://localhost:8888
- Grafana: http://localhost:3000 (admin/admin)
- Prometheus: http://localhost:9090
- Jaeger: http://localhost:16686
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
Ensures reliable message delivery by storing outgoing messages in the database before publishing to the message broker.
- Commands: Handle write operations and business logic
- Queries: Optimized read models for different use cases
- Event Sourcing: Store all state changes as events
go test ./...
# Run migrations (handled automatically on startup)
- Define Domain Events in
entities/events.go
- Create Command Handlers in
message/command/
- Implement Event Handlers in
message/event/
- Add HTTP Endpoints in
http/
- Update Database Schema in
db/
- Business entities and value objects
- Domain events and commands
- Business rules and invariants
- Application services
- Command and event handlers
- Orchestration logic
- External service integrations
- Database repositories
- HTTP handlers and routing
- Business metrics (bookings, revenue)
- Technical metrics (response times, error rates)
- Custom metrics for domain events
- Distributed tracing across services
- Correlation IDs for request tracking
- Performance analysis
- Structured logging with correlation IDs
- Different log levels for different environments
- Centralized log aggregation
- Input validation and sanitization
- Secure payment processing
- Rate limiting and throttling
- Audit logging for sensitive operations
docker build -t tickets-service .
docker run -p 8080:8080 tickets-service
POSTGRES_URL
: Database connection stringREDIS_ADDR
: Redis connection addressGATEWAY_ADDR
: API Gateway addressLOG_LEVEL
: Logging level (debug, info, warn, error)