Skip to content

Repository files navigation

Distributed Microservice System

A polyglot, event-driven commerce backend built with Go, Python, gRPC, RabbitMQ, PostgreSQL, and Docker Compose. Go services handle users, orders, and the HTTP gateway. The Python payment service processes order events asynchronously and publishes payment completion events back to the order service.

Architecture

flowchart LR
    Client -->|REST| Gateway[Go API Gateway]
    Gateway -->|gRPC| User[Go User Service]
    Gateway -->|gRPC| Order[Go Order Service]
    Order -->|order.created| Rabbit[(RabbitMQ)]
    Rabbit -->|order.created| Payment[Python Payment Service]
    Payment --> PaymentsDB[(Payments PostgreSQL)]
    Payment -->|payment.completed| Rabbit
    Rabbit -->|payment.completed| Order
    Order --> OrdersDB[(Orders PostgreSQL)]
    User --> UsersDB[(Users PostgreSQL)]
Loading

The event handlers are designed for at-least-once delivery. The Python payment service upserts payments by order_id, and the order service applies status updates idempotently, making message retries safe.

Services

Service Language Responsibility
gateway Go REST API and REST-to-gRPC translation
usersvc Go User creation and retrieval
ordersvc Go Order persistence, gRPC API, and payment-status updates
paymentsvc Python Payment validation, persistence, and event processing
rabbitmq RabbitMQ Durable asynchronous event delivery
postgres PostgreSQL Isolated user, order, and payment databases

Run locally

Requirements: Docker with the Compose plugin.

docker compose up --build

The API Gateway is available at http://localhost:8080, and the RabbitMQ management console is available at http://localhost:15672 with the default local credentials guest / guest.

Create a user:

curl -sS -X POST http://localhost:8080/users \
  -H 'Content-Type: application/json' \
  -d '{"name":"Ada Lovelace","email":"ada@example.com"}'

Use the returned user ID to create an order:

curl -sS -X POST http://localhost:8080/orders \
  -H 'Content-Type: application/json' \
  -d '{"user_id":"<USER_ID>","amount_cents":12500}'

The order is created with a pending status. The Python service consumes the order.created event, stores an idempotent payment record, publishes payment.completed, and the order service updates the order to paid.

Confirm the final order status:

curl -sS http://localhost:8080/orders/<ORDER_ID>

Tests

Run the complete local verification suite, including Go tests, Python tests, static analysis, and Docker Compose configuration validation:

make verify

Use make test, make vet, or make compose-check to run an individual verification stage.

Regenerate Go and Python Protocol Buffer bindings after changing a .proto file:

make proto

About

A distributed event-driven system composed of independent services, usersvc, ordersvc, paymentsvc, and an API Gateway, communicating via gRPC for synchronous requests and RabbitMQ for asynchronous message passing.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages