Technology Stack & Role
ZenithCart showcases a split-service architecture designed for high-concurrency event handling during flash sale scenarios. The core engines are written in Go for speed, using gRPC for low-latency communication.
Core Microservices
Go (Golang) / gRPC Protocols
Protobuf / Context / Go Routines
Storage & Locks
Redis Cluster (Distributed Locks)
PostgreSQL / SQL Optimizations
Checkout & Messaging
RabbitMQ queues & Stripe Webhooks
Next.js 15 Storefront
1. The Business & Engineering Problem
Freelance clients building high-scale e-commerce operations encounter major failures during flash sales or heavy traffic:
- Double-Spending & Race Conditions: Multiple customers purchasing the last item in stock concurrently, leading to negative stock counts.
- Database Bottlenecks: Writing order records directly to a relational database synchronously under 10,000+ RPS crushes DB connection pools.
- Stripe Event Desynchronization: Payments clearing in Stripe but failing to allocate stock or update order states due to network timeouts.
- Slow API Latencies: Standard REST setups suffering from serialization overheads and connection bloat during checkout routing.
2. High-Level System Architecture
I designed ZenithCart to process checkout requests asynchronously. The Inventory service verifies and locks item counts in Redis, the Checkout service accepts the cart details, RabbitMQ queues orders for persistence, and Go workers write the records to PostgreSQL in batches.
High-speed, typed binary calls using HTTP/2 multiplexing, reducing payload transfer size by 70% compared to typical JSON/HTTP REST APIs.
Acquires transaction locks on product IDs prior to validating inventory, preventing double-spend race conditions.
Handles surges by buffering orders in queue pipelines. Consumer workers read and commit records safely to PostgreSQL without overload.
3. Core Engineering Implementations
A. Low-Latency gRPC Contract Definitions
To speed up communication between the Next.js API router and the Go inventory backend, the contract is compiled using Protocol Buffers.
/** protobuf definition: inventory.proto **/ syntax = "proto3"; package inventory; service InventoryService { rpc ReserveStock (StockRequest) returns (StockResponse); } message StockRequest { string product_id = 1; int32 quantity = 2; } message StockResponse { bool success = 1; int32 remaining_stock = 2; string reservation_token = 3; }
B. Go-Redis Inventory Lock Engine
To support thousands of checkout calls on the same item, we acquire a temporary key lock in Redis with a 5-second TTL. If stock is available, we decrement the value atomically in Redis.
/** Atomic Go-Redis stock reservation logic **/ func (s *server) ReserveStock(ctx context.Context, req *pb.StockRequest) (*pb.StockResponse, error) { lockKey := fmt.Sprintf("lock:product:%s", req.ProductId) stockKey := fmt.Sprintf("stock:product:%s", req.ProductId) -- Acquire distributed lock ok, err := s.redisClient.SetNX(ctx, lockKey, "locked", 5*time.Second).Result() if !ok || err != nil { return &pb.StockResponse{Success: false}, fmt.Errorf("concurrency lock timeout") } defer s.redisClient.Del(ctx, lockKey) -- Check and decrement atomically currentStock, _ := s.redisClient.Get(ctx, stockKey).Int() if currentStock < int(req.Quantity) { return &pb.StockResponse{Success: false}, nil } s.redisClient.DecrBy(ctx, stockKey, int64(req.Quantity)) return &pb.StockResponse{Success: true, RemainingStock: int32(currentStock - int(req.Quantity))}, nil }
C. Batch DB Writes & Transaction Persistence
Rather than blocking the client checkout request, orders are pushed to a RabbitMQ queue. Dedicated worker routines consume the queue in batches and bulk-insert them into PostgreSQL, boosting overall write throughput.
4. Concurrency Stress Test Log
We performed load testing using Locust and k6 to verify system bottlenecks under high-concurrency spikes.
5. Key Engineering Accomplishments
Inter-service communication payload sizes saved via gRPC protobuf serialization.
Stock sync errors reported during flash sales simulating 50k active shoppers.
Webhook reconciliation rate on payment verification webhooks via RabbitMQ.
ZenithCart showcases how high-scale commerce requirements can be solved using structured database designs, distributed locking mechanisms, and robust Go services.