Software DevelopmentBackendGo Archis and Frameworks

Go Architectures and Frameworks

List of Go architectures:

  1. Classic MVC
  2. Clean architecture
  3. Hexagonal
  4. Onion

List of Go Frameworks:

  1. Gin
  2. Fiber
  3. Echo
  4. Chi

Go API Types and Protocols:

  1. REST API
  2. gRPC
  3. GraphQL
  4. SOAP
  5. WebSockets
  6. gRPC-Web
  7. MQ (RabbitMQ, NATS, Kafka)

Go Architectures

Classic MVC (Model View Controller)

Use cases:

  • Monoliths apps
  • For very small microservices (e.g., 1 or 2 endpoints)
  • When speed > structure (PoCs or MVPs)

it’s better to at least separate your core logic from your handler (controller) code, to keep future flexibility.

project/
├── main.go                 ← app entry point
├── controllers/            ← Controller: handle HTTP requests
│   └── user_controller.go
├── models/                 ← Model: structs + DB logic
│   └── user.go
├── views/                  ← View: templates (HTML, optional)
│   └── login.html
├── routes/                 ← Routing setup
│   └── router.go
├── database/               ← DB connection setup
│   └── postgres.go
 

Hexagonal

A type of clean architecture

They share the same core principles, but differ mainly in focus and visual metaphor.

Key difference with Clean archi:

FocusExplanation
HexagonalFocuses on how the app talks to the outside world, using ports (interfaces) and adapters (HTTP, CLI, DB, etc).
Clean ArchitectureFocuses on how the business logic is organized and protected from infrastructure changes. Often uses layered rings (like an onion).
project/
├── cmd/                    ← Main apps (entrypoints)
│   └── server/
│       └── main.go
├── internal/
│   ├── domain/             ← Entities + interfaces
│   │   └── user.go
│   ├── usecase/Application logic (interactors)
│   │   └── user_usecase.go
│   ├── delivery/           ← Adapters (controllers, HTTP handlers)
│   │   └── http/
│   │       └── user_handler.go
│   └── repository/Database implementations
│       └── user_pg.go
├── pkg/                    ← Shared external code
├── config/                 ← Config files
└── go.mod
 

Go API Types and Protocols

REST vs gRPC

NameTypeDescription
RESTResource-based API protocolHTTP-based API using human-readable URLs and payloads (JSON/XML)
gRPCRPC (Remote Procedure Call)Protocol based on HTTP/2 and Protocol Buffers, used for high-performance service-to-service communication

REST use cases?

ScenarioDescription
🌐 Public APIsEasy to test/debug (via browser or Postman), human-readable JSON.
🖥 Frontend (Web/Mobile) ClientsWorks easily with browsers and native apps.
📄 Hypermedia / CRUDStandard for CRUD operations on web resources (GET, POST, etc).
🧩 3rd-party IntegrationsMost SaaS APIs are RESTful for easy integration.
🌍 Broad client compatibilityBrowsers, IoT, mobile apps without special tools.

Real world REST use cases?

Use CaseExample
Public APIGitHub REST API
Frontend AppReact app fetching blog posts
Mobile APIiOS app calling weather API
SaaS PlatformStripe API for payments
CRUD Admin PanelExpress.js/Gin/GoFiber app with REST endpoints

gRPC use cases?

ScenarioDescription
High performanceBinary protocol (protobuf) over HTTP/2, much faster than REST+JSON
🔁 Streaming / Real-time dataSupports server-side, client-side, and bidirectional streams
🧱 Strictly defined contracts.proto file acts as contract between client/server
🧪 Multi-language microservicesAuto-generates client/server stubs in Go, Java, Python, etc
🔐 Internal servicesBetween trusted backends in the same org or data center
📦 Data-intensive operationsImage/video processing, ML pipelines, large message payloads

Real life gRPC use cases?

Use CaseExample
Microservice CommunicationUser Service ↔ Auth Service ↔ Payment Service
Streaming ServiceLive stock price updates or sensor data stream
ML PipelineBackend calling TensorFlow model via gRPC
IoT DevicesEdge device ↔ cloud gateway
Mobile ↔ Backend (with gRPC-Web)Flutter/React Native app using gRPC protocol

REST vs gRPC use cases?

Use CaseRecommended
Public API for external devs✅ REST
Internal backend-to-backend✅ gRPC
Mobile app with REST clients✅ REST
IoT device sending live telemetry✅ gRPC (or MQTT)
Real-time collaboration tools✅ gRPC (with streaming)
CRUD admin dashboard✅ REST
Chat application backend✅ gRPC (for performance/streaming)
Payment integration (Stripe, PayPal)✅ REST
Go services talking to Python services✅ gRPC
Uploading large binary files✅ REST (with multipart), or gRPC (with chunking)

🚀 Use REST for frontend & public APIs, ⚙️ Use gRPC internally between microservices 🧠 Use both together with an API Gateway to bridge frontend and backend layers.

Other Types and Protocols?

NameTypeDescription
GraphQLQuery languageFlexible API where client defines data shape. Runs over HTTP.
SOAPXML-based RPCLegacy enterprise protocol, uses XML, WSDL.
WebSocketsBidirectional streamReal-time communication (e.g., chats, games).
gRPC-WebgRPC over HTTP/1.1Allows browsers to talk to gRPC backend.
ThriftRPC frameworkSimilar to gRPC, used at Facebook, supports many languages.
JSON-RPC / XML-RPCLightweight RPC protocolsSimple request-response over HTTP. Mostly outdated.
MQ (RabbitMQ, NATS, Kafka)Message queue, Event-drivenAsynchronous messaging systems, not request/response.

When to use what?

Use CaseRecommended Protocol
Public web API✅ REST or GraphQL
High-performance microservices✅ gRPC
Real-time chat or multiplayer✅ WebSocket
Internal service-to-service✅ gRPC or MQ
UI dashboard with flexible queries✅ GraphQL
Legacy system integration✅ SOAP or REST

Use cases?

ProtocolBest ForExample Use Case
GraphQLClient-driven data shapes, reducing overfetchingMobile app requesting nested user data
SOAPLegacy enterprise with strict schemasInsurance or banking API integration
WebSocketReal-time, full-duplex communicationMultiplayer games, live chats
gRPC-WebBrowsers talking to gRPC microservicesAdmin dashboard with gRPC backend
ThriftMulti-language internal RPCFacebook-like backend microservice system
JSON-RPCLightweight RPC, CLI tools, blockchain nodesEthereum JSON-RPC API
MQ (Kafka)Asynchronous, event-driven architecturePayment service → Order service via Kafka