multi-tenancy-patterns

Implement strict multi-tenant isolation across Go services, PostgreSQL schemas, and NATS JetStream.

1|Updated Apr 17, 2026
One-click install
npx skills add https://github.com/PremModhaOfficial/motadata-ai-pipeline --skill multi-tenancy-patterns-premmodhaofficial
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: multi-tenancy-patterns
Source: https://github.com/PremModhaOfficial/motadata-ai-pipeline/tree/main/.claude/skills/multi-tenancy-patterns
Command: npx skills add https://github.com/PremModhaOfficial/motadata-ai-pipeline --skill multi-tenancy-patterns-premmodhaofficial

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Delivers a proven framework for hard tenant isolation across Go services, per-tenant PostgreSQL schemas, and NATS JetStream messaging. The patterns cover tenant-id propagation in Go types, schema routing, tenant-specific NATS subjects, and per-tenant feature toggles and rate limits.

Core Features & Use Cases

  • TenantID in Go Structs: Ensure every domain model includes a TenantID field for routing, logging, and tracing.
  • Schema-Per-Tenant Isolation: Use per-tenant schemas to enforce database isolation via search_path without tenant_id columns.
  • NATS Subject Tenant Segment: Enforce tenant segmentation in all JetStream subjects to maintain tenant-scoped messaging boundaries.
  • Tenant Context Propagation Chain: Propagate tenant identity through JWT, HTTP headers, Go context, and across inter-service calls.
  • Per-Tenant Feature Toggles: Enable/disable features per tenant with dedicated storage and routing.
  • Per-Tenant Rate Limiting: Apply per-tenant rate limits to prevent cross-tenant performance impact.
  • End-to-end Patterns: Provide end-to-end guidance from domain models to messaging and data access layers.

Quick Start

Apply patterns when designing any tenant-scoped data structures, service boundaries, and messaging that require strict isolation.

Quick Start

Apply patterns when designing any tenant-scoped data structures, service boundaries, and messaging that require strict isolation.

Frequently Asked Questions about multi-tenancy-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement strict multi-tenant isolation in a Go microservices architecture?

Multi-tenant isolation in Go services is achieved by propagating tenant identifiers through JWT, HTTP headers, and Go context, enforcing strict boundaries across domain models, database schemas, and messaging subjects.

What is the best way to isolate tenant data in PostgreSQL without adding tenant_id columns to every table?

Schema-per-tenant isolation uses dedicated PostgreSQL schemas for each tenant, enforcing database isolation via the search_path without requiring tenant_id columns in your domain data tables.

How do I maintain tenant segmentation when publishing events to NATS JetStream?

Tenant segmentation in NATS JetStream is maintained by enforcing a tenant segment within all messaging subjects, ensuring tenant-scoped boundaries are preserved across event-driven inter-service communication.

Can I apply per-tenant rate limiting and feature toggles across my Go services?

Per-tenant rate limiting and feature toggles can be applied across Go services using dedicated storage and routing, preventing cross-tenant performance impact and allowing features to be enabled or disabled per tenant.

Do I need to include a TenantID field in every Go struct for context propagation to work?

Including a TenantID field in every domain model struct is required to ensure correct routing, logging, and tracing, completing the tenant context propagation chain across HTTP headers and inter-service calls.