Replication

Run several API replicas behind a load balancer, keep them in sync, and make sure triggered work runs exactly once.

A single API replica serves most projects. Run more when you need higher availability or more throughput. Replicas are stateless towards clients, but they share background work such as function triggers, so they must coordinate.

Turn it on

Start every replica with:

Terminal
--replication=true

The Helm chart sets it automatically when application.replicas is greater than 1.

With replication on:

  • Scheduled, bucket and database events are claimed by one replica, so each runs once.
  • Replicas keep their in-memory state, such as loaded functions and triggers, in step.

Requirements

ConcernWhat to do
Function sourcesUse --function-asset-storage-strategy=awss3 or gcs, or point --function-asset-path at a shared volume.
Uploaded filesUse the awss3 or gcloud storage strategy, or a shared volume (application.diskAccessMode: ReadWriteMany in the chart).
DatabaseAll replicas use the same database.
SecretsAll replicas use the same master key or secrets.
Load balancerAny. WebSocket connections (realtime, firehose) must be allowed.

Things that run on every replica

  • system triggers with READY, because every replica starts.
  • In-memory response caches (--bucket-cache). Each replica has its own cache and invalidates it on its own writes, so cached reads can be stale for up to --bucket-cache-ttl seconds.