Example implementations for the Medium article: Go ile Multi-tenant SaaS Proje Geliştirmek
This repository demonstrates hybrid multi-tenancy strategy in Go with PostgreSQL:
- Database per Tenant for large tenants
- Schema per Tenant for small tenants
| Project | Framework | ORM |
|---|---|---|
| echo-bun | Echo v5 | Bun |
| fiber-gorm | Fiber v2 | GORM |
docker-compose upmake test-unit # Unit tests (no DB required)
make test-integration # Integration tests (requires DB)
make test-all # Run everything (starts DB, runs tests, stops DB)Integration tests verify tenant isolation with concurrent requests.
GET /api/tenant1/articles # Large tenant (dedicated DB)
GET /api/tenant2/articles # Small tenant (shared DB, schema: tenant2)
GET /api/tenant3/articles # Small tenant (shared DB, schema: tenant3)
Request → Middleware → Handler → Repository → Tenant Database
↓
Tenant detection
from URL path
↓
context.WithValue
↓
PrepareConn: SET search_path