Data Migration
When tenants upgrade from a shared cluster to dedicated infrastructure, their data must be migrated with zero data loss. The migration pipeline handles databases, object storage, message queues, and cache state.
Migration Components
| Component | Source (Shared) | Target (Dedicated) | Strategy |
|---|---|---|---|
| PostgreSQL | Shared instance, tenant schema | Dedicated instance | Schema export/import |
| Object Storage | Shared bucket, tenant prefix | Dedicated storage account | Copy with verification |
| Redis | Shared cluster, key prefix | Dedicated Redis | Cache warming (no migration) |
| Kafka | Shared topics, consumer groups | Dedicated topics | Topic replay from retention |
| Elasticsearch | Shared index, tenant filter | Dedicated indices | Reindex with tenant filter |
Database Migration
Schema Isolation in Shared Clusters
In shared clusters, each tenant's data is isolated by schema or row-level security:
-- Shared cluster: tenant data isolated by tenant_id column
SELECT * FROM shared_schema.queries WHERE tenant_id = 'acme-tenant-id';
-- Dedicated cluster: full schema ownership
SELECT * FROM public.queries;Migration Steps
- Pre-migration snapshot: Create a point-in-time backup of tenant data
- Schema export: Export all tenant-scoped tables using
pg_dumpwith row filters - Schema creation: Create the database schema on the dedicated instance
- Data import: Import using
pg_restorewith parallel workers - Verification: Row count comparison and checksum validation
- Cutover: Update tenant connection string in config store
Object Storage Migration
Files and artifacts are migrated between storage accounts:
Shared: s3://matih-shared-data/tenants/acme/**
--> Dedicated: s3://acme-dedicated-data/**The migration service:
- Lists all objects with the tenant prefix
- Copies objects in parallel (configurable concurrency)
- Verifies checksums (MD5/SHA-256) for each object
- Updates storage references in the database
Migration Verification
After data migration completes, the system runs automated verification:
| Check | Description | Threshold |
|---|---|---|
| Row count | Source vs target row counts per table | Exact match |
| Checksum | SHA-256 of sorted primary keys per table | Exact match |
| Object count | Source vs target object counts in storage | Exact match |
| Object size | Total bytes comparison | Exact match |
| API health | All service endpoints return 200 | 100% |
| Query test | Sample queries produce identical results | Exact match |
Rollback Procedure
If migration verification fails, the system rolls back:
- Keep shared cluster data intact (never deleted until verification passes)
- Drop dedicated database or mark as failed
- Delete migrated objects from dedicated storage
- Revert tenant configuration to point to shared cluster
- Log failure details in the migration audit trail
Source Files
| File | Path |
|---|---|
| Migration Service | control-plane/tenant-service/src/main/java/com/matih/tenant/service/migration/TierMigrationService.java |
| Provisioning Service | control-plane/tenant-service/src/main/java/com/matih/tenant/service/ProvisioningService.java |