Skip to content

hhuseyinpay/golang-multi-tenancy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Multi-Tenancy Examples

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

Projects

Project Framework ORM
echo-bun Echo v5 Bun
fiber-gorm Fiber v2 GORM

Quick Start

docker-compose up

Testing

make 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.

Endpoints

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)

Architecture

Request → Middleware → Handler → Repository → Tenant Database
              ↓
      Tenant detection
      from URL path
              ↓
      context.WithValue
              ↓
      PrepareConn: SET search_path

About

Demonstrates hybrid multi-tenancy strategy in Go with PostgreSQL

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors