DEV Community

Lakhan Samani
Lakhan Samani

Posted on

Building a Distributed E-commerce App with Go and gRPC – Part 1

Introduction & Project Overview

πŸš€ Why Build a Distributed System with Go & gRPC?

Modern applications need to be scalable, fast, and efficient. A monolithic approach may work initially, but as your app grows, it becomes hard to maintain. This is where microservices come in!

In this series, we’ll build a simple distributed e-commerce system using Go, gRPC, PostgreSQL, and Kubernetes. By the end of this series, you’ll understand how to:

  • βœ… Design gRPC APIs for communication between services.
  • βœ… Implement services with Go and handle user authentication.
  • βœ… Use middleware for logging, monitoring, and security.
  • βœ… Deploy services to Kubernetes and scale them dynamically.

πŸ“Œ Project Overview: What Are We Building?

We’ll build a simplified e-commerce backend with two core services:

User Service πŸ§‘β€πŸ’»
- Create users
- Authenticate users with JWT
- Retrieve user details

Order Service πŸ“¦
- Place an order (linked to a user)
- Get order details

πŸ›  Tech Stack

Technology Purpose
Go Backend services
gRPC Communication between services
PostgreSQL Database for users & orders
Redis Caching & rate-limiting
Prometheus & Grafana Monitoring & metrics
Prometheus & Alertmanager Setting up alerts for failures
Kubernetes (K8s) Deployment & auto-scaling

🌍 System Architecture

Here’s how the services interact:

services-architecture

  • The User Service stores user data in PostgreSQL.
  • The Order Service processes orders and links them to users.
  • Both services communicate via gRPC instead of REST for high performance.

πŸ“ Step 1: Setting Up the Project

1️⃣ Install Dependencies

Make sure you have Go installed (v1.23+ recommended). Then install proto buff:

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
Enter fullscreen mode Exit fullscreen mode

Now add them to your PATH:

export PATH="$PATH:$(go env GOPATH)/bin"
Enter fullscreen mode Exit fullscreen mode

2️⃣ Create the Project Structure

Run the following to set up the project:

Note: please replace github.com/lakhansamani with your github or go package URL.

mkdir ecom-grpc
cd ecom-grpc
mkdir apis userd orderd
cd apis # common repo for all the service apis 
go mod init github.com/lakhansamani/ecom-grpc-apis
cd ..
cd userd # user service
go mod init github.com/lakhansamani/ecom-grpc-userd
cd ..
cd orderd # order service
go mod init github.com/lakhansamani/ecom-grpc-orderd
Enter fullscreen mode Exit fullscreen mode

🎯 Next Steps
In Part 2, we’ll define our gRPC APIs using Protobuf and implement the User Service in Go. Stay tuned! πŸš€

Top comments (0)