Architecture-00024 — Tenant Catalog Bulk Migration Component Topology and Data Flow
By Engineering Team•October 11, 2026•7 min read
Metadata
| Field | Value |
|---|---|
| System Name | firebase-function → tenant-migration → tenant-migration-orchestrator |
| Document ID | ARCH-2026-MIG-001 |
| Author | Engineering Team |
| Status | Implemented |
Realizes SR-029 under ADR-00043, ADR-00044, ADR-00045, and ADR-00015.
Diagram

Components
| Component | Role |
|---|---|
ui-admin-application (migration feature) |
Uploads a tenant’s catalog bundle to the staging bucket with transaction name migration_bundle — the only producer of this upload shape. |
firebase-function’s storage_migration_upload_event.js |
GCS Storage-upload trigger filtering on transactionName === 'migration_bundle'; publishes the batch-uploaded envelope. |
tenant-migration’s MigrationBatchCreatedReceiver |
Consumes the batch-uploaded envelope, creates the migration_batches document idempotently. |
tenant-migration’s VerifyService |
Agenda job running EXTRACT → SCHEMA → COMPILE against the uploaded archive. |
IEntityVerifyProcessor factory + registered processors |
Pluggable per-entity-type CSV parsing/validation/compilation — all 13 known entity types (category hierarchy, warehouse/fulfillment locations, package definitions, base product, and 9 product-detail types), one processor class each, registered in migration.module.ts. |
| Shared assets mount | Holds the compiled, line-delimited (NDJSON) output per entity type, written by verify and read by execute and dispatch. |
tenant-migration’s ExecuteService |
Agenda job that builds the four-stage plan from migration_order, publishes each stage’s records only after the previous stage’s wave completes. |
migration-item Pub/Sub topic |
Carries one message per record, tagged with a tier attribute and, for the one self-referencing entity type, an ordering key. |
tenant-migration-orchestrator’s 4 tier-filtered subscriptions |
core/image/gates/sequential — independent concurrency caps per data shape. |
EntityMigrationServiceFactory + per-entity-type repositories |
Routes each record to its target microservice’s REST API, one outbound integration per entity type. |
Circuit breaker (keyed by destination baseURL) |
Shared failure/trip state across every entity type calling the same downstream service. |
migration_dead_letters / migration_errors |
The real retry state machine (dead letters) vs. audit-only visibility (errors) — never the same collection. |
tenant-migration’s batch lifecycle endpoints |
List/get/delete/cancel/retry, plus an SSE status stream — all tenant-isolated. |
End-to-end flow
- Operations uploads a tenant’s catalog bundle through
ui-admin-application’s migration feature, landing in the staging bucket tagged with transaction namemigration_bundle(SR-029 FR-01). firebase-function’sstorage_migration_upload_event.jsfires only once GCS confirms the object write is durable (onObjectFinalized), confirms the transaction name matches, and publishes a storage-upload envelope to the batch-uploaded topic (FR-01) — see ADR-00045 for why batch creation waits for this event instead of a synchronous call from the uploader.tenant-migration’sMigrationBatchCreatedReceiverconsumes the envelope, derivesbatchIdfrom itstransaction_id, and creates themigration_batchesdocument — a redelivered envelope for an already-created batch is a no-op (FR-02).- Operations calls
POST /migration/verify/:batchId;VerifyService.enqueuechecks tenant ownership and schedules the verify Agenda job, returning202 Acceptedimmediately (FR-03). - EXTRACT streams the staged archive to local disk, then concurrently archives it to the primary bucket and extracts its CSV entries into per-entity-type buckets (FR-05).
- SCHEMA checks run only for entity types actually present in the bundle, resolved via the verify-processor factory; an unrecognized bundle is rejected outright (FR-06).
- COMPILE parses, validates, and compiles each present entity type’s rows into a validation summary and line-delimited output files on the shared assets mount (FR-07) — see ADR-00043’s Decision 1.
- On success the batch is marked
VERIFIEDand the scratch directory is removed; on failure the specific step/entity type/error is recorded, the batch is markedVERIFICATION_FAILED, and the scratch directory is deliberately left for inspection (FR-08). - Operations calls
POST /migration/execute/:batchId;ExecuteService.enqueuechecks ownership and schedules the execute job (FR-10). - The job resolves the tenant’s entity-to-stage order, groups entities into four fixed stage buckets, and publishes each stage’s records only after every entity type in the previous stage has finished — a wave barrier with a bounded wait (FR-11, FR-12) — see ADR-00043’s Decision 2.
- Each record is streamed from its compiled file and published individually, tagged with a processing-tier attribute and, for category hierarchy records, a per-batch ordering key (FR-14).
tenant-migration-orchestrator’s four tier-filtered subscriptions receive the published records; before dispatching, a per-record dependency recheck confirms the record’s prerequisite entity type has actually finished, redelivering it otherwise as a backstop to the wave barrier already enforced upstream (FR-12, FR-18).- The record is routed, by entity type, to a dedicated outbound integration calling that entity type’s target microservice API — never a direct write into that microservice’s own database — behind a circuit breaker shared by every entity type calling the same destination (FR-16, FR-17; see ADR-00044 for why REST dispatch was chosen over direct database writes).
- A record that fails is recorded for visibility (
migration_errors); one that exhausts delivery attempts is additionally captured inmigration_dead_letterswith its full original envelope, retryable later without re-deriving it from the original upload (FR-19, FR-20). - Throughout, operations watches the batch’s live status via the SSE stream, and — for a batch that finished with failures — retries only the failed records without resubmitting or re-verifying anything that already succeeded (FR-21), all scoped to the caller’s own tenant (FR-22).
What this does not yet guarantee
This flow is deliberately simple: a fixed four-stage plan with a coarse wave barrier, not a general dependency graph (ADR-00043’s Decision 2). A couple of gaps surfaced while tracing this flow are not yet closed:
- A batch compiled under the pipeline’s earlier JSON-array output format cannot be read by the current byte-offset readers and has no compatibility shim — TD-00023.
- Several of this monorepo’s own module docs still describe base product records as lacking a verify-time processor; the current code registers one, and this documentation drift is itself tracked — TD-00023.
Related Documents
- SR-029 — Tenant Catalog Bulk Data Migration Spec
- ADR-00043 — NDJSON Streaming and Wave-Barrier Execution for Tenant Catalog Migration
- ADR-00044 — REST API Dispatch and Tiered Concurrency Over Direct Database Writes for Migration Delivery
- ADR-00045 — Event-Driven Batch Creation From Storage-Upload Completion
- TD-00023 — Tenant Catalog Bulk Migration Gaps
- tenant-migration
- tenant-migration-orchestrator
- firebase-function