Multi-Tenancy & Sharding Documentation
January 8, 2026 · View on GitHub
This directory contains documentation for PropertyWebBuilder's multi-tenancy architecture and database sharding system.
Core Documentation
Architecture & Reference
- MULTI_TENANCY_DATABASE_REFERENCE.md - Complete database architecture reference
- MULTI_TENANCY_EXPLORATION_SUMMARY.md - System exploration summary
- MULTI_TENANCY_QUICK_START.md - Quick start guide
Sharding
- PREMIUM_ENTERPRISE_SHARDING_PLAN.md - Enterprise sharding plan
- DEMO_SHARD_GUIDE.md - Demo shard setup guide
Shard Admin Implementation (NEW - 2026-01-08)
- SHARD_ADMIN_IMPLEMENTATION_PLAN.md - Complete implementation plan (48KB)
- SHARD_ADMIN_IMPLEMENTATION_UPDATES.md - Codebase-aligned updates (28KB)
Shard Admin Implementation
Overview
The Shard Admin project adds a complete UI for managing database shards in the Tenant Admin interface.
Status: Planning Complete ✅
Implementation: Not Started
Estimated Effort: 2-3 weeks
What Will Be Built
Phase 1 (Week 1): Foundation
- Shard dashboard showing all configured shards
- Website shard assignment UI
- Audit logging for all changes
- Health monitoring basics
Phase 2 (Week 2): Advanced Features
- Detailed health monitoring with PgHero
- Bulk shard assignment
- Statistics & capacity tracking
- Turbo/Stimulus dynamic UI
Phase 3 (Week 3): Migration Tools
- Background migration jobs
- Progress tracking
- Verification & rollback
- Email notifications
Key Features
✅ Read from Actual Codebase
- Uses
Pwb::ShardRegistry(not invented API) - Uses
Pwb::TenantShardMigrator(actual class name) - Integrates with existing PgHero installation
✅ Modern Rails 8
- Turbo Streams for instant updates
- Stimulus controllers for interactivity
- Solid Queue for background jobs
- Feature flags for gradual rollout
✅ Production Ready
- Comprehensive validation
- Risk mitigation strategies
- Audit trail for all operations
- CLI tools (Rake tasks)
- API endpoints for monitoring
Quick Reference
Access: /tenant_admin/shards (requires TENANT_ADMIN_EMAILS)
CLI Commands:
# Status check
bin/rails pwb:shards:status
# Assign website to shard
bin/rails pwb:shards:assign[42,shard_1]
# Health check
bin/rails pwb:shards:health
Feature Flags (Progressive Rollout):
SHARD_ADMIN_ENABLED=true # Enable dashboard
SHARD_ASSIGNMENT_ENABLED=true # Enable assignment
SHARD_MIGRATIONS_ENABLED=true # Enable data migration
Getting Started
-
Read the Plan:
- Start with
SHARD_ADMIN_IMPLEMENTATION_PLAN.md - Review
SHARD_ADMIN_IMPLEMENTATION_UPDATES.mdfor codebase-specific details
- Start with
-
Understand Dependencies:
- Existing:
Pwb::ShardRegistry,Pwb::TenantShardMigrator, PgHero - New:
Pwb::ShardService,Pwb::ShardHealthCheck,Pwb::ShardAuditLog
- Existing:
-
Phase 1 Implementation:
- Create database migration for
pwb_shard_audit_logs - Create routes in
tenant_adminnamespace - Create
ShardsController - Create views with Tailwind CSS
- Add shard column to websites index
- Create database migration for
Risk Assessment
| Risk | Mitigation |
|---|---|
| Unconfigured shard assignment | Validate with ShardRegistry.configured? |
| Data loss during migration | Transactions, verification, source preservation |
| Concurrent operations | Database locks, single-queue processing |
| Permission escalation | Strict TENANT_ADMIN_EMAILS validation |
Success Criteria
- All tests passing (unit, controller, integration)
- Can view all configured shards
- Can assign websites to shards
- Audit logs created for all changes
- Health monitoring working
- Documentation complete
Additional Resources
- Database configuration:
config/database.yml - Shard registry:
app/lib/pwb/shard_registry.rb - Migrator service:
app/services/pwb/tenant_shard_migrator.rb - Application record:
app/models/pwb_tenant/application_record.rb
Questions?
See the implementation plan for detailed answers on:
- Architecture decisions
- Security model
- Testing strategy
- Deployment procedures
- Troubleshooting guide