How mehdihadeli/go-food-delivery-microservices works
Project Type & Purpose
• This is a Go-based microservices system (“Go Food Delivery Microservices”) implementing
• Vertical Slice Architecture
• CQRS + Mediator Pattern
• Domain-Driven Design & Event Sourcing
• Event-Driven Architecture over RabbitMQ
• REST (via Echo + Swagger) & gRPC for sync calls
• Dependency Injection (uber-go/fx)
• Multiple data stores (Postgres, EventStoreDB, MongoDB, Elasticsearch, Redis)
• It comprises three independently deployable services:
• Catalog Read Service (CRUD + read caches)
• Catalog Write Service (DDD + Postgres + Outgoing Integration Events)
• Order Service (Event Sourcing + EventStoreDB + projections into Mongo/Elastic)
• Shared libraries live under internal/pkg, and API / protobuf / OpenAPI contracts under api/.
File‐Structure Insights
• Top Level:
• api/ – OpenAPI specs & protobufs for all services
• deployments/ – Docker-Compose & Kubernetes resources
• internal/pkg/ – reusable packages (messaging, config, HTTP/gRPC framework, persistence adapters, logging, telemetry, test helpers)
• services/ – three folders (catalogreadservice, catalogwriteservice, orderservice), each with:
– cmd/app (service entrypoint)
– config (Viper setups)
– internal/... (feature slices: commands/queries, handlers, DTOs, repos, integration events)
– docs/swagger.yaml, Dockerfile, tests (unit, integration, end-to-end)
• Messaging: RabbitMQ bus builders & connectors under internal/pkg/core/messaging and internal/pkg/rabbitmq.
• Databases: adapters for Postgres (bun, postgrespgx, gorm, sqlx), MongoDB, Redis, Elasticsearch, EventStoreDB.
• Observability: OpenTelemetry tracing & metrics pipelines in internal/pkg/otel, Prometheus/Grafana config under deployments.
Key Components & Interactions
a. Clients invoke service APIs (HTTP/REST or gRPC) →
b. API Layer (Echo endpoints or gRPC handlers) →
c. Vertical Slice Handler (CQRS command/query via go-mediatr) →
d. Domain Logic
• Write services persist to Postgres or EventStoreDB; publish integration events to RabbitMQ
• Read services query NoSQL stores (MongoDB, Elastic) or cache (Redis)
e. Message Broker (RabbitMQ) routes events → other service consumers → drives eventual consistency
f. Projections: Order service’s event store projections populate read models in Mongo/Elastic
g. Sync gRPC: used for direct RPC between services when needed
Architectural Patterns & Principles
• Vertical Slice: each feature folder holds its endpoint, DTOs, handler, domain model, repository
• CQRS & Mediator: clear separation of commands vs queries, decoupled via pipelines
• Event Sourcing: orders are persisted as streams of events in EventStoreDB
• Event-Driven: integration events for cross-service communication over RabbitMQ
• Dependency Injection: all components wired by uber-go/fx modules
• DDD: services structured around aggregates, entities, domain events