Skip to main content

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 TypePathNotes
Scheduled Contentapps/{source}/bannersapps/{destination}/bannersAll scheduled content or a single item
Assetsapps/{source}/contentsapps/{destination}/contentsAll 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: bannerId set → 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:

  • massReplication config – Stored at apps/{appId}/config/massReplication. Includes enabled, emails (for notifications), and createdBy.
  • autoReplication queue – Stored at apps/{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

StatusMeaning
PendingReplication created; Cloud Task queued or scheduled
In ProgressReplication job is running
SuccessfulReplication completed without errors
ErrorReplication failed (see statusMessages)

Flow

  1. Create – A replication record is written to replications/{id}.
  2. Queue – Firebase trigger (onUpdateReplication or creation handler) creates a Cloud Task.
  3. RunreplicationCallback or bannersAutoReplicator HTTP function executes.
  4. Copy – Scheduled content and assets are read from source and written to destination in chunks.
  5. Publish – After success, scheduled content is published to R2 for both source and destination apps.
  6. 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 baseUrl from apps/{appId}/config/consumer/baseUrl for both apps.
  • Before copying, it replaces the source origin with the destination origin in:
    • banner.location
    • banner.locations (array)
    • banner.variants[].location
    • banner.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}:

FieldTypeDescription
sourcestringSource app ID
destinationstringDestination app ID
bannerIdstring (optional)Single scheduled content item to replicate; omit for full copy
statusenumPending, In Progress, Successful, Error
statusMessagesstring[]Error details when status is Error
schedulenumber (optional)Unix timestamp for scheduled run
automatedbooleantrue for mass/auto replication
replicationTaskstring (optional)Cloud Task name
completedAtnumber (optional)Unix timestamp when finished
replicatedBannerIdsstring[]IDs of replicated scheduled content
replicatedContentIdsstring[]IDs of replicated assets
archivedbooleanSoft-delete flag
deletedbooleanSoft-delete flag
createdAt, updatedAtnumberTimestamps
createdBy, updatedBystring/objectUser 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:

OperationWhen
startedReplication job has started
completedReplication job completed successfully
failedReplication 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:

HookWhen
bannersReplicationBeforeBefore replication runs
bannersReplicationAfterAfter 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: onUpdateReplication listens to replications/{id} and creates/updates Cloud Tasks when a replication record is created or changed.
  • Automated replications: A daily task is created based on schedule and calls bannersAutoReplicator.

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

ConceptDescription
PurposeCopy scheduled content and assets from source app to destination app
Full vs singleOmit bannerId for all; set bannerId for one item
Manual vs automatedManual = user-initiated; automated = daily mass replication via autoReplication queue
Web URL swapFor web→web, origins in URLs are replaced with destination base URL
ExecutionCloud Tasks invoke HTTP functions; Firebase triggers create tasks on record changes
Post-replicationScheduled content is published to R2 for both apps