Go Architectures and Frameworks
List of Go architectures:
- Classic MVC
- Clean architecture
- Hexagonal
- Onion
List of Go Frameworks:
- Gin
- Fiber
- Echo
- Chi
Go API Types and Protocols:
- REST API
- gRPC
- GraphQL
- SOAP
- WebSockets
- gRPC-Web
- 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:
| Focus | Explanation |
|---|---|
| Hexagonal | Focuses on how the app talks to the outside world, using ports (interfaces) and adapters (HTTP, CLI, DB, etc). |
| Clean Architecture | Focuses 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
| Name | Type | Description |
|---|---|---|
| REST | Resource-based API protocol | HTTP-based API using human-readable URLs and payloads (JSON/XML) |
| gRPC | RPC (Remote Procedure Call) | Protocol based on HTTP/2 and Protocol Buffers, used for high-performance service-to-service communication |
REST use cases?
| Scenario | Description |
|---|---|
| 🌐 Public APIs | Easy to test/debug (via browser or Postman), human-readable JSON. |
| 🖥 Frontend (Web/Mobile) Clients | Works easily with browsers and native apps. |
| 📄 Hypermedia / CRUD | Standard for CRUD operations on web resources (GET, POST, etc). |
| 🧩 3rd-party Integrations | Most SaaS APIs are RESTful for easy integration. |
| 🌍 Broad client compatibility | Browsers, IoT, mobile apps without special tools. |
Real world REST use cases?
| Use Case | Example |
|---|---|
| Public API | GitHub REST API |
| Frontend App | React app fetching blog posts |
| Mobile API | iOS app calling weather API |
| SaaS Platform | Stripe API for payments |
| CRUD Admin Panel | Express.js/Gin/GoFiber app with REST endpoints |
gRPC use cases?
| Scenario | Description |
|---|---|
| ⚡ High performance | Binary protocol (protobuf) over HTTP/2, much faster than REST+JSON |
| 🔁 Streaming / Real-time data | Supports server-side, client-side, and bidirectional streams |
| 🧱 Strictly defined contracts | .proto file acts as contract between client/server |
| 🧪 Multi-language microservices | Auto-generates client/server stubs in Go, Java, Python, etc |
| 🔐 Internal services | Between trusted backends in the same org or data center |
| 📦 Data-intensive operations | Image/video processing, ML pipelines, large message payloads |
Real life gRPC use cases?
| Use Case | Example |
|---|---|
| Microservice Communication | User Service ↔ Auth Service ↔ Payment Service |
| Streaming Service | Live stock price updates or sensor data stream |
| ML Pipeline | Backend calling TensorFlow model via gRPC |
| IoT Devices | Edge device ↔ cloud gateway |
| Mobile ↔ Backend (with gRPC-Web) | Flutter/React Native app using gRPC protocol |
REST vs gRPC use cases?
| Use Case | Recommended |
|---|---|
| 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?
| Name | Type | Description |
|---|---|---|
| GraphQL | Query language | Flexible API where client defines data shape. Runs over HTTP. |
| SOAP | XML-based RPC | Legacy enterprise protocol, uses XML, WSDL. |
| WebSockets | Bidirectional stream | Real-time communication (e.g., chats, games). |
| gRPC-Web | gRPC over HTTP/1.1 | Allows browsers to talk to gRPC backend. |
| Thrift | RPC framework | Similar to gRPC, used at Facebook, supports many languages. |
| JSON-RPC / XML-RPC | Lightweight RPC protocols | Simple request-response over HTTP. Mostly outdated. |
| MQ (RabbitMQ, NATS, Kafka) | Message queue, Event-driven | Asynchronous messaging systems, not request/response. |
When to use what?
| Use Case | Recommended 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?
| Protocol | Best For | Example Use Case |
|---|---|---|
| GraphQL | Client-driven data shapes, reducing overfetching | Mobile app requesting nested user data |
| SOAP | Legacy enterprise with strict schemas | Insurance or banking API integration |
| WebSocket | Real-time, full-duplex communication | Multiplayer games, live chats |
| gRPC-Web | Browsers talking to gRPC microservices | Admin dashboard with gRPC backend |
| Thrift | Multi-language internal RPC | Facebook-like backend microservice system |
| JSON-RPC | Lightweight RPC, CLI tools, blockchain nodes | Ethereum JSON-RPC API |
| MQ (Kafka) | Asynchronous, event-driven architecture | Payment service → Order service via Kafka |