Hi everyone,
I’d like to share tenant-core, a Go toolkit for multi-tenant SaaS applications.
**The problem it addresses:** in a multi-tenant system, every request needs to resolve which tenant it belongs to, and every subsystem (cache, rate limits, permissions, metrics) needs to respect that boundary consistently. Most teams end up building this incrementally and inconsistently.
**What it provides:**
- Tenant resolution (subdomain-based resolver included), propagated via `context.Context`
- A `Store`/`CachedStore` abstraction with a singleflight-based cache to avoid stampedes
- Real-time ban propagation across instances via an `EventBus` (in-memory or Redis)
- Per-tenant RBAC (roles are scoped per tenant, not global)
- Per-tenant rate limiting, with an optional Redis-backed distributed variant
- A framework-agnostic Admin API with pluggable authentication
- Adapters for `net/http`, Gin, Echo, and Chi — the core has zero framework dependency
**Design choices worth mentioning:**
- Interfaces live in the core package; concrete implementations (Redis, Prometheus) live in separate Go submodules, so consumers only pull in what they use
- Concurrency-sensitive paths (singleflight under cache misses, `sync.Map` contention for the rate limiter) were benchmarked and profiled rather than assumed
- The architecture doc is explicit about current limitations (e.g. the event retry queue is best-effort in-memory, not a durable Outbox)
It’s `v0.2.0`, about a month old — not claiming API stability yet, and I’m already working on a breaking change (`Permission` as a defined type instead of `string`) based on feedback from r/golang.
Getting started: tenant-core/GETTING_STARTED.md at main · sylvinhio676-ux/tenant-core · GitHub
Architecture doc: tenant-core/docs/ARCHITECTURE.md at main · sylvinhio676-ux/tenant-core · GitHub
Feedback and criticism very welcome.