4.8 KiB
Marketplace Microservices Platform
A Go-based microservices marketplace platform built step-by-step across modules. It showcases HTTP & gRPC APIs, databases, concurrency, messaging, and observability.
Services
- Cart — user shopping cart (HTTP).
- LOMS — Logistics & Order Management (gRPC + HTTP gateway): orders, stock, reservation.
- Comments — item comments (HTTP).
- Notifier — Kafka consumer that processes order events.
Infra: PostgreSQL, Kafka, Docker Compose, Prometheus, Grafana, OpenTelemetry.
Features by Module
-
Go Basics (Cart)
- HTTP API: add/delete/clear/list cart.
- Logging middleware, request validation, client retries.
- In-memory repository.
-
Testing in Go
- Unit tests for use cases & repository (minimock).
- Coverage target ≥ 60%.
- Benchmarks + e2e tests (selected handlers).
-
Inter-service Communication (LOMS)
- gRPC API:
OrderCreate,OrderInfo,OrderPay,OrderCancel,StocksInfo. - Cart → LOMS via gRPC (checkout & stock checks).
- proto-gen-validate interceptor, HTTP gateway, Swagger UI.
- gRPC API:
-
Databases
- LOMS uses PostgreSQL with migrations.
- Transactional order creation.
- SQLC for type-safe queries.
-
Concurrency
- Parallel product lookups with a custom
errgroup. - Client-side RPS limiting (10 RPS), context cancellation.
- Mutex-protected in-memory stores.
- Parallel product lookups with a custom
-
Messaging & Outbox (extended)
- Kafka outbox for order domain events (see
loms/internal/infra/messaging/kafka_outbox). - Notifier consumes and processes events (
notifier/internal/infra/messaging/kafka).
- Kafka outbox for order domain events (see
-
Observability (extended)
- OpenTelemetry tracing, Prometheus metrics, Grafana dashboards.
- gRPC/HTTP middleware for logging/metrics/tracing.
-
Production-Ready Enhancements (extended)
- Dockerized services & Makefile automation.
- Graceful shutdowns, race/leak checks.
- CI-friendly lint/tests/migrations.
- End-to-end integration tests.
Tech Stack
Go 1.23 • HTTP • gRPC + gRPC-Gateway • Swagger • PostgreSQL • SQLC • Kafka • OpenTelemetry • Prometheus • Grafana • Docker & Docker Compose • minimock
Project Structure (high-level)
/cart # HTTP cart service, clients to LOMS & product-service, tests
/loms # gRPC LOMS service (orders, stocks), DB layer (sqlc), gateway, swagger
/comments # Comments service (HTTP, Postgres repository)
/notifier # Kafka consumer (order events)
/prometheus # Prometheus config
/grafana_data # Local Grafana storage
/docker-compose.yaml
/Makefile # build/run/test targets
(See service-specific folders for configs, db/migrations, and Makefile targets.)
Run Locally
make run-all
Starts services (cart, loms, comments, notifier) plus dependencies (PostgreSQL, Kafka), applies migrations, and exposes UIs.
Default ports
- Cart HTTP:
http://localhost:8080 - LOMS gRPC-Gateway & Swagger:
http://localhost:8081 - Product service (mock):
http://localhost:8082/docs - Prometheus:
http://localhost:9090 - Grafana:
http://localhost:3000
Auth to product-service via
X-API-KEY: testToken.
Key APIs
Cart (HTTP)
POST /user/{user_id}/cart/{sku}— add item (validates via product-service; checks stock via LOMS).DELETE /user/{user_id}/cart/{sku}— remove item.DELETE /user/{user_id}/cart— clear cart.GET /user/{user_id}/cart— list cart (sorted by SKU).POST /checkout/{user_id}— create order in LOMS from cart.
LOMS (gRPC + HTTP Gateway)
OrderCreate,OrderInfo,OrderPay,OrderCancelStocksInfo— available to buy (total − reserved)
Swagger (when enabled):
- LOMS:
http://localhost:8081/docs - Product mock:
http://localhost:8082/docs
Happy Path (Example Flow)
POST /user/{user_id}/cart/{sku}— Add item to cart (checks product exists and stock is sufficient).GET /user/{user_id}/cart— Verify cart contents.POST /checkout/{user_id}— Create an order in LOMS.POST /order/pay(LOMS) — Pay the order with body{ "orderId": <id> }.- Optionally,
POST /order/cancel(LOMS) before payment to cancel the order.
Development
Makefile highlights
make run-all— build & run full stackmake test— unit tests (minimock)make lint— lint (incl. cyclomatic/cognitive complexity)make cover— coverage reportmake gen— proto & SQLC codegen
Testing
- Unit tests for use cases & repositories
- e2e tests for selected handlers
- Benchmarks for in-memory storage
- Race detector & goroutine leak checks (where applicable)
Observability
- Tracing via OpenTelemetry (
internal/infra/tracing) - Metrics via Prometheus (
/prometheus/prometheus.yml) - Dashboards in Grafana (
/grafana_data)