Go gRPC-HTTP Microservices

E-Commerce Order Management System
16Containers
8Design Patterns
6Backend Services
5Databases
3Message Brokers
Go 1.25gRPCProtocol BuffersPostgreSQL 16Redis 7NATS JetStreamRabbitMQ 3DockerReact 19TypeScriptTailwind CSSNginx
System Architecture
🌐
Browser / Mobile
External Clients
HTTPS
⚛️
Frontend
React 19 + TypeScript + Tailwind CSS
Served by Nginx 1.27
:3000
/api/* proxy
🛡️
API Gateway
gRPC-Gateway — REST to gRPC Translation
CORS Middleware • Health Check /healthz
:8080
gRPC
gRPC
gRPC
gRPC
👤
User Service
Register, Login
JWT (Per-User Secret)
Profile Management
:50051
📦
Product Service
Catalog CRUD
Atomic Stock Reservation
Inventory Management
:50052
📋
Order Service
CQRS + Event Sourcing
Command & Query Split
Event Store + Projector
:50053
💳
Payment Service
Event-Driven Processing
Auto-Payment on Order
Refund Support
:50054
SQL
SQL
Events
Read Model
SQL
🗄️
PostgreSQL
userdb
:5433
🗄️
PostgreSQL
productdb
:5434
🗄️
PostgreSQL
orderdb (event_store)
:5435
Redis
CQRS Read Model
:6379
🗄️
PostgreSQL
paymentdb
:5436
Event Bus & Async Processing
Order Svc publishes
Payment Svc publishes
📨
NATS JetStream
Event Bus — Pub/Sub • Subjects: orders.* • payments.*
Durable Consumers • At-Least-Once Delivery
:4222 • Monitor :8222
Forwards events
🌉
Bridge Service
NATS → RabbitMQ
Event Forwarder
(Separate Container)
🐇
RabbitMQ
Topic Exchange
Durable Queue
Management UI
:5672 • :15672
🔔
Notification Service
Consumes from RabbitMQ
Sends Email via SMTP
Saves Audit Log to DB
✉️
Mailtrap SMTP
Email Sandbox
🗄️
PostgreSQL
notificationdb
:5437
Order Placement Flow
1
User Places Order
Browser sends POST /api/v1/orders to Nginx, proxied to API Gateway, translated to gRPC PlaceOrder()
Browser → Nginx → Gateway → Order Service
2
Stock Reservation (Sync gRPC)
Order Service calls Product Service to enrich items (name, price) and atomically reserve stock. Rollback all on any failure.
Order → Product ServiceUPDATE stock -= N WHERE stock >= N
3
Event Sourcing
Order aggregate produces OrderCreatedEvent. Appended to PostgreSQL event_store with optimistic concurrency (UNIQUE aggregate_id + version).
INSERT INTO event_store (order.created, v1)
4
Publish to NATS & Return Response
Event published to NATS "orders.created". Client receives {order_id, status: "pending"} immediately.
NATS: orders.createdResponse: status = pending
5
Async: Projector + Payment + Notification (Parallel)
Projector: Writes order to Redis (status: pending) • Payment: Creates payment, publishes payments.completed • Bridge → RabbitMQ → Notification: Sends "Order Confirmed" email
Redis SET order:{id}NATS: payments.completedRabbitMQ → NotificationSMTP: Order Confirmed
6
Order Marked as Paid
Order Service receives payments.completed, produces OrderPaidEvent (v2). Projector updates Redis (status: paid). Client polls GET /api/v1/orders/{id} → sees paid.
event_store (order.paid, v2)Redis: status = paidSMTP: Payment ReceivedClient sees: PAID
Design Patterns
🛡️
API Gateway
gRPC-Gateway translates REST to gRPC. Single entry point.
🗄️
Database per Service
5 PostgreSQL instances. Loose coupling, independent scaling.
↔️
CQRS
Commands write to event store. Queries read from Redis.
📜
Event Sourcing
Immutable event log. State from replay. Full audit trail.
📨
Event-Driven
NATS JetStream pub/sub. At-least-once. Decoupled services.
🔑
Per-User JWT
Unique signing secret per user. Instant revocation.
📦
Repository Pattern
Interface abstraction. Swappable backends for testing.
💚
Health Checks
gRPC Health v1 protocol. Docker healthchecks.
Docker Containers (16)
Infrastructure — Pre-built Images (8 containers)
ContainerImagePortDescription
🗄️ postgres-userpostgres:16-alpine:5433User accounts, auth tokens, password hashes
🗄️ postgres-productpostgres:16-alpine:5434Product catalog, inventory, 20 seed products
🗄️ postgres-orderpostgres:16-alpine:5435Event store (append-only order events)
🗄️ postgres-paymentpostgres:16-alpine:5436Payment records and status tracking
🗄️ postgres-notificationpostgres:16-alpine:5437Notification audit log
⚡ redisredis:7-alpine:6379CQRS read model (denormalized order views)
📨 natsnats:2-alpine:4222Event bus with JetStream persistence
🐇 rabbitmqrabbitmq:3-management-alpine:5672 :15672Notification queue with management UI
Application — Custom Dockerfiles (8 containers)
ContainerDockerfilePortDescription
⚛️ frontendfrontend/Dockerfile:3000Node 22 build + Nginx 1.27 serve (React SPA)
🛡️ gatewaydeployments/docker/gateway.Dockerfile:8080REST-to-gRPC reverse proxy, CORS
👤 user-servicedeployments/docker/user-service.Dockerfile:50051Auth, JWT, registration, profile
📦 product-servicedeployments/docker/product-service.Dockerfile:50052Catalog CRUD, atomic stock reservation
📋 order-servicedeployments/docker/order-service.Dockerfile:50053CQRS + Event Sourcing, projector
💳 payment-servicedeployments/docker/payment-service.Dockerfile:50054Event-driven payment processing
🌉 bridge-servicedeployments/docker/bridge-service.DockerfileNATS → RabbitMQ event forwarder
🔔 notification-servicedeployments/docker/notification-service.DockerfileRabbitMQ consumer, SMTP email, audit log
Multi-Stage Build Pattern (All Go Services)