Replication
What is Replication?
Replication is the process of copying scheduled content and assets from a source to a destination. It is used to:
- Sync assets across environments (e.g., staging → production)
- Share scheduled content between different apps or websites
- Propagate changes from a master app to child apps on a schedule
What Gets Replicated
| Data Type | Path | Notes |
|---|---|---|
| Scheduled Content | apps/{source}/banners → apps/{destination}/banners | All scheduled content or a single item |
| Assets | apps/{source}/contents → apps/{destination}/contents | All assets |
Replication performs a direct copy; existing scheduled content and assets at the destination are overwritten with source data.
Replication Types
1. Manual Replication
A user creates a replication record specifying source, destination, and optionally a single bannerId. The record is stored and triggers execution via Cloud Tasks.
- Full replication: No
bannerId→ copies all scheduled content and all assets - Single scheduled content replication:
bannerIdset → copies only that item and all assets
2. Scheduled Replication
A replication can have a schedule (Unix timestamp). If the schedule is in the future, the job is queued via Cloud Tasks to run at that time. If the schedule is in the past or omitted, execution starts immediately.
3. Automated (Mass) Replication
Automated replication uses:
massReplicationconfig – Stored atapps/{appId}/config/massReplication. Includesenabled,emails(for notifications), andcreatedBy.autoReplicationqueue – Stored atapps/{appId}/autoReplication. Each entry references a scheduled content ID to replicate to a destination.- Daily schedule – A Cloud Task is created to run at a configured time each day and replicate only the scheduled content listed in
autoReplication.
When scheduled content is added to autoReplication, it is picked up by the next scheduled run. After replication, those entries are removed from the queue.
Replication Lifecycle
Statuses
| Status | Meaning |
|---|---|
| Pending | Replication created; Cloud Task queued or scheduled |
| In Progress | Replication job is running |
| Successful | Replication completed without errors |
| Error | Replication failed (see statusMessages) |
Flow
- Create – A replication record is written to
replications/{id}. - Queue – Firebase trigger (
onUpdateReplicationor creation handler) creates a Cloud Task. - Run –
replicationCallbackorbannersAutoReplicatorHTTP function executes. - Copy – Scheduled content and assets are read from source and written to destination in chunks.
- Publish – After success, scheduled content is published to R2 for both source and destination apps.
- Complete – Replication record is updated with
status,completedAt,replicatedBannerIds,replicatedContentIds, etc.
Web vs App: Base URL Replacement
When both source and destination are web apps:
- The system fetches
baseUrlfromapps/{appId}/config/consumer/baseUrlfor both apps. - Before copying, it replaces the source origin with the destination origin in:
banner.locationbanner.locations(array)banner.variants[].locationbanner.variants[].locations(arrays)
This ensures embedded URLs in scheduled content point to the correct site after replication. If either base URL is missing, the replication records an error.
For app-to-app or mixed web/app replications, no URL replacement is performed.
Data Model
Replication Record
Stored at replications/{id}:
| Field | Type | Description |
|---|---|---|
source | string | Source app ID |
destination | string | Destination app ID |
bannerId | string (optional) | Single scheduled content item to replicate; omit for full copy |
status | enum | Pending, In Progress, Successful, Error |
statusMessages | string[] | Error details when status is Error |
schedule | number (optional) | Unix timestamp for scheduled run |
automated | boolean | true for mass/auto replication |
replicationTask | string (optional) | Cloud Task name |
completedAt | number (optional) | Unix timestamp when finished |
replicatedBannerIds | string[] | IDs of replicated scheduled content |
replicatedContentIds | string[] | IDs of replicated assets |
archived | boolean | Soft-delete flag |
deleted | boolean | Soft-delete flag |
createdAt, updatedAt | number | Timestamps |
createdBy, updatedBy | string/object | User info |
Source and Destination
Source and destination must be different apps. Replicating an app to itself is rejected with an error.
Webhooks and Hooks
Replication Webhook
Configure a URL at apps/{appId}/config/webhooks.replicationWebhook. It receives HTTP POST requests when:
| Operation | When |
|---|---|
started | Replication job has started |
completed | Replication job completed successfully |
failed | Replication job failed |
Payload includes replicationId, source, destination, status, bannerId, automated, schedule, and related metadata.
Client Hooks
These run in the Visual Experience Engine UI around scheduled content replication:
| Hook | When |
|---|---|
bannersReplicationBefore | Before replication runs |
bannersReplicationAfter | After replication completes |
These hooks are client-side and can be used to purge CDN cache, trigger analytics, etc.
Technical Implementation
Cloud Tasks
- Replications are executed via Google Cloud Tasks.
- Non-automated replications:
onUpdateReplicationlistens toreplications/{id}and creates/updates Cloud Tasks when a replication record is created or changed. - Automated replications: A daily task is created based on
scheduleand callsbannersAutoReplicator.
Concurrency
Only one replication runs at a time. If another replication is already executing, new ones are rescheduled 5–10 minutes later. After a maximum retry count, the replication is marked as Error.
Chunking
Firebase limits multi-path writes. Replication writes data in chunks (default 50 paths per update) to stay within limits.
R2 Publishing
After a successful replication, the system publishes scheduled content to R2 for both source and destination apps via the standard scheduled content publish pipeline. Results are stored on the replication record (publishResults, publishError, publishedAt).
Summary
| Concept | Description |
|---|---|
| Purpose | Copy scheduled content and assets from source app to destination app |
| Full vs single | Omit bannerId for all; set bannerId for one item |
| Manual vs automated | Manual = user-initiated; automated = daily mass replication via autoReplication queue |
| Web URL swap | For web→web, origins in URLs are replaced with destination base URL |
| Execution | Cloud Tasks invoke HTTP functions; Firebase triggers create tasks on record changes |
| Post-replication | Scheduled content is published to R2 for both apps |