Skip to content

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

Published: at 12:00 PM

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:


📌 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

TechnologyPurpose
GoBackend services
gRPCCommunication between services
PostgreSQLDatabase for users & orders
RedisCaching & rate-limiting
Prometheus & GrafanaMonitoring & metrics
Prometheus & AlertmanagerSetting up alerts for failures
Kubernetes (K8s)Deployment & auto-scaling

🌍 System Architecture

Here’s how the services interact:

services-architecture


##📝 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

Now add them to your PATH:

export PATH="$PATH:$(go env GOPATH)/bin"

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

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