{"id":21954952,"url":"https://github.com/saalikmubeen/go-grpc-implementation","last_synced_at":"2025-04-23T12:04:55.700Z","repository":{"id":240804428,"uuid":"803473716","full_name":"saalikmubeen/go-grpc-implementation","owner":"saalikmubeen","description":"Golang + Gin + Docker + gRPC + NGINX","archived":false,"fork":false,"pushed_at":"2024-06-12T05:49:42.000Z","size":5805,"stargazers_count":63,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-23T12:04:11.819Z","etag":null,"topics":["docker","gin","golang","grpc","nginx","protocol-buffers","sqlc"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/saalikmubeen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-20T19:43:48.000Z","updated_at":"2025-04-17T15:41:09.000Z","dependencies_parsed_at":"2024-06-01T13:04:30.258Z","dependency_job_id":"38ef2a22-32d5-447b-aebd-a01737664782","html_url":"https://github.com/saalikmubeen/go-grpc-implementation","commit_stats":null,"previous_names":["saalikmubeen/go-grpc-implementation"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saalikmubeen%2Fgo-grpc-implementation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saalikmubeen%2Fgo-grpc-implementation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saalikmubeen%2Fgo-grpc-implementation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saalikmubeen%2Fgo-grpc-implementation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saalikmubeen","download_url":"https://codeload.github.com/saalikmubeen/go-grpc-implementation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250430586,"owners_count":21429324,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","gin","golang","grpc","nginx","protocol-buffers","sqlc"],"created_at":"2024-11-29T07:26:52.605Z","updated_at":"2025-04-23T12:04:55.573Z","avatar_url":"https://github.com/saalikmubeen.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Golang + Gin + Postgres + Docker + gRPC + NGINX\n\ngRPC and RESTful HTTP implementation of backend server written in Go.\n\n\n### Description\nA Go-based based implementation of gRPC with Gin, PostgreSQL, Docker, and NGINX. This project\ndemonstrates how to build a robust backend service with HTTP and gRPC servers, using Go's Gin\nframework for HTTP, a separate gRPC server  and a gRPC gateway to handle HTTP requests under the hood.\n\n\n# Technologies used\n\n- **`Gin`** as HTTP web framework\n- **`PostgreSQL`** as database\n- **`SQLC`** as code generator for SQL\n- **`golang-migrate`** for database migration\n- **`gRPC`** Remote procedure call framework.\n- **`Docker`** for containerizing the application\n- **`NGINX`** as a load balancer and reverse proxy\n- **`Protoc`** as protocol buffer compiler\n\n\n\n\n# Architecture\n\nThe project consists of the following 3 kinds of servers:\n\n\n### 1. HTTP Gin Server\n\n- `Description`: A lightweight HTTP web server built with the Gin framework.\n- `Functionality`: Serves HTTP requests directly without any additional translation.\n- `Purpose`: Offers a simple and efficient means for handling HTTP client requests.\n\n\n### 2. gRPC Server\n\n- `Description`: Implements gRPC services for remote procedure calls.\n- `Functionality`: Handles gRPC client requests directly, providing efficient communication between client and server.\n- `Purpose`: Facilitates high-performance, bidirectional communication between client and server.\n\n### 3. gRPC Gateway Server\n\n- `Description`: An HTTP server that acts as a gateway for HTTP clients to communicate with the gRPC server.\n- `Functionality`: Receives HTTP requests from clients and translates them into gRPC calls, forwarding them to the appropriate gRPC handlers.\n- `Purpose`: Enables HTTP clients to interact seamlessly with the gRPC server, expanding compatibility and usability.\n\n\nBy following this architecture, developers can seamlessly switch between running the server as a `standalone HTTP Gin server` or as `a gRPC server with an HTTP Gateway server serving both gRPC and HTTP clients at the same time`. NGINX ensures efficient load balancing and distribution of incoming requests, enhancing the scalability and reliability of the  architecture.\n\n\n## Setup local development\n\n\n### Install tools\n\n- [Docker desktop](https://www.docker.com/products/docker-desktop)\n- [Golang](https://golang.org/)\n- [Homebrew](https://brew.sh/)\n- [Migrate](https://github.com/golang-migrate/migrate/tree/master/cmd/migrate)\n- [Evans Cli](https://github.com/ktr0731/evans)\n\n\n    ```bash\n    brew install golang-migrate\n    ```\n\n\n- [Sqlc](https://github.com/kyleconroy/sqlc#installation)\n\n    ```bash\n    brew install sqlc\n    ```\n\n- [Gomock](https://github.com/golang/mock)\n\n    ``` bash\n    go install github.com/golang/mock/mockgen@v1.6.0\n    ```\n\n\n# Installation\n\n1. Clone project\n\n```\ngit git@github.com:saalikmubeen/go-grpc-implementation.git\n```\n\n## Manual\n\n**`If you aren't a docker person`**, ([Please learn docker 🥲](https://www.docker.com/why-docker))\n\ncd into root project\n\n```\ncd go-grpc-implementation\n```\n\n`go mod tidy` to install server dependencies\n\n`Setup required environment variables:`\n\n*In the **`app.env`* file, replace the environment variables with your own.*\n\n*Make sure you have postgresQL  installed*\n\n\nTo start the gRPC and HTTP server:\n\n```\nmake server\n```\n\n**`OR`** ( if you don't have make installed)\n\n```\ngo run main.go\n```\n\n\n*This will start the gRPC server by default on port  50051 and the HTTP Gateway server on port 8080*\n\n\n## Docker\n\n**`If you use docker, respect++`**\n\nRunning project through docker is a breeze. You don't have to do any setup. Just one docker-compose command and magic\n\n`cd go-grpc-implementation`\n\n### 1. To run the project without load balancing\n\n`run:`\n\n```\nmake dockerup:\n```\n\n**`OR`**\n\n```\ndocker-compose up --build\n```\n\n*This will start the gRPC server by default on port  50051 and the HTTP Gateway server on port 8080*\n\n### 2. To run the project with load balancing\n\n`run:`\n\n```\nmake loadbalancerup\n```\n\n**`OR`**\n\n```\ndocker-compose -f docker-compose-lb.yml up --build\n```\n\n*This will run the 4 instances of our Go server in 4 different containers, each running on a different port and an NGINX load balancer to distribute the load between the 4 instances*\nEach instance or container will be running two servers, one for gRPC and as an  HTTP Gateway server. The NGINX will do two things:\n\n- Load balance the incoming HTTP requests between the 4 HTTP Gateway servers running in the 4 instances\n- Load balance the incoming gRPC requests between the 4 gRPC servers running in the 4 instances\n\n\nNGINX Load Balancer opens two ports:\n\n- Port 80, which maps to port 3050 for incoming HTTP requests\n- Port 9090, which maps to same port 9090  for incoming gRPC requests\n\n\nTo send HTTP requests to the NGINX load balancer (which will distribute the requests between the 4 HTTP Gateway servers),\njust open web browser or Postman and send requests to `http://localhost:3050`\n\nTo send gRPC requests to the NGINX load balancer (which will distribute the requests between the 4 gRPC servers),\nyou can use the Evans CLI tool to send gRPC requests to the NGINX load balancer. Run the following command:\n\n```\nevans --port 9090 --host localhost -r repl;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaalikmubeen%2Fgo-grpc-implementation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaalikmubeen%2Fgo-grpc-implementation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaalikmubeen%2Fgo-grpc-implementation/lists"}